Skip to content

Commit f0e3d90

Browse files
committed
more review
1 parent a9f8920 commit f0e3d90

File tree

2 files changed

+26
-34
lines changed

2 files changed

+26
-34
lines changed

test/test_unified_format.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,11 @@
3636
]))
3737

3838

39-
globals().update(generate_test_classes(
40-
os.path.join(_TEST_PATH, 'valid-fail'),
41-
module=__name__,
42-
class_name_prefix='UnifiedTestFormat',
43-
expected_failures=[
44-
'foo',
45-
'FindOneAndReplace returnDocument invalid enum value',
46-
'FindOneAndUpdate returnDocument invalid enum value'
47-
]))
39+
# Uncomment to run the valid-fail tests
40+
# globals().update(generate_test_classes(
41+
# os.path.join(_TEST_PATH, 'valid-fail'),
42+
# module=__name__,
43+
# class_name_prefix='UnifiedTestFormat'))
4844

4945

5046
class TestMatchEvaluatorUtil(unittest.TestCase):

test/unified_format.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,6 @@ def setUpClass(cls):
538538
# super call creates internal client cls.client
539539
super(UnifiedSpecTestMixinV1, cls).setUpClass()
540540

541-
# process schemaVersion
542-
version = Version.from_string(cls.TEST_SPEC['schemaVersion'])
543-
if not version <= cls.SCHEMA_VERSION:
544-
raise unittest.SkipTest(
545-
'expected schemaVersion %s or lower, got %s' % (
546-
cls.SCHEMA_VERSION, version))
547-
548541
# process file-level runOnRequirements
549542
run_on_spec = cls.TEST_SPEC.get('runOnRequirements', [])
550543
if not cls.should_run_on(run_on_spec):
@@ -559,6 +552,15 @@ def tearDownClass(cls):
559552
def setUp(self):
560553
super(UnifiedSpecTestMixinV1, self).setUp()
561554

555+
# process schemaVersion
556+
# note: we check major schema version during class generation
557+
# note: we do this here because we cannot run assertions in setUpClass
558+
version = Version.from_string(self.TEST_SPEC['schemaVersion'])
559+
self.assertLessEqual(
560+
version, self.SCHEMA_VERSION,
561+
'expected schema version %s or lower, got %s' % (
562+
self.SCHEMA_VERSION, version))
563+
562564
# initialize internals
563565
self.match_evaluator = MatchEvaluatorUtil(self)
564566

@@ -977,23 +979,17 @@ class SpecTestBase(with_metaclass(UnifiedSpecTestMeta)):
977979
test_type.replace('-', '_').replace('.', '_'))
978980
class_name = snake_to_camel(snake_class_name)
979981

980-
try:
981-
schema_version = Version.from_string(
982-
scenario_def['schemaVersion'])
983-
mixin_class = _SCHEMA_VERSION_MAJOR_TO_MIXIN_CLASS.get(
984-
schema_version[0])
985-
if mixin_class is None:
986-
print('Ignoring test file %s with '
987-
'unsupported schemaVersion %s' %
988-
(fpath, schema_version))
989-
continue
990-
test_klasses[class_name] = type(
991-
class_name,
992-
(mixin_class, test_base_class_factory(scenario_def),),
993-
{'__module__': module})
994-
except (AttributeError, KeyError, TypeError):
995-
print("Ignoring invalid test file '%s'\n"
996-
"Original exception: %s" %
997-
(fpath, traceback.format_exc()))
982+
schema_version = Version.from_string(
983+
scenario_def['schemaVersion'])
984+
mixin_class = _SCHEMA_VERSION_MAJOR_TO_MIXIN_CLASS.get(
985+
schema_version[0])
986+
if mixin_class is None:
987+
raise ValueError(
988+
"test file '%s' has unsupported schemaVersion '%s'" % (
989+
fpath, schema_version))
990+
test_klasses[class_name] = type(
991+
class_name,
992+
(mixin_class, test_base_class_factory(scenario_def),),
993+
{'__module__': module})
998994

999995
return test_klasses

0 commit comments

Comments
 (0)