Skip to content

Commit

Permalink
allow empty tests, fix validation return value code
Browse files Browse the repository at this point in the history
  • Loading branch information
soad003 committed Oct 10, 2024
1 parent 5298540 commit 8f50e34
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/tagpack/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand Down Expand Up @@ -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:
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/tagpack/tagpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}"
Expand Down
21 changes: 11 additions & 10 deletions tests/test_tagpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/testfiles/simple/with_concepts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ concepts:
tags:
- address: 1bacdeddg32dsfk5692dmn23
concepts:
- stuff
- organization
label: sometag
- address: 1bacdeddg32dsfk5692dmn23
label: othertag

0 comments on commit 8f50e34

Please sign in to comment.