@@ -148,7 +148,6 @@ def setUpClass(cls):
148
148
tf .enable_v2_behavior ()
149
149
super (DatasetBuilderTestCase , cls ).setUpClass ()
150
150
name = cls .__name__
151
- cls ._download_urls = set ()
152
151
# Check class has the right attributes
153
152
if cls .DATASET_CLASS is None or not callable (cls .DATASET_CLASS ):
154
153
raise AssertionError (
@@ -171,6 +170,15 @@ def setUp(self):
171
170
if self .MOCK_OUT_FORBIDDEN_OS_FUNCTIONS :
172
171
self ._mock_out_forbidden_os_functions ()
173
172
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
+
174
182
def tearDown (self ):
175
183
super (DatasetBuilderTestCase , self ).tearDown ()
176
184
for patcher in self .patchers :
@@ -222,6 +230,10 @@ def test_info(self):
222
230
self .assertEqual (self .builder .name , info .name )
223
231
224
232
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
225
237
if isinstance (url_or_urls , download .resource .Resource ):
226
238
self ._download_urls .add (url_or_urls .url )
227
239
else :
@@ -244,6 +256,9 @@ def _get_dl_download_result(self, url):
244
256
return utils .map_nested (lambda fname : os .path .join (self .example_dir , fname ),
245
257
self .DL_DOWNLOAD_RESULT )
246
258
259
+ def _download_checksums (self , url ):
260
+ self ._stop_record_download = True
261
+
247
262
def _make_builder (self , config = None ):
248
263
return self .DATASET_CLASS ( # pylint: disable=not-callable
249
264
data_dir = self .tmp_dir ,
@@ -317,7 +332,7 @@ def _download_and_prepare_as_dataset(self, builder):
317
332
"tensorflow_datasets.core.download.DownloadManager" ,
318
333
download_and_extract = self ._get_dl_extract_result ,
319
334
download = self ._get_dl_download_result ,
320
- download_checksums = lambda * _ : None ,
335
+ download_checksums = self . _download_checksums ,
321
336
manual_dir = manual_dir ,
322
337
):
323
338
if isinstance (builder , dataset_builder .BeamBasedBuilder ):
0 commit comments