Skip to content

Commit dd8b5de

Browse files
Merge pull request #1721 from Eshan-Agarwal:patch-33
PiperOrigin-RevId: 302932579
2 parents 5ef7651 + 10cbec5 commit dd8b5de

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

tensorflow_datasets/audio/crema_d_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class CremaDTest(testing.DatasetBuilderTestCase):
4040
'1002_AA_ANG_XX.wav', '1003_AA_FEA_XX.wav',
4141
]
4242
}
43-
SKIP_CHECKSUMS = True # TODO(tfds): Update checksums
4443

4544

4645
if __name__ == '__main__':

tensorflow_datasets/testing/dataset_builder_testing.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ def setUpClass(cls):
148148
tf.enable_v2_behavior()
149149
super(DatasetBuilderTestCase, cls).setUpClass()
150150
name = cls.__name__
151-
cls._download_urls = set()
152151
# Check class has the right attributes
153152
if cls.DATASET_CLASS is None or not callable(cls.DATASET_CLASS):
154153
raise AssertionError(
@@ -171,6 +170,15 @@ def setUp(self):
171170
if self.MOCK_OUT_FORBIDDEN_OS_FUNCTIONS:
172171
self._mock_out_forbidden_os_functions()
173172

173+
# Track the urls which are downloaded to validate the checksums
174+
# The `dl_manager.download` and `dl_manager.download_and_extract` are
175+
# patched to record the urls in `_download_urls`.
176+
# Calling `dl_manager.download_checksums` stop the url
177+
# registration (as checksums are stored remotelly)
178+
# `_test_checksums` validates the recorded urls.
179+
self._download_urls = set()
180+
self._stop_record_download = False
181+
174182
def tearDown(self):
175183
super(DatasetBuilderTestCase, self).tearDown()
176184
for patcher in self.patchers:
@@ -222,6 +230,10 @@ def test_info(self):
222230
self.assertEqual(self.builder.name, info.name)
223231

224232
def _add_url(self, url_or_urls):
233+
if self._stop_record_download:
234+
# Stop record the checksums if dl_manager.download_checksums has been
235+
# called (as checksums may be stored remotelly)
236+
return
225237
if isinstance(url_or_urls, download.resource.Resource):
226238
self._download_urls.add(url_or_urls.url)
227239
else:
@@ -244,6 +256,9 @@ def _get_dl_download_result(self, url):
244256
return utils.map_nested(lambda fname: os.path.join(self.example_dir, fname),
245257
self.DL_DOWNLOAD_RESULT)
246258

259+
def _download_checksums(self, url):
260+
self._stop_record_download = True
261+
247262
def _make_builder(self, config=None):
248263
return self.DATASET_CLASS( # pylint: disable=not-callable
249264
data_dir=self.tmp_dir,
@@ -317,7 +332,7 @@ def _download_and_prepare_as_dataset(self, builder):
317332
"tensorflow_datasets.core.download.DownloadManager",
318333
download_and_extract=self._get_dl_extract_result,
319334
download=self._get_dl_download_result,
320-
download_checksums=lambda *_: None,
335+
download_checksums=self._download_checksums,
321336
manual_dir=manual_dir,
322337
):
323338
if isinstance(builder, dataset_builder.BeamBasedBuilder):

0 commit comments

Comments
 (0)