Skip to content

Commit 6c5f55e

Browse files
committed
tensorflow_datasets/testing pylint errors fixed
1 parent 3367582 commit 6c5f55e

19 files changed

+71
-71
lines changed

tensorflow_datasets/core/api_utils_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ def fn(a, b, c=api_utils.REQUIRED_ARG, d=4):
3434
self.assertEqual(["a", "b", "c", "d"], api_utils.getargspec(fn).args)
3535
self.assertEqual((1, 2, 3, 4), fn(a=1, b=2, c=3))
3636
predicate = "use keyword"
37-
with self.assertRaisesWithPredicateMatch(ValueError, predicate):
37+
with self.assert_raises_with_predicate_match(ValueError, predicate):
3838
fn(1, 2, 3)
39-
with self.assertRaisesWithPredicateMatch(ValueError, predicate):
39+
with self.assert_raises_with_predicate_match(ValueError, predicate):
4040
fn(1, b=2, c=3)
41-
with self.assertRaisesWithPredicateMatch(ValueError, "is required"):
41+
with self.assert_raises_with_predicate_match(ValueError, "is required"):
4242
fn(a=1, b=2)
4343

4444
def test_disallow_positional_args_with_exceptions(self):
@@ -50,7 +50,7 @@ def fn(a, b, c=api_utils.REQUIRED_ARG, d=4):
5050
self.assertEqual(["a", "b", "c", "d"], api_utils.getargspec(fn).args)
5151
self.assertEqual((1, 2, 3, 4), fn(a=1, b=2, c=3))
5252
predicate = "use keyword"
53-
with self.assertRaisesWithPredicateMatch(ValueError, predicate):
53+
with self.assert_raises_with_predicate_match(ValueError, predicate):
5454
fn(1, 2, 3)
5555
self.assertEqual((1, 2, 3, 4), fn(1, b=2, c=3))
5656

@@ -70,11 +70,11 @@ def fn(self, a, b, c=api_utils.REQUIRED_ARG, d=4):
7070

7171
self.assertEqual((1, 2, 3, 4, 5), fn(a=1, b=2, c=3))
7272
predicate = "use keyword"
73-
with self.assertRaisesWithPredicateMatch(ValueError, predicate):
73+
with self.assert_raises_with_predicate_match(ValueError, predicate):
7474
fn(1, 2, 3)
75-
with self.assertRaisesWithPredicateMatch(ValueError, predicate):
75+
with self.assert_raises_with_predicate_match(ValueError, predicate):
7676
fn(1, b=2, c=3)
77-
with self.assertRaisesWithPredicateMatch(ValueError, "is required"):
77+
with self.assert_raises_with_predicate_match(ValueError, "is required"):
7878
fn(a=1, b=2)
7979

8080

tensorflow_datasets/core/dataset_builder_beam_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class BeamBasedBuilderTest(testing.TestCase):
136136
def test_download_prepare_raise(self):
137137
with testing.tmp_dir(self.get_temp_dir()) as tmp_dir:
138138
builder = DummyBeamDataset(data_dir=tmp_dir)
139-
with self.assertRaisesWithPredicateMatch(ValueError, "no Beam Runner"):
139+
with self.assert_raises_with_predicate_match(ValueError, "no Beam Runner"):
140140
builder.download_and_prepare()
141141

142142
def _assertBeamGeneration(self, dl_config, dataset_cls, dataset_name):

tensorflow_datasets/core/dataset_builder_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ def test_latest_experimental_version(self):
302302

303303
def test_with_unsupported_version(self):
304304
expected = "Dataset dummy_dataset_with_configs cannot be loaded at version"
305-
with self.assertRaisesWithPredicateMatch(AssertionError, expected):
305+
with self.assert_raises_with_predicate_match(AssertionError, expected):
306306
DummyDatasetWithConfigs(config="plus1", version="0.0.2")
307-
with self.assertRaisesWithPredicateMatch(AssertionError, expected):
307+
with self.assert_raises_with_predicate_match(AssertionError, expected):
308308
DummyDatasetWithConfigs(config="plus1", version="0.1.*")
309309

310310
def test_previous_supported_version(self):
@@ -322,12 +322,12 @@ def test_non_preparable_version(self, *unused_mocks):
322322
"(available for `download_and_prepare`: 1.0.0, 2.0.0, 0.0.9, 0.0.8).")
323323
builder = DummyDatasetSharedGenerator(version="0.0.7")
324324
self.assertIsNotNone(builder)
325-
with self.assertRaisesWithPredicateMatch(AssertionError, expected):
325+
with self.assert_raises_with_predicate_match(AssertionError, expected):
326326
builder.download_and_prepare()
327327

328328
def test_invalid_split_dataset(self):
329329
with testing.tmp_dir(self.get_temp_dir()) as tmp_dir:
330-
with self.assertRaisesWithPredicateMatch(
330+
with self.assert_raises_with_predicate_match(
331331
ValueError, "`all` is a special"):
332332
# Raise error during .download_and_prepare()
333333
registered.load(

tensorflow_datasets/core/dataset_info_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ def tearDownClass(cls):
8282
testing.rm_tmp_dir(cls._tfds_tmp_dir)
8383

8484
def test_undefined_dir(self):
85-
with self.assertRaisesWithPredicateMatch(ValueError,
85+
with self.assert_raises_with_predicate_match(ValueError,
8686
"undefined dataset_info_dir"):
8787
info = dataset_info.DatasetInfo(builder=self._builder)
8888
info.read_from_directory(None)
8989

9090
def test_non_existent_dir(self):
9191
info = dataset_info.DatasetInfo(builder=self._builder)
92-
with self.assertRaisesWithPredicateMatch(
92+
with self.assert_raises_with_predicate_match(
9393
tf.errors.NotFoundError, "No such file or dir"):
9494
info.read_from_directory(_NON_EXISTENT_DIR)
9595

tensorflow_datasets/core/download/extractor_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def test_wrong_method(self):
129129
from_path = os.path.join(self.test_data, 'archives', 'foo.csv.gz')
130130
promise = self.extractor.extract(from_path, ZIP, self.to_path)
131131
expected_msg = 'File is not a zip file'
132-
with self.assertRaisesWithPredicateMatch(
132+
with self.assert_raises_with_predicate_match(
133133
extractor.ExtractError, expected_msg):
134134
promise.get()
135135

tensorflow_datasets/core/features/class_label_feature_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ def test_num_classes(self):
8686
self.assertEqual(1, labels.str2int('1'))
8787
self.assertEqual(u'1', labels.int2str(1))
8888

89-
with self.assertRaisesWithPredicateMatch(ValueError, 'Invalid'):
89+
with self.assert_raises_with_predicate_match(ValueError, 'Invalid'):
9090
labels.str2int('10')
91-
with self.assertRaisesWithPredicateMatch(ValueError, 'Invalid'):
91+
with self.assert_raises_with_predicate_match(ValueError, 'Invalid'):
9292
labels.int2str(10)
9393

9494
def test_str_classes(self):
@@ -119,7 +119,7 @@ def test_save_load(self):
119119
with testing.tmp_dir(self.get_temp_dir()) as tmp_dir:
120120
labels1.save_metadata(tmp_dir, 'test-labels')
121121
labels2.load_metadata(tmp_dir, 'test-labels')
122-
with self.assertRaisesWithPredicateMatch(
122+
with self.assert_raises_with_predicate_match(
123123
ValueError, 'number of names do not match the defined num_classes'):
124124
labels3.load_metadata(tmp_dir, 'test-labels')
125125

@@ -134,27 +134,27 @@ def test_save_load(self):
134134
def test_names(self):
135135

136136
labels = features.ClassLabel(names=['label3', 'label1', 'label2'])
137-
with self.assertRaisesWithPredicateMatch(
137+
with self.assert_raises_with_predicate_match(
138138
ValueError, 'overwrite already defined ClassLabel'):
139139
labels.names = ['other', 'labels']
140140

141141
labels = features.ClassLabel()
142142
labels.names = ['label3', 'label1', 'label2']
143-
with self.assertRaisesWithPredicateMatch(
143+
with self.assert_raises_with_predicate_match(
144144
ValueError, 'overwrite already defined ClassLabel'):
145145
labels.names = ['other', 'labels']
146146

147147
labels = features.ClassLabel(num_classes=3)
148148
labels.names = ['label3', 'label1', 'label2']
149149

150150
labels = features.ClassLabel(num_classes=3)
151-
with self.assertRaisesWithPredicateMatch(
151+
with self.assert_raises_with_predicate_match(
152152
ValueError, 'number of names do not match the defined num_classes'):
153153
labels.names = ['label3', 'label1']
154154

155155
def test_duplicate_names(self):
156156

157-
with self.assertRaisesWithPredicateMatch(
157+
with self.assert_raises_with_predicate_match(
158158
ValueError, 'label names are duplicated'):
159159
features.ClassLabel(names=['label1', 'label1', 'label2'])
160160

tensorflow_datasets/core/features/sequence_feature_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def to_ragged(ex):
224224
self.assert_all_equal_nested(to_ragged(ex4), out)
225225

226226
# Should raise error if two sequences do not have the same length.
227-
with self.assertRaisesWithPredicateMatch(
227+
with self.assert_raises_with_predicate_match(
228228
ValueError, 'length of all elements'):
229229
f.encode_example({
230230
'a': {'c': [[1, 1, 1], []]},

tensorflow_datasets/core/features/top_level_feature_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_sequence_rank(self):
3737
shape=(None,), dtype=tf.int32, sequence_rank=1),
3838
}))
3939

40-
with self.assertRaisesWithPredicateMatch(
40+
with self.assert_raises_with_predicate_match(
4141
NotImplementedError, 'mixing sequence and context'):
4242
top_level_feature._get_sequence_rank({
4343
'a': features_lib.TensorInfo(
@@ -100,14 +100,14 @@ def test_flatten_nested(self):
100100
'c': tf.int32,
101101
},
102102
})
103-
with self.assertRaisesWithPredicateMatch(ValueError, 'received a non dict'):
103+
with self.assert_raises_with_predicate_match(ValueError, 'received a non dict'):
104104
f._flatten({'b': 123})
105105

106-
with self.assertRaisesWithPredicateMatch(
106+
with self.assert_raises_with_predicate_match(
107107
ValueError, 'Unrecognized keys: [\'d\']'):
108108
f._flatten({'b': {'c': 123, 'd': 123}})
109109

110-
with self.assertRaisesWithPredicateMatch(
110+
with self.assert_raises_with_predicate_match(
111111
ValueError, 'Expected length 2 does not match input length 3'):
112112
f._nest([None, None, None])
113113

@@ -129,7 +129,7 @@ def test_top_level(self):
129129
},
130130
})
131131

132-
with self.assertRaisesWithPredicateMatch(
132+
with self.assert_raises_with_predicate_match(
133133
AssertionError, 'decoded when defined as top-level'):
134134
f['b'].decode_example({'c': 1})
135135

tensorflow_datasets/core/file_format_adapter_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ def test_dict_to_example(self):
134134
self.assertEqual([b"\x00\x00", b"\x00\x00"],
135135
list(feature["e2"].bytes_list.value))
136136

137-
with self.assertRaisesWithPredicateMatch(ValueError, "Received an empty"):
137+
with self.assert_raises_with_predicate_match(ValueError, "Received an empty"):
138138
# Raise error if an undefined empty value is given
139139
example_serializer._dict_to_tf_example({
140140
"empty": [],
141141
})
142142

143-
with self.assertRaisesWithPredicateMatch(ValueError, "not support type"):
143+
with self.assert_raises_with_predicate_match(ValueError, "not support type"):
144144
# Raise error if an unsupported dtype is given
145145
example_serializer._dict_to_tf_example({
146146
"wrong_type": np.zeros(shape=(5,), dtype=np.complex64),
@@ -318,7 +318,7 @@ def assertWrongSpecs(self, specs, raise_cls, raise_msg):
318318

319319
adapter = file_format_adapter.TFRecordExampleAdapter({"wrong_field": specs})
320320
# Raise error if an unsupported dtype is given
321-
with self.assertRaisesWithPredicateMatch(raise_cls, raise_msg):
321+
with self.assert_raises_with_predicate_match(raise_cls, raise_msg):
322322
adapter._parser._build_feature_specs()
323323

324324
@testing.run_in_graph_and_eager_modes()
@@ -334,7 +334,7 @@ def assert_feature(self, specs, serialized_info, tests):
334334
with self._sub_test(str(i)):
335335

336336
if test.raise_cls is not None:
337-
with self.assertRaisesWithPredicateMatch(
337+
with self.assert_raises_with_predicate_match(
338338
test.raise_cls, test.raise_msg):
339339
adapter._serializer.serialize_example(test.value)
340340
continue

tensorflow_datasets/core/lazy_imports_lib_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_import(self, module_name):
5555
getattr(tfds.core.lazy_imports, module_name)
5656

5757
def test_bad_import(self):
58-
with self.assertRaisesWithPredicateMatch(ImportError, "extras_require"):
58+
with self.assert_raises_with_predicate_match(ImportError, "extras_require"):
5959
_ = tfds.core.lazy_imports.test_foo
6060

6161

tensorflow_datasets/core/registered_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,26 @@ def test_registered(self):
6868
self.assertIn(name, registered.list_builders())
6969

7070
nonexistent = "nonexistent_foobar_dataset"
71-
with self.assertRaisesWithPredicateMatch(ValueError, "not found"):
71+
with self.assert_raises_with_predicate_match(ValueError, "not found"):
7272
registered.builder(nonexistent)
7373
# Prints registered datasets
74-
with self.assertRaisesWithPredicateMatch(ValueError, name):
74+
with self.assert_raises_with_predicate_match(ValueError, name):
7575
registered.builder(nonexistent)
7676

7777
def test_abstract(self):
7878
name = "unregistered_builder"
7979
self.assertEqual(name, UnregisteredBuilder.name)
8080
self.assertNotIn(name, registered.list_builders())
8181

82-
with self.assertRaisesWithPredicateMatch(ValueError, "an abstract class"):
82+
with self.assert_raises_with_predicate_match(ValueError, "an abstract class"):
8383
registered.builder(name)
8484

8585
def test_in_development(self):
8686
name = "in_development_dataset_builder"
8787
self.assertEqual(name, InDevelopmentDatasetBuilder.name)
8888
self.assertNotIn(name, registered.list_builders())
8989

90-
with self.assertRaisesWithPredicateMatch(
90+
with self.assert_raises_with_predicate_match(
9191
ValueError,
9292
("Dataset %s is under active development and is not available yet."
9393
) % name):
@@ -200,7 +200,7 @@ def test_duplicate_dataset(self):
200200
class DuplicateBuilder(object):
201201
pass
202202

203-
with self.assertRaisesWithPredicateMatch(ValueError, "already registered"):
203+
with self.assert_raises_with_predicate_match(ValueError, "already registered"):
204204
@six.add_metaclass(registered.RegisteredDataset) # pylint: disable=function-redefined
205205
class DuplicateBuilder(object):
206206
pass

tensorflow_datasets/core/shuffle_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ def test_disk(self):
114114

115115
def test_nonbytes(self):
116116
shuffler = shuffle.Shuffler(self.get_temp_dir(), 'split1')
117-
with self.assertRaisesWithPredicateMatch(AssertionError, 'Only bytes'):
117+
with self.assert_raises_with_predicate_match(AssertionError, 'Only bytes'):
118118
shuffler.add(1, u'a')
119-
with self.assertRaisesWithPredicateMatch(AssertionError, 'Only bytes'):
119+
with self.assert_raises_with_predicate_match(AssertionError, 'Only bytes'):
120120
shuffler.add(1, 123)
121121

122122
def test_duplicate_key(self):

tensorflow_datasets/core/splits_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,12 @@ def test_split_equality(self):
268268
test = tfds.Split.TEST
269269
train = tfds.Split.TRAIN
270270

271-
with self.assertRaisesWithPredicateMatch(
271+
with self.assert_raises_with_predicate_match(
272272
NotImplementedError,
273273
"Equality is not implemented between merged/sub splits."):
274274
_ = test.subsplit(tfds.percent[10:]) == test.subsplit(tfds.percent[10:])
275275

276-
with self.assertRaisesWithPredicateMatch(
276+
with self.assert_raises_with_predicate_match(
277277
NotImplementedError,
278278
"Equality is not implemented between merged/sub splits."):
279279
_ = test + train == test + train
@@ -485,23 +485,23 @@ def test_split_invalid(self):
485485
# Cannot add a split with himself
486486
test = tfds.Split.TEST
487487

488-
with self.assertRaisesWithPredicateMatch(ValueError, "added with itself"):
488+
with self.assert_raises_with_predicate_match(ValueError, "added with itself"):
489489
split = test + test
490490
self._builder.values(split=split)
491491

492-
with self.assertRaisesWithPredicateMatch(ValueError, "added with itself"):
492+
with self.assert_raises_with_predicate_match(ValueError, "added with itself"):
493493
split = (test.subsplit(tfds.percent[:10]) +
494494
test.subsplit(tfds.percent[10:]))
495495
self._builder.values(split=split)
496496

497497
# Cannot slice a split twice
498498

499-
with self.assertRaisesWithPredicateMatch(
499+
with self.assert_raises_with_predicate_match(
500500
ValueError, "has already been sliced"):
501501
split = test.subsplit(tfds.percent[:10]).subsplit(tfds.percent[:10])
502502
self._builder.values(split=split)
503503

504-
with self.assertRaisesWithPredicateMatch(
504+
with self.assert_raises_with_predicate_match(
505505
ValueError, "has already been sliced"):
506506
split = test.subsplit(tfds.percent[10:]) + tfds.Split.TRAIN
507507
split = split.subsplit(tfds.percent[:50])
@@ -629,7 +629,7 @@ def test_split_file_instructions(self):
629629
}])
630630

631631
def test_sub_split_wrong_key(self):
632-
with self.assertRaisesWithPredicateMatch(
632+
with self.assert_raises_with_predicate_match(
633633
ValueError, "Unknown split \"unknown\""):
634634
_ = self._builder.info.splits["unknown"]
635635

0 commit comments

Comments
 (0)