Пример #1
0
 def test_should_parse_default_severity_correctly(self,
                                                  simple_severity_ruleset):
     rules = SeverityRules._parse_raw_severity_rules(
         simple_severity_ruleset)
     expressions, modifier = next(rules)
     assert expressions == ()
     assert modifier(
         None) == 2, "first rule isn't the default severity level"
Пример #2
0
 def test_should_return_modifiers_that_take_int_and_return_int(
         self, nested_severity_ruleset):
     for expressions, modifier in SeverityRules._parse_raw_severity_rules(
             nested_severity_ruleset):
         assert callable(
             modifier), f"modifier isn't callable for rule {expressions!r}"
         assert isinstance(
             modifier(Severity(3)), int
         ), f"modifier does not follow protocol for rule {expressions!r}"
Пример #3
0
 def test_should_parse_nested_rule_correctly(self, nested_severity_ruleset):
     rules = SeverityRules._parse_raw_severity_rules(
         nested_severity_ruleset)
     _ = next(rules), next(rules)  # skip two first rules
     expressions, modifier = next(rules)
     assert expressions == (
         Expression("first", "level-one"),
         Expression("second", "level-two"),
     ), "could not find a properly parsed nested rule"
     assert callable(modifier)
Пример #4
0
 def test_should_find_perfectly_cromulent_rule(self,
                                               simple_severity_ruleset):
     rules = SeverityRules._parse_raw_severity_rules(
         simple_severity_ruleset)
     _ = next(rules)  # toss default severity level rule
     expressions, modifier = next(rules)
     assert expressions == (
         Expression("foo", "perfectly-cromulent"),
     ), "the second rule in the ruleset was not parsed correctly"
     assert callable(modifier)
Пример #5
0
 def test_should_parse_compound_rule_correctly(self,
                                               nested_severity_ruleset):
     rules = SeverityRules._parse_raw_severity_rules(
         nested_severity_ruleset)
     _ = next(rules), next(rules), next(rules)  # skip first three
     expressions, modifier = next(rules)
     assert expressions == (
         Expression("foo", "0xc0ffee"),
         Expression("bar", "0xbadc0de"),
     ), "could not find a properly parsed compound rule"
     assert callable(modifier)
Пример #6
0
 def test_should_load_simple_ruleset_without_error(self,
                                                   simple_severity_ruleset):
     assert list(
         SeverityRules._parse_raw_severity_rules(simple_severity_ruleset))
Пример #7
0
 def test_should_return_original_severity_on_empty_ruleset(self):
     rules = SeverityRules._parse_raw_severity_rules({})
     expressions, modifier = next(rules)
     assert expressions == ()
     assert modifier(5) == 5