Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_generate_testdata.py
- This file was added.
# Copyright (C) 2019 The Software Heritage developers | |||||
# See the AUTHORS file at the top-level directory of this distribution | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
from .generate_testdata import gen_contents, gen_origins, ORIGINS | |||||
from swh.model.model import Origin, Content | |||||
def test_gen_origins_empty(): | |||||
origins = gen_origins(0) | |||||
assert not origins | |||||
def test_gen_origins_one(): | |||||
origins = gen_origins(1) | |||||
assert len(origins) == 1 | |||||
assert [Origin.from_dict(d) for d in origins] | |||||
def test_gen_origins_default(): | |||||
origins = gen_origins() | |||||
assert len(origins) == 100 | |||||
models = [Origin.from_dict(d).url for d in origins] | |||||
assert len(origins) == len(set(models)) | |||||
def test_gen_origins_max(): | |||||
nmax = len(ORIGINS) | |||||
origins = gen_origins(nmax+1) | |||||
assert len(origins) == nmax | |||||
models = {Origin.from_dict(d).url for d in origins} | |||||
# ensure we did not generate the same origin twice | |||||
assert len(origins) == len(models) | |||||
vlorentz: The test should check url unicity. Currently, you test only checks unicity of (type, url). | |||||
Done Inline Actionsright, type is still around! douardda: right, type is still around! | |||||
Not Done Inline Actionsmodels = {Origin.from_dict(d).url for d in origins} vlorentz: `models = {Origin.from_dict(d).url for d in origins}` | |||||
Done Inline Actionsmakes sense, thx douardda: makes sense, thx | |||||
def test_gen_contents_empty(): | |||||
contents = gen_contents(0) | |||||
assert not contents | |||||
def test_gen_contents_one(): | |||||
contents = gen_contents(1) | |||||
assert len(contents) == 1 | |||||
assert [Content.from_dict(d) for d in contents] | |||||
def test_gen_contents_default(): | |||||
contents = gen_contents() | |||||
assert len(contents) == 20 | |||||
models = {Content.from_dict(d) for d in contents} | |||||
# ensure we did not generate the same content twice | |||||
assert len(contents) == len(models) | |||||
Not Done Inline ActionsThis set should check unicity of each of the hashes. vlorentz: This set should check unicity of each of the hashes. |
The test should check url unicity. Currently, you test only checks unicity of (type, url).