Skip to content

Commit 2b575b8

Browse files
fineguyThe TensorFlow Datasets Authors
authored andcommitted
Update TestCaseInContext.
PiperOrigin-RevId: 616762965
1 parent 76642e2 commit 2b575b8

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

tensorflow_datasets/testing/test_case.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ def setUp(self):
5959
# get_temp_dir is actually the same for all tests, so create a temp sub-dir.
6060
self.tmp_dir = tempfile.mkdtemp(dir=tf.compat.v1.test.get_temp_dir())
6161

62-
def assertRaisesWithPredicateMatch(self, err_type, predicate):
63-
if isinstance(predicate, str):
64-
predicate_fct = lambda err: predicate in str(err)
65-
else:
66-
predicate_fct = predicate
67-
return super().assertRaisesWithPredicateMatch(err_type, predicate_fct)
68-
6962
@contextlib.contextmanager
7063
def assertLogs(self, text, level="info"):
7164
with mock.patch.object(logging, level) as mock_log:

tensorflow_datasets/testing/test_case_in_context.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
from collections.abc import Sequence
1919
import contextlib
2020
from typing import Any, ContextManager
21-
import unittest
2221

22+
from absl.testing import absltest
2323

24-
class TestCaseInContext(unittest.TestCase):
24+
25+
class TestCaseInContext(absltest.TestCase):
2526
"""Base TestCase for running tests inside the given contexts.
2627
2728
It ensures that all contexts are entered before any test starts and are exited
@@ -47,3 +48,10 @@ def tearDownClass(cls):
4748
# Exit all contexts in the reverse order
4849
cls._stack.close()
4950
super().tearDownClass()
51+
52+
def assertRaisesWithPredicateMatch(self, err_type, predicate): # pylint: disable=invalid-name
53+
if isinstance(predicate, str):
54+
predicate_fn = lambda err: predicate in str(err)
55+
else:
56+
predicate_fn = predicate
57+
return super().assertRaisesWithPredicateMatch(err_type, predicate_fn)

0 commit comments

Comments
 (0)