Skip to content

Commit 79cdc57

Browse files
committed
Skip checkers for non-present formatters (fixed the build)
1 parent 53d857f commit 79cdc57

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

tests.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import json
88

99
if sys.version_info[:2] < (2, 7): # pragma: no cover
10-
from unittest2 import TestCase, skipIf
10+
import unittest2 as unittest
1111
else:
12-
from unittest import TestCase, skipIf
12+
import unittest
1313

1414
try:
1515
from unittest import mock
@@ -35,7 +35,7 @@ def test_case(self):
3535
return test_case
3636

3737

38-
def load_json_cases(tests_glob, basedir=os.path.dirname(__file__)):
38+
def load_json_cases(tests_glob, basedir=os.path.dirname(__file__), skip=None):
3939
def add_test_methods(test_class):
4040
for filename in glob.iglob(os.path.join(basedir, tests_glob)):
4141
validating, _ = os.path.splitext(os.path.basename(filename))
@@ -60,14 +60,19 @@ def add_test_methods(test_class):
6060
test_name = test_name.encode("utf-8")
6161
a_test.__name__ = test_name
6262

63+
if skip is not None and skip(case):
64+
a_test = unittest.skip("Checker not present.")(
65+
a_test
66+
)
67+
6368
setattr(test_class, test_name, a_test)
6469

6570
return test_class
6671
return add_test_methods
6772

6873

6974
class BytesMixin(object):
70-
@skipIf(PY3, "The JSON module in Python 3 always produces unicode")
75+
@unittest.skipIf(PY3, "In Python 3 json.load always produces unicode")
7176
def test_string_a_bytestring_is_a_string(self):
7277
self.validator_class({"type" : "string"}).validate(b"foo")
7378

@@ -87,18 +92,10 @@ def test_it_can_validate_with_decimals(self):
8792
validator.validate(invalid)
8893

8994

90-
class AnyTypeMixin(object):
91-
def test_any_type_is_valid_for_type_any(self):
92-
validator = self.validator_class({"type" : "any"})
93-
validator.validate(mock.Mock())
94-
95-
96-
@load_json_cases("json/tests/draft3/optional/bignum.json")
97-
class BigNumMixin(object):
98-
pass
99-
100-
101-
@load_json_cases("json/tests/draft3/optional/format.json")
95+
@load_json_cases(
96+
"json/tests/draft3/optional/format.json",
97+
skip=lambda case : case["schema"]["format"] not in FormatChecker.checkers
98+
)
10299
class FormatMixin(object):
103100

104101
validator_kwargs = {"format_checker" : FormatChecker()}
@@ -125,11 +122,15 @@ def test_it_validates_formats_if_a_checker_is_provided(self):
125122

126123

127124
@load_json_cases("json/tests/draft3/*.json")
128-
class TestDraft3(
129-
TestCase, BytesMixin, DecimalMixin, AnyTypeMixin, FormatMixin, BigNumMixin,
130-
):
125+
@load_json_cases("json/tests/draft3/optional/bignum.json")
126+
class TestDraft3(unittest.TestCase, BytesMixin, DecimalMixin, FormatMixin):
127+
131128
validator_class = Draft3Validator
132129

130+
def test_any_type_is_valid_for_type_any(self):
131+
validator = self.validator_class({"type" : "any"})
132+
validator.validate(mock.Mock())
133+
133134
# TODO: we're in need of more meta schema tests
134135
def test_invalid_properties(self):
135136
with self.assertRaises(SchemaError):
@@ -140,7 +141,7 @@ def test_minItems_invalid_string(self):
140141
validate([1], {"minItems" : "1"}) # needs to be an integer
141142

142143

143-
class TestIterErrors(TestCase):
144+
class TestIterErrors(unittest.TestCase):
144145
def setUp(self):
145146
self.validator = Draft3Validator({})
146147

@@ -174,7 +175,7 @@ def test_iter_errors_multiple_failures_one_validator(self):
174175
self.assertEqual(len(errors), 4)
175176

176177

177-
class TestValidationErrorMessages(TestCase):
178+
class TestValidationErrorMessages(unittest.TestCase):
178179
def message_for(self, instance, schema, *args, **kwargs):
179180
with self.assertRaises(ValidationError) as e:
180181
validate(instance, schema, *args, **kwargs)
@@ -248,7 +249,7 @@ def test_invalid_format(self):
248249
self.assertIn("is not a", message)
249250

250251

251-
class TestValidationErrorDetails(TestCase):
252+
class TestValidationErrorDetails(unittest.TestCase):
252253
def setUp(self):
253254
self.validator = Draft3Validator({})
254255

@@ -314,7 +315,7 @@ def test_multiple_nesting(self):
314315
self.assertEqual(e6.validator, "enum")
315316

316317

317-
class TestErrorTree(TestCase):
318+
class TestErrorTree(unittest.TestCase):
318319
def setUp(self):
319320
self.validator = Draft3Validator({})
320321

@@ -356,7 +357,7 @@ def test_children_have_their_errors_dicts_built(self):
356357
self.assertEqual(tree["bar"][0].errors, {"foo" : e1, "quux" : e2})
357358

358359

359-
class TestDraft3Validator(TestCase):
360+
class TestDraft3Validator(unittest.TestCase):
360361
def setUp(self):
361362
self.instance = mock.Mock()
362363
self.schema = {}
@@ -422,7 +423,7 @@ def test_is_type_raises_exception_for_unknown_type(self):
422423
self.validator.is_type("foo", object())
423424

424425

425-
class TestRefResolver(TestCase):
426+
class TestRefResolver(unittest.TestCase):
426427
def setUp(self):
427428
self.base_uri = ""
428429
self.referrer = {}
@@ -472,7 +473,7 @@ def test_it_can_construct_a_base_uri_from_a_schema_without_id(self):
472473
self.assertEqual(resolver.referrer, schema)
473474

474475

475-
class TestFormatChecker(TestCase):
476+
class TestFormatChecker(unittest.TestCase):
476477
def setUp(self):
477478
self.fn = mock.Mock()
478479

0 commit comments

Comments
 (0)