diff options
author | Julian Berman <Julian@GrayVines.com> | 2019-09-04 11:15:24 +0200 |
---|---|---|
committer | Julian Berman <Julian@GrayVines.com> | 2019-09-04 11:15:24 +0200 |
commit | d241afb695b072f311974cf64ba8f271b3dfcfaa (patch) | |
tree | 3975812103b6aab650fd84972ed68dbcb960e03d | |
parent | 9ab25e0c28dd0d5384dbfd834e244a09b24ca56c (diff) | |
download | jsonschema-d241afb695b072f311974cf64ba8f271b3dfcfaa.tar.gz |
FormatChecker.__repr__
This could use attrs, but probably some day checkers will
become a pyrsistent.pmap, and we can do that then.
-rw-r--r-- | jsonschema/_format.py | 3 | ||||
-rw-r--r-- | jsonschema/tests/test_format.py | 10 |
2 files changed, 13 insertions, 0 deletions
diff --git a/jsonschema/_format.py b/jsonschema/_format.py index d3f1345..51b9b50 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -39,6 +39,9 @@ class FormatChecker(object): else: self.checkers = dict((k, self.checkers[k]) for k in formats) + def __repr__(self): + return "<FormatChecker checkers={}>".format(sorted(self.checkers)) + def checks(self, format, raises=()): """ Register a decorated function as validating a new format. diff --git a/jsonschema/tests/test_format.py b/jsonschema/tests/test_format.py index e9e5f99..14512c5 100644 --- a/jsonschema/tests/test_format.py +++ b/jsonschema/tests/test_format.py @@ -78,3 +78,13 @@ class TestFormatChecker(TestCase): checker = FormatChecker() with self.assertRaises(FormatError): checker.check(instance="not-an-ipv4", format="ipv4") + + def test_repr(self): + checker = FormatChecker(formats=()) + checker.checks("foo")(lambda thing: True) + checker.checks("bar")(lambda thing: True) + checker.checks("baz")(lambda thing: True) + self.assertEqual( + repr(checker), + "<FormatChecker checkers=['bar', 'baz', 'foo']>", + ) |