Mercurial > hgrepos > Python > libs > data-schema
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 29:68286d27f27d | 30:2e7c08c356ee |
|---|---|
| 1436 check_single_ref_key=False) | 1436 check_single_ref_key=False) |
| 1437 | 1437 |
| 1438 | 1438 |
| 1439 class BasicValidation(unittest.TestCase): | 1439 class BasicValidation(unittest.TestCase): |
| 1440 | 1440 |
| 1441 def test_enum_name(self): | 1441 def test_problem_enum_name(self): |
| 1442 code = ERRORS.E10001 | 1442 code = ERRORS.E10001 |
| 1443 self.assertEqual("ERRORS.E10001", str(code)) | 1443 self.assertEqual("ERRORS.E10001", str(code)) |
| 1444 self.assertEqual("E10001", code.name) | 1444 self.assertEqual("E10001", code.name) |
| 1445 self.assertTrue(isinstance(code, ERRORS)) | 1445 self.assertTrue(isinstance(code, ERRORS)) |
| 1446 | |
| 1447 def test_problem_to_str(self): | |
| 1448 pr = data_schema.ValidationProblem(code=ERRORS.E10001) | |
| 1449 self.assertTrue(str(pr).startswith("ValidationProblem(code=E10001 (list expected), severity=ERROR")) | |
| 1450 self.assertTrue(repr(pr).startswith("ValidationProblem(code=E10001 (list expected), severity=ERROR")) | |
| 1451 | |
| 1452 def test_problem_with_other_severity_to_str(self): | |
| 1453 pr = data_schema.ValidationProblem(code=ERRORS.E10000, | |
| 1454 severity=SEVERITY.WARNING) | |
| 1455 self.assertTrue(str(pr).startswith("ValidationProblem(code=E10000 (dict expected), severity=WARNING")) | |
| 1456 self.assertTrue(repr(pr).startswith("ValidationProblem(code=E10000 (dict expected), severity=WARNING")) | |
| 1446 | 1457 |
| 1447 def test_schema_must_be_a_dict_alike(self): | 1458 def test_schema_must_be_a_dict_alike(self): |
| 1448 try: | 1459 try: |
| 1449 pr = list(data_schema.validate(None, None)) | 1460 pr = list(data_schema.validate(None, None)) |
| 1450 except data_schema.SchemaError: | 1461 except data_schema.SchemaError: |
