File tree Expand file tree Collapse file tree 3 files changed +48
-11
lines changed Expand file tree Collapse file tree 3 files changed +48
-11
lines changed Original file line number Diff line number Diff line change 32
32
TF2_IGNORE=$( for test in $TF2_IGNORE_TESTS ; do echo " --ignore=$test " ; done)
33
33
34
34
# Run Tests
35
- pytest $TF2_IGNORE --ignore=" tensorflow_datasets/testing/test_utils.py"
35
+ # Ignores:
36
+ # * Some TF2 tests if running against TF2 (see above)
37
+ # * test_utils.py is not a test file
38
+ # * eager_not_enabled_by_default_test needs to be run separately because the
39
+ # enable_eager_execution calls set global state and pytest runs all the tests
40
+ # in the same process.
41
+ pytest \
42
+ --disable-warnings \
43
+ $TF2_IGNORE \
44
+ --ignore=" tensorflow_datasets/testing/test_utils.py" \
45
+ --ignore=" tensorflow_datasets/eager_not_enabled_by_default_test.py"
36
46
set_status
47
+ # If not running with TF2, ensure Eager is not enabled by default
48
+ if [[ " $TF_VERSION " != " tf2" ]]
49
+ then
50
+ pytest \
51
+ --disable-warnings \
52
+ tensorflow_datasets/eager_not_enabled_by_default_test.py
53
+ set_status
54
+ fi
37
55
38
56
# Test notebooks in isolated environments
39
57
NOTEBOOKS="
@@ -54,8 +72,9 @@ function test_notebook() {
54
72
set_status
55
73
}
56
74
57
- # Re-enable as TF 2.0 gets closer to stable release
75
+ # TODO(tfds): Re-enable as TF 2.0 gets closer to stable release
58
76
if [[ " $PY_BIN " = " python2.7" && " $TF_VERSION " = " tf2" ]]
77
+ then
59
78
echo " Skipping notebook tests"
60
79
else
61
80
for notebook in $NOTEBOOKS
Original file line number Diff line number Diff line change @@ -197,14 +197,17 @@ def test_restore_after_modification(self):
197
197
})
198
198
199
199
def test_reading_from_gcs_bucket (self ):
200
- mnist_builder = mnist .MNIST (
201
- data_dir = tempfile .mkdtemp (dir = self .get_temp_dir ()))
202
- info = dataset_info .DatasetInfo (builder = mnist_builder )
203
- info = mnist_builder .info
204
-
205
- # A nominal check to see if we read it.
206
- self .assertTrue (info .initialized )
207
- self .assertEqual (10000 , info .splits ["test" ].num_examples )
200
+ # The base TestCase prevents GCS access, so we explicitly ask it to restore
201
+ # access here.
202
+ with self .gcs_access ():
203
+ mnist_builder = mnist .MNIST (
204
+ data_dir = tempfile .mkdtemp (dir = self .get_temp_dir ()))
205
+ info = dataset_info .DatasetInfo (builder = mnist_builder )
206
+ info = mnist_builder .info
207
+
208
+ # A nominal check to see if we read it.
209
+ self .assertTrue (info .initialized )
210
+ self .assertEqual (10000 , info .splits ["test" ].num_examples )
208
211
209
212
def test_str_smoke (self ):
210
213
info = mnist .MNIST (data_dir = "/tmp/some_dummy_dir" ).info
Original file line number Diff line number Diff line change 19
19
from __future__ import division
20
20
from __future__ import print_function
21
21
22
+ import contextlib
22
23
import os
23
24
import tempfile
24
25
29
30
30
31
31
32
33
+ GCS_ACCESS_FNS = {
34
+ "original" : dataset_info .gcs_dataset_files ,
35
+ "dummy" : lambda _ : []
36
+ }
37
+
38
+
32
39
class TestCase (tf .test .TestCase ):
33
40
"""Base TestCase to be used for all tests.
34
41
@@ -41,7 +48,15 @@ def setUpClass(cls):
41
48
super (TestCase , cls ).setUpClass ()
42
49
cls .test_data = os .path .join (os .path .dirname (__file__ ), "test_data" )
43
50
# Test must not communicate with GCS.
44
- dataset_info .gcs_dataset_files = lambda _ : []
51
+ dataset_info .gcs_dataset_files = GCS_ACCESS_FNS ["dummy" ]
52
+
53
+ @contextlib .contextmanager
54
+ def gcs_access (self ):
55
+ # Restore GCS access
56
+ dataset_info .gcs_dataset_files = GCS_ACCESS_FNS ["original" ]
57
+ yield
58
+ # Revert access
59
+ dataset_info .gcs_dataset_files = GCS_ACCESS_FNS ["dummy" ]
45
60
46
61
def setUp (self ):
47
62
super (TestCase , self ).setUp ()
You can’t perform that action at this time.
0 commit comments