Skip to content

Commit c8c00f0

Browse files
dbiebercopybara-github
authored andcommitted
Adds support for EXAMPLE_DIR config to tfds tests.
PiperOrigin-RevId: 238093283
1 parent e269bc8 commit c8c00f0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tensorflow_datasets/testing/dataset_builder_testing.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class DatasetBuilderTestCase(parameterized.TestCase, test_utils.SubTestCase):
7777
`download_and_extract` method. The values should be the path of files
7878
present in the `fake_examples` directory, relative to that directory.
7979
If not specified, path to `fake_examples` will always be returned.
80+
EXAMPLE_DIR: `str`, the base directory in in which fake examples are
81+
contained. Optional; defaults to
82+
tensorflow_datasets/testing/test_data/fake_examples/<dataset name>.
8083
OVERLAPPING_SPLITS: `list[str]`, splits containing examples from other
8184
splits (e.g. a "example" split containing pictures from other splits).
8285
MOCK_OUT_FORBIDDEN_OS_FUNCTIONS: `bool`, defaults to True. Set to False to
@@ -100,6 +103,7 @@ class DatasetBuilderTestCase(parameterized.TestCase, test_utils.SubTestCase):
100103
DATASET_CLASS = None
101104
BUILDER_CONFIG_NAMES_TO_TEST = []
102105
DL_EXTRACT_RESULT = None
106+
EXAMPLE_DIR = None
103107
OVERLAPPING_SPLITS = []
104108
MOCK_OUT_FORBIDDEN_OS_FUNCTIONS = True
105109

@@ -117,9 +121,14 @@ def setUp(self):
117121
super(DatasetBuilderTestCase, self).setUp()
118122
self.patchers = []
119123
self.builder = self._make_builder()
124+
125+
# Determine the fake_examples directory.
120126
self.example_dir = os.path.join(
121127
os.path.dirname(__file__),
122128
"test_data/fake_examples/%s" % self.builder.name)
129+
if self.EXAMPLE_DIR is not None:
130+
self.example_dir = self.EXAMPLE_DIR
131+
123132
if not tf.io.gfile.exists(self.example_dir):
124133
err_msg = "fake_examples dir %s not found." % self.example_dir
125134
raise ValueError(err_msg)

0 commit comments

Comments
 (0)