Skip to content

Commit 94b5c4a

Browse files
Merge pull request #6 from ixcat/pr-703
tests/{schema,test_jobs}.py: add tests/test_jobs.py:test_suppress_dj_errors
2 parents 04d6d23 + 4801f4d commit 94b5c4a

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

tests/schema.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,38 @@ def make(self, key):
277277
raise SystemExit('SIGTERM received')
278278

279279

280+
@schema
281+
class DjExceptionNames(dj.Lookup):
282+
definition = """
283+
dj_exception_name: char(64)
284+
"""
285+
@property
286+
def contents(self):
287+
ret = []
288+
for e in dir(dj.errors):
289+
ea = getattr(dj.errors, e)
290+
if callable(ea):
291+
try:
292+
werks = (isinstance(ea, type(Exception))
293+
and isinstance(ea(), Exception))
294+
except TypeError as te:
295+
pass
296+
if werks:
297+
ret.append((e,))
298+
return ret
299+
300+
301+
@schema
302+
class ErrorClassTable(dj.Computed):
303+
definition = """
304+
-> DjExceptionNames
305+
"""
306+
def make(self, key):
307+
ename = key['dj_exception_name']
308+
raise getattr(dj.errors, ename)(ename)
309+
310+
311+
280312
@schema
281313
class DecimalPrimaryKey(dj.Lookup):
282314
definition = """

tests/test_jobs.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ def test_sigterm():
8888
assert_equals(error_message, 'SystemExit: SIGTERM received')
8989
schema.schema.jobs.delete()
9090

91+
92+
def test_suppress_dj_errors():
93+
''' test_suppress_dj_errors: dj errors suppressable w/o native py blobs'''
94+
schema.schema.jobs.delete()
95+
with dj.config(enable_python_native_blobs=False):
96+
schema.ErrorClassTable().populate(
97+
reserve_jobs=True, suppress_errors=True)
98+
99+
assert len(schema.DjExceptionNames()) == len(schema.DjExceptionNames
100+
& schema.schema.jobs)
101+
102+
91103
def test_long_error_message():
92104
# clear out jobs table
93105
schema.schema.jobs.delete()

0 commit comments

Comments
 (0)