Skip to content

Commit

Permalink
Split convert and dump test.
Browse files Browse the repository at this point in the history
  • Loading branch information
xkww3n committed Dec 1, 2023
1 parent abea000 commit 3ad3e00
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions Tests/test_2_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@ def test_is_domain(self):
assert not rule.is_domain(invalid_domain_b)
assert not rule.is_domain(ipv4addr)

def test_custom_convert(self):
def test_custom_convert_domain(self):
test_src_path = Path("./src/custom_ruleset/")
test_conv_ruleset = ruleset.custom_convert(test_src_path/"domain.txt")
assert test_conv_ruleset == ruleset.RuleSet("Domain",
[rule.Rule("DomainSuffix", "example.com"),
rule.Rule("DomainFull", "example.com")])

def test_custom_convert_ipcidr(self):
test_src_path = Path("./src/custom_ruleset/")
test_conv_ruleset = ruleset.custom_convert(test_src_path/"ipcidr.txt")
assert test_conv_ruleset == ruleset.RuleSet("IPCIDR",
[rule.Rule("IPCIDR", "11.4.5.14"),
rule.Rule("IPCIDR6", "fc00:114::514")])

def test_custom_convert_combined(self):
test_src_path = Path("./src/custom_ruleset/")
test_conv_ruleset = ruleset.custom_convert(test_src_path/"combined.txt")
assert test_conv_ruleset == ruleset.RuleSet("Combined",
[rule.Rule("DomainFull", "example.com"),
Expand All @@ -49,11 +53,11 @@ def test_patch(self):
ruleset.apply_patch(test_ruleset, "patch", test_src_patch)
assert test_ruleset == ruleset.RuleSet("Domain", [rule.Rule("DomainSuffix", "example.com")])

def test_dump(self):
def test_dump_domain(self):
test_dist = Path("./dists/")
ruleset_domain = ruleset.custom_convert(Path("./src/custom_ruleset/domain.txt"))
ruleset.batch_dump(ruleset_domain, const.TARGETS, test_dist, "domain")

ruleset_combined = ruleset.custom_convert(Path("./src/custom_ruleset/domain.txt"))
ruleset.batch_dump(ruleset_combined, const.TARGETS, test_dist, "domain")
assert (test_dist/"text"/"domain.txt").exists()
with open(test_dist/"text"/"domain.txt", mode="r") as f:
assert f.read() == (".example.com\n"
Expand Down Expand Up @@ -85,8 +89,11 @@ def test_dump(self):
assert f.read() == ("example.com\n"
"full:example.com\n")

ruleset_combined = ruleset.custom_convert(Path("./src/custom_ruleset/ipcidr.txt"))
ruleset.batch_dump(ruleset_combined, const.TARGETS, test_dist, "ipcidr")
def test_dump_ipcidr(self):
test_dist = Path("./dists/")
ruleset_ipcidr = ruleset.custom_convert(Path("./src/custom_ruleset/ipcidr.txt"))
ruleset.batch_dump(ruleset_ipcidr, const.TARGETS, test_dist, "ipcidr")

assert not (test_dist/"text-plus"/"ipcidr.txt").exists()
assert not (test_dist/"geosite"/"ipcidr").exists()

Expand All @@ -111,8 +118,11 @@ def test_dump(self):
" - '11.4.5.14'\n"
" - 'fc00:114::514'\n")

def test_dump_combined(self):
test_dist = Path("./dists/")
ruleset_combined = ruleset.custom_convert(Path("./src/custom_ruleset/combined.txt"))
ruleset.batch_dump(ruleset_combined, const.TARGETS, test_dist, "combined")

assert not (test_dist/"text"/"combined.txt").exists()
assert not (test_dist/"text-plus"/"combined.txt").exists()
assert not (test_dist/"yaml"/"combined.yaml").exists()
Expand Down

0 comments on commit 3ad3e00

Please sign in to comment.