From 8f50e341aa291f9863ec5236202ed1d23f5b8c3a Mon Sep 17 00:00:00 2001 From: "Michael F." Date: Thu, 10 Oct 2024 11:46:58 +0200 Subject: [PATCH] allow empty tests, fix validation return value code --- src/tagpack/cli.py | 12 ++++++------ src/tagpack/tagpack.py | 4 ++-- tests/test_tagpack.py | 21 +++++++++++---------- tests/testfiles/simple/with_concepts.yaml | 2 +- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/tagpack/cli.py b/src/tagpack/cli.py index 1cd7e22..54796a3 100644 --- a/src/tagpack/cli.py +++ b/src/tagpack/cli.py @@ -314,7 +314,6 @@ def validate_tagpack(args): print_info(f"Collected {n_tagpacks} TagPack files\n") no_passed = 0 - failed = False try: for headerfile_dir, files in tagpack_files.items(): for tagpack_file in files: @@ -334,9 +333,10 @@ def validate_tagpack(args): no_passed += 1 except (ValidationError, TagPackFileError) as e: print_fail("FAILED", e) - failed = True - status = "fail" if no_passed < n_tagpacks else "success" + failed = no_passed < n_tagpacks + + status = "fail" if failed else "success" duration = round(time.time() - t0, 2) print_line( @@ -724,7 +724,6 @@ def validate_actorpack(args): print_info(f"Collected {n_actorpacks} ActorPack files\n") no_passed = 0 - failed = False try: for headerfile_dir, files in actorpack_files.items(): for actorpack_file in files: @@ -740,9 +739,10 @@ def validate_actorpack(args): no_passed += 1 except (ValidationError, TagPackFileError, ParserError, ScannerError) as e: print_fail("FAILED", e) - failed = True - status = "fail" if no_passed < n_actorpacks else "success" + failed = no_passed < n_actorpacks + + status = "fail" if failed else "success" duration = round(time.time() - t0, 2) msg = f"{no_passed}/{n_actorpacks} ActorPacks passed in {duration}s" diff --git a/src/tagpack/tagpack.py b/src/tagpack/tagpack.py index d124ea0..d47e20a 100644 --- a/src/tagpack/tagpack.py +++ b/src/tagpack/tagpack.py @@ -320,8 +320,8 @@ def validate(self): self.schema.check_type(field, value) self.schema.check_taxonomies(field, value, self.taxonomies) - if len(self.tags) < 1: - raise ValidationError("no tags found.") + # if len(self.tags) < 1: + # raise ValidationError("no tags found.") # iterate over all tags, check types, taxonomy and mandatory use e2 = "Mandatory tag field {} missing in {}" diff --git a/tests/test_tagpack.py b/tests/test_tagpack.py index 33b3f78..d77bdca 100644 --- a/tests/test_tagpack.py +++ b/tests/test_tagpack.py @@ -34,6 +34,7 @@ def taxonomies(): tax_conc.add_concept("bad_coding", "bad_coding", None, "Really bad") tax_conc.add_concept("exchange", "exchange", None, "Really bad") tax_conc.add_concept("stuff", "stuff", None, "Really bad") + tax_conc.add_concept("organization", "organization", None, "Really bad") taxonomies = { "entity": tax_entity, @@ -497,7 +498,7 @@ def test_file_collection_simple_with_concepts(taxonomies): None, files[0], TagPackSchema(), taxonomies, headerfile_path ) - assert tagpack.tags[0].all_fields.get("concepts") == ["stuff"] + assert tagpack.tags[0].all_fields.get("concepts") == ["organization"] assert tagpack.tags[1].all_fields.get("concepts") == ["exchange"] tagpack.validate() @@ -555,16 +556,16 @@ def test_yaml_inclusion_overwrite_abuse(taxonomies): assert tagpack.tags[0].contents["abuse"] == "sextortion" -def test_empty_tag_list_raises(taxonomies): - tagpack = TagPack.load_from_file( - "http://example.com/packs", - "tests/testfiles/simple/empty_tag_list.yaml", - TagPackSchema(), - taxonomies, - ) +# def test_empty_tag_list_raises(taxonomies): +# tagpack = TagPack.load_from_file( +# "http://example.com/packs", +# "tests/testfiles/simple/empty_tag_list.yaml", +# TagPackSchema(), +# taxonomies, +# ) - with pytest.raises(ValidationError) as _: - tagpack.validate() +# with pytest.raises(ValidationError) as _: +# tagpack.validate() def test_multiple_tags_for_one_address_work(taxonomies): diff --git a/tests/testfiles/simple/with_concepts.yaml b/tests/testfiles/simple/with_concepts.yaml index ca83116..32cc6b4 100644 --- a/tests/testfiles/simple/with_concepts.yaml +++ b/tests/testfiles/simple/with_concepts.yaml @@ -10,7 +10,7 @@ concepts: tags: - address: 1bacdeddg32dsfk5692dmn23 concepts: - - stuff + - organization label: sometag - address: 1bacdeddg32dsfk5692dmn23 label: othertag