Skip to content

Commit 735badf

Browse files
committed
more review 2
1 parent f0e3d90 commit 735badf

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

test/test_unified_format.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
sys.path[0:0] = [""]
1919

20-
from bson import ObjectId, Timestamp
20+
from bson import ObjectId
2121

2222
from test import unittest
2323
from test.unified_format import generate_test_classes, MatchEvaluatorUtil
@@ -36,11 +36,14 @@
3636
]))
3737

3838

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'))
39+
globals().update(generate_test_classes(
40+
os.path.join(_TEST_PATH, 'valid-fail'),
41+
module=__name__,
42+
class_name_prefix='UnifiedTestFormat',
43+
bypass_test_generation_errors=True,
44+
expected_failures=[
45+
'.*', # All tests expected to fail
46+
]))
4447

4548

4649
class TestMatchEvaluatorUtil(unittest.TestCase):

test/unified_format.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import datetime
2222
import functools
2323
import os
24+
import re
2425
import sys
25-
import traceback
2626
import types
2727

2828
from bson import json_util, Code, Decimal128, DBRef, SON, Int64, MaxKey, MinKey
@@ -930,8 +930,10 @@ def test_case(self):
930930
test_method = create_test(copy.deepcopy(test_spec))
931931
test_method.__name__ = test_name
932932

933-
if description in cls.EXPECTED_FAILURES:
934-
test_method = unittest.expectedFailure(test_method)
933+
for fail_pattern in cls.EXPECTED_FAILURES:
934+
if re.search(fail_pattern, description):
935+
test_method = unittest.expectedFailure(test_method)
936+
break
935937

936938
setattr(cls, test_name, test_method)
937939

@@ -947,7 +949,8 @@ def test_case(self):
947949

948950

949951
def generate_test_classes(test_path, module=__name__, class_name_prefix='',
950-
expected_failures=[]):
952+
expected_failures=[],
953+
bypass_test_generation_errors=False):
951954
"""Method for generating test classes. Returns a dictionary where keys are
952955
the names of test classes and values are the test class objects."""
953956
test_klasses = {}
@@ -979,17 +982,22 @@ class SpecTestBase(with_metaclass(UnifiedSpecTestMeta)):
979982
test_type.replace('-', '_').replace('.', '_'))
980983
class_name = snake_to_camel(snake_class_name)
981984

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})
985+
try:
986+
schema_version = Version.from_string(
987+
scenario_def['schemaVersion'])
988+
mixin_class = _SCHEMA_VERSION_MAJOR_TO_MIXIN_CLASS.get(
989+
schema_version[0])
990+
if mixin_class is None:
991+
raise ValueError(
992+
"test file '%s' has unsupported schemaVersion '%s'" % (
993+
fpath, schema_version))
994+
test_klasses[class_name] = type(
995+
class_name,
996+
(mixin_class, test_base_class_factory(scenario_def),),
997+
{'__module__': module})
998+
except Exception:
999+
if bypass_test_generation_errors:
1000+
continue
1001+
raise
9941002

9951003
return test_klasses

0 commit comments

Comments
 (0)