Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/tests/test_utils.py
# Copyright (C) 2015-2017 The Software Heritage developers | # Copyright (C) 2015-2017 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from random import shuffle | |||||
import pytest | import pytest | ||||
from swh.loader.git import utils | from swh.loader.git import utils | ||||
class TestUtils: | class TestUtils: | ||||
def test_check_date_time(self): | def test_check_date_time(self): | ||||
"""A long as datetime is fine, date time check does not raise | """A long as datetime is fine, date time check does not raise | ||||
Show All 9 Lines | class TestUtils: | ||||
def test_check_date_time_raises(self): | def test_check_date_time_raises(self): | ||||
"""From a give threshold, check will no longer works. | """From a give threshold, check will no longer works. | ||||
""" | """ | ||||
exp = 38 | exp = 38 | ||||
timestamp = 2 ** exp | timestamp = 2 ** exp | ||||
with pytest.raises(ValueError, match=".*is out of range.*"): | with pytest.raises(ValueError, match=".*is out of range.*"): | ||||
utils.check_date_time(timestamp) | utils.check_date_time(timestamp) | ||||
def test_ignore_branch_name(): | |||||
branches = [ | |||||
b"HEAD", | |||||
b"refs/heads/master", | |||||
b"refs/{}", | |||||
b"refs/pull/10/head", | |||||
b"refs/pull/100/head", | |||||
b"refs/pull/xyz/merge", # auto-merged GitHub pull requests filtered out | |||||
b"refs/^{}", # Peeled refs filtered out | |||||
] | |||||
# order is not interesting | |||||
shuffle(branches) | |||||
actual_branches = [b for b in branches if not utils.ignore_branch_name(b)] | |||||
assert sorted(actual_branches) == sorted( | |||||
[ | |||||
b"HEAD", | |||||
b"refs/heads/master", | |||||
b"refs/{}", | |||||
b"refs/pull/10/head", | |||||
b"refs/pull/100/head", | |||||
] | |||||
) | |||||
vlorentz: no love for sets? :( | |||||
vlorentzUnsubmitted Not Done Inline Actionsyou can even use a set comprehension directly instead of set() vlorentz: you can even use a set comprehension directly instead of `set()` | |||||
ardumontAuthorUnsubmitted Done Inline Actionsso true ;) ardumont: so true ;) |
no love for sets? :(