Mercurial > hgrepos > Python > libs > data-schema
diff tests/test_schema.py @ 30:2e7c08c356ee
Test the the ValidationProblem's str() and repr()
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 08 Jul 2023 20:45:36 +0200 |
| parents | 68286d27f27d |
| children | 271ec3abdfa3 |
line wrap: on
line diff
--- a/tests/test_schema.py Sat Jul 08 16:10:36 2023 +0200 +++ b/tests/test_schema.py Sat Jul 08 20:45:36 2023 +0200 @@ -1438,12 +1438,23 @@ class BasicValidation(unittest.TestCase): - def test_enum_name(self): + def test_problem_enum_name(self): code = ERRORS.E10001 self.assertEqual("ERRORS.E10001", str(code)) self.assertEqual("E10001", code.name) self.assertTrue(isinstance(code, ERRORS)) + def test_problem_to_str(self): + pr = data_schema.ValidationProblem(code=ERRORS.E10001) + self.assertTrue(str(pr).startswith("ValidationProblem(code=E10001 (list expected), severity=ERROR")) + self.assertTrue(repr(pr).startswith("ValidationProblem(code=E10001 (list expected), severity=ERROR")) + + def test_problem_with_other_severity_to_str(self): + pr = data_schema.ValidationProblem(code=ERRORS.E10000, + severity=SEVERITY.WARNING) + self.assertTrue(str(pr).startswith("ValidationProblem(code=E10000 (dict expected), severity=WARNING")) + self.assertTrue(repr(pr).startswith("ValidationProblem(code=E10000 (dict expected), severity=WARNING")) + def test_schema_must_be_a_dict_alike(self): try: pr = list(data_schema.validate(None, None))
