Changeset View
Changeset View
Standalone View
Standalone View
swh/journal/tests/test_replay.py
Show First 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | |||||
def test_write_replay_legacy_origin_visit1(): | def test_write_replay_legacy_origin_visit1(): | ||||
"""Test origin_visit when the 'origin' is just a string.""" | """Test origin_visit when the 'origin' is just a string.""" | ||||
now = datetime.datetime.now() | now = datetime.datetime.now() | ||||
visits = [{ | visits = [{ | ||||
'visit': 1, | 'visit': 1, | ||||
'origin': 'http://example.com/', | 'origin': 'http://example.com/', | ||||
'date': now, | 'date': now, | ||||
'type': 'hg' | 'type': 'git', | ||||
'status': 'partial', | |||||
'snapshot': None, | |||||
}] | }] | ||||
_test_write_replay_origin_visit(visits) | _test_write_replay_origin_visit(visits) | ||||
def test_write_replay_legacy_origin_visit2(): | def test_write_replay_legacy_origin_visit2(): | ||||
"""Test origin_visit when 'type' is missing.""" | """Test origin_visit when 'type' is missing.""" | ||||
now = datetime.datetime.now() | now = datetime.datetime.now() | ||||
visits = [{ | visits = [{ | ||||
'visit': 1, | 'visit': 1, | ||||
'origin': { | 'origin': { | ||||
'url': 'http://example.com/', | 'url': 'http://example.com/', | ||||
'type': 'git', | 'type': 'git', | ||||
}, | }, | ||||
'date': now, | 'date': now, | ||||
'type': 'git', | |||||
'status': 'partial', | |||||
'snapshot': None, | |||||
}] | }] | ||||
_test_write_replay_origin_visit(visits) | _test_write_replay_origin_visit(visits) | ||||
hash_strategy = strategies.binary(min_size=20, max_size=20) | hash_strategy = strategies.binary(min_size=20, max_size=20) | ||||
@settings(max_examples=500) | @settings(max_examples=500) | ||||
@given(strategies.sets(hash_strategy, min_size=0, max_size=500), | @given(strategies.sets(hash_strategy, min_size=0, max_size=500), | ||||
strategies.sets(hash_strategy, min_size=10)) | strategies.sets(hash_strategy, min_size=10)) | ||||
def test_is_hash_in_bytearray(haystack, needles): | def test_is_hash_in_bytearray(haystack, needles): | ||||
array = b''.join(sorted(haystack)) | array = b''.join(sorted(haystack)) | ||||
needles |= haystack # Exhaustively test for all objects in the array | needles |= haystack # Exhaustively test for all objects in the array | ||||
for needle in needles: | for needle in needles: | ||||
assert is_hash_in_bytearray(needle, array, len(haystack)) == \ | assert is_hash_in_bytearray(needle, array, len(haystack)) == \ | ||||
(needle in haystack) | (needle in haystack) |