Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/storage/generate_data_test.py
# Copyright (C) 2018 The Software Heritage developers | # Copyright (C) 2018 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 uuid import uuid1 | |||||
from swh.model.hashutil import MultiHash | from swh.model.hashutil import MultiHash | ||||
from hypothesis.strategies import (composite, sets, one_of, uuids, | from hypothesis.strategies import (composite, sets, one_of, uuids, | ||||
tuples, sampled_from) | tuples, sampled_from) | ||||
MIMETYPES = [ | MIMETYPES = [ | ||||
b'application/json', | b'application/json', | ||||
b'application/octet-stream', | b'application/octet-stream', | ||||
b'application/xml', | b'application/xml', | ||||
b'text/plain', | b'text/plain', | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | for uuid, mimetype, encoding in _ids: | ||||
content_mimetypes.append({ | content_mimetypes.append({ | ||||
**_init_content(uuid), | **_init_content(uuid), | ||||
'mimetype': mimetype, | 'mimetype': mimetype, | ||||
'encoding': encoding, | 'encoding': encoding, | ||||
}) | }) | ||||
return content_mimetypes | return content_mimetypes | ||||
FOSSOLOGY_LICENSES = [ | MIMETYPE_OBJECTS = [ | ||||
{'id': MultiHash.from_data(uuid1().bytes, {'sha1'}).digest()['sha1'], | |||||
vlorentz: Why an uuid instead of os.random? | |||||
douarddaAuthorUnsubmitted Done Inline Actionsbecause the uuid hypothesis generator is used in gen_content_mimetypes() I guess, so I stuck to it without really thinking about it. And it's a simple way of generating a small random string/bytes. Is there a problem with using uuid there? douardda: because the uuid hypothesis generator is used in gen_content_mimetypes() I guess, so I stuck to… | |||||
vlorentzUnsubmitted Not Done Inline Actions
no, it just doesn't make sense vlorentz: > Is there a problem with using uuid there?
no, it just doesn't make sense | |||||
douarddaAuthorUnsubmitted Done Inline Actionswhy so? uuid is a perfectly valid way of generating a small random piece of bytes. Also, it's not clear if this really is a blocker for you or not. douardda: why so? uuid is a perfectly valid way of generating a small random piece of bytes. Also, it's… | |||||
'indexer_configuration_id': 1, | |||||
'mimetype': mt, | |||||
'encoding': enc, | |||||
} | |||||
for mt in MIMETYPES | |||||
for enc in ENCODINGS] | |||||
LICENSES = [ | |||||
b'3DFX', | b'3DFX', | ||||
b'BSD', | b'BSD', | ||||
b'GPL', | b'GPL', | ||||
b'Apache2', | b'Apache2', | ||||
b'MIT', | b'MIT', | ||||
] | ] | ||||
FOSSOLOGY_LICENSES = [ | |||||
{'id': MultiHash.from_data(uuid1().bytes, {'sha1'}).digest()['sha1'], | |||||
vlorentzUnsubmitted Not Done Inline Actionssame vlorentz: same | |||||
'indexer_configuration_id': 1, | |||||
'licenses': [LICENSES[i % len(LICENSES)], ], | |||||
} | |||||
for i in range(10) | |||||
] | |||||
def gen_license(): | def gen_license(): | ||||
return one_of(sampled_from(FOSSOLOGY_LICENSES)) | return one_of(sampled_from(LICENSES)) | ||||
@composite | @composite | ||||
def gen_content_fossology_licenses(draw, *, min_size=0, max_size=100): | def gen_content_fossology_licenses(draw, *, min_size=0, max_size=100): | ||||
"""Generate valid and consistent content_fossology_licenses. | """Generate valid and consistent content_fossology_licenses. | ||||
Context: Test purposes | Context: Test purposes | ||||
Show All 19 Lines | _ids = draw( | ||||
) | ) | ||||
) | ) | ||||
content_licenses = [] | content_licenses = [] | ||||
for uuid, license in _ids: | for uuid, license in _ids: | ||||
content_licenses.append({ | content_licenses.append({ | ||||
**_init_content(uuid), | **_init_content(uuid), | ||||
'licenses': [license], | 'licenses': [license], | ||||
'indexer_configuration_id': 1, | |||||
}) | }) | ||||
return content_licenses | return content_licenses |
Why an uuid instead of os.random?