Skip to content

Commit 1861ea9

Browse files
committed
cleanup of deprecated test methods
PiperOrigin-RevId: 715994558
1 parent 3876e25 commit 1861ea9

File tree

6 files changed

+34
-34
lines changed

6 files changed

+34
-34
lines changed

tensorflow_data_validation/api/stats_api_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def test_stats_pipeline_with_sample_rate(self):
365365

366366
def test_invalid_stats_options(self):
367367
record_batches = [pa.RecordBatch.from_arrays([])]
368-
with self.assertRaisesRegexp(TypeError, '.*should be a StatsOptions.'):
368+
with self.assertRaisesRegex(TypeError, '.*should be a StatsOptions.'):
369369
with beam.Pipeline() as p:
370370
_ = (
371371
p | beam.Create(record_batches)

tensorflow_data_validation/api/validation_api_test.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ def test_infer_schema_multiple_datasets_with_default_slice(self):
665665
self.assertEqual(actual_schema, expected_schema)
666666

667667
def test_infer_schema_invalid_statistics_input(self):
668-
with self.assertRaisesRegexp(
668+
with self.assertRaisesRegex(
669669
TypeError, '.*should be a DatasetFeatureStatisticsList proto.*'):
670670
_ = validation_api.infer_schema({})
671671

@@ -675,7 +675,7 @@ def test_infer_schema_invalid_multiple_datasets_no_default_slice(self):
675675
statistics_pb2.DatasetFeatureStatistics(),
676676
statistics_pb2.DatasetFeatureStatistics()
677677
])
678-
with self.assertRaisesRegexp(ValueError,
678+
with self.assertRaisesRegex(ValueError,
679679
'.*statistics proto with one dataset.*'):
680680
_ = validation_api.infer_schema(statistics)
681681

@@ -999,13 +999,13 @@ def test_update_schema_multiple_datasets_with_default_slice(self):
999999
def test_update_schema_invalid_schema_input(self):
10001000
statistics = statistics_pb2.DatasetFeatureStatisticsList()
10011001
statistics.datasets.extend([statistics_pb2.DatasetFeatureStatistics()])
1002-
with self.assertRaisesRegexp(
1002+
with self.assertRaisesRegex(
10031003
TypeError, 'schema is of type.*'):
10041004
_ = validation_api.update_schema({}, statistics)
10051005

10061006
def test_update_schema_invalid_statistics_input(self):
10071007
schema = schema_pb2.Schema()
1008-
with self.assertRaisesRegexp(
1008+
with self.assertRaisesRegex(
10091009
TypeError, 'statistics is of type.*'):
10101010
_ = validation_api.update_schema(schema, {})
10111011

@@ -1016,7 +1016,7 @@ def test_update_schema_invalid_multiple_datasets_no_default_slice(self):
10161016
statistics_pb2.DatasetFeatureStatistics(),
10171017
statistics_pb2.DatasetFeatureStatistics()
10181018
])
1019-
with self.assertRaisesRegexp(ValueError,
1019+
with self.assertRaisesRegex(ValueError,
10201020
'.*statistics proto with one dataset.*'):
10211021
_ = validation_api.update_schema(schema, statistics)
10221022

@@ -1956,15 +1956,15 @@ def test_validate_stats_with_previous_and_serving_stats_with_default_slices(
19561956

19571957
def test_validate_stats_invalid_statistics_input(self):
19581958
schema = schema_pb2.Schema()
1959-
with self.assertRaisesRegexp(
1959+
with self.assertRaisesRegex(
19601960
TypeError, 'statistics is of type.*'):
19611961
_ = validation_api.validate_statistics({}, schema)
19621962

19631963
def test_validate_stats_invalid_previous_statistics_input(self):
19641964
statistics = statistics_pb2.DatasetFeatureStatisticsList()
19651965
statistics.datasets.extend([statistics_pb2.DatasetFeatureStatistics()])
19661966
schema = schema_pb2.Schema()
1967-
with self.assertRaisesRegexp(
1967+
with self.assertRaisesRegex(
19681968
TypeError, 'previous_statistics is of type.*'):
19691969
_ = validation_api.validate_statistics(statistics, schema,
19701970
previous_statistics='test')
@@ -1973,7 +1973,7 @@ def test_validate_stats_internal_invalid_previous_span_statistics_input(self):
19731973
statistics = statistics_pb2.DatasetFeatureStatisticsList()
19741974
statistics.datasets.extend([statistics_pb2.DatasetFeatureStatistics()])
19751975
schema = schema_pb2.Schema()
1976-
with self.assertRaisesRegexp(TypeError,
1976+
with self.assertRaisesRegex(TypeError,
19771977
'previous_span_statistics is of type.*'):
19781978
_ = validation_api.validate_statistics_internal(
19791979
statistics, schema, previous_span_statistics='test')
@@ -1982,7 +1982,7 @@ def test_validate_stats_invalid_serving_statistics_input(self):
19821982
statistics = statistics_pb2.DatasetFeatureStatisticsList()
19831983
statistics.datasets.extend([statistics_pb2.DatasetFeatureStatistics()])
19841984
schema = schema_pb2.Schema()
1985-
with self.assertRaisesRegexp(
1985+
with self.assertRaisesRegex(
19861986
TypeError, 'serving_statistics is of type.*'):
19871987
_ = validation_api.validate_statistics(statistics, schema,
19881988
serving_statistics='test')
@@ -1991,15 +1991,15 @@ def test_validate_stats_invalid_previous_version_statistics_input(self):
19911991
statistics = statistics_pb2.DatasetFeatureStatisticsList()
19921992
statistics.datasets.extend([statistics_pb2.DatasetFeatureStatistics()])
19931993
schema = schema_pb2.Schema()
1994-
with self.assertRaisesRegexp(TypeError,
1994+
with self.assertRaisesRegex(TypeError,
19951995
'previous_version_statistics is of type.*'):
19961996
_ = validation_api.validate_statistics_internal(
19971997
statistics, schema, previous_version_statistics='test')
19981998

19991999
def test_validate_stats_invalid_schema_input(self):
20002000
statistics = statistics_pb2.DatasetFeatureStatisticsList()
20012001
statistics.datasets.extend([statistics_pb2.DatasetFeatureStatistics()])
2002-
with self.assertRaisesRegexp(TypeError, '.*should be a Schema proto.*'):
2002+
with self.assertRaisesRegex(TypeError, '.*should be a Schema proto.*'):
20032003
_ = validation_api.validate_statistics(statistics, {})
20042004

20052005
def test_validate_stats_invalid_environment(self):
@@ -2017,7 +2017,7 @@ def test_validate_stats_invalid_environment(self):
20172017
type: BYTES
20182018
}
20192019
""", schema_pb2.Schema())
2020-
with self.assertRaisesRegexp(
2020+
with self.assertRaisesRegex(
20212021
ValueError, 'Environment.*not found in the schema.*'):
20222022
_ = validation_api.validate_statistics(statistics, schema,
20232023
environment='INVALID')
@@ -2030,7 +2030,7 @@ def test_validate_stats_invalid_statistics_multiple_datasets_no_default_slice(
20302030
statistics_pb2.DatasetFeatureStatistics()
20312031
])
20322032
schema = schema_pb2.Schema()
2033-
with self.assertRaisesRegexp(
2033+
with self.assertRaisesRegex(
20342034
ValueError, 'Only statistics proto with one dataset or the default.*'):
20352035
_ = validation_api.validate_statistics(statistics, schema)
20362036

@@ -2045,7 +2045,7 @@ def test_validate_stats_invalid_previous_statistics_multiple_datasets(self):
20452045
statistics_pb2.DatasetFeatureStatistics()
20462046
])
20472047
schema = schema_pb2.Schema()
2048-
with self.assertRaisesRegexp(
2048+
with self.assertRaisesRegex(
20492049
ValueError, 'Only statistics proto with one dataset or the default.*'):
20502050
_ = validation_api.validate_statistics(current_stats, schema,
20512051
previous_statistics=previous_stats)
@@ -2061,7 +2061,7 @@ def test_validate_stats_invalid_serving_statistics_multiple_datasets(self):
20612061
statistics_pb2.DatasetFeatureStatistics()
20622062
])
20632063
schema = schema_pb2.Schema()
2064-
with self.assertRaisesRegexp(
2064+
with self.assertRaisesRegex(
20652065
ValueError, 'Only statistics proto with one dataset or the default.*'):
20662066
_ = validation_api.validate_statistics(current_stats, schema,
20672067
serving_statistics=serving_stats)
@@ -2078,7 +2078,7 @@ def test_validate_stats_invalid_previous_version_stats_multiple_datasets(
20782078
statistics_pb2.DatasetFeatureStatistics()
20792079
])
20802080
schema = schema_pb2.Schema()
2081-
with self.assertRaisesRegexp(
2081+
with self.assertRaisesRegex(
20822082
ValueError, 'Only statistics proto with one dataset or the default.*'):
20832083
_ = validation_api.validate_statistics_internal(
20842084
current_stats,
@@ -2789,22 +2789,22 @@ def test_validate_instance_invalid_environment(self):
27892789
""", schema_pb2.Schema())
27902790
options = stats_options.StatsOptions(schema=schema)
27912791

2792-
with self.assertRaisesRegexp(
2792+
with self.assertRaisesRegex(
27932793
ValueError, 'Environment.*not found in the schema.*'):
27942794
_ = validation_api.validate_instance(
27952795
instance, options, environment='INVALID')
27962796

27972797
def test_validate_instance_invalid_options(self):
27982798
instance = pa.RecordBatch.from_arrays([pa.array([['A']])], ['feature'])
2799-
with self.assertRaisesRegexp(ValueError,
2799+
with self.assertRaisesRegex(ValueError,
28002800
'options must be a StatsOptions object.'):
28012801
_ = validation_api.validate_instance(instance, {})
28022802

28032803
def test_validate_instance_stats_options_without_schema(self):
28042804
instance = pa.RecordBatch.from_arrays([pa.array([['A']])], ['feature'])
28052805
# This instance of StatsOptions has no schema.
28062806
options = stats_options.StatsOptions()
2807-
with self.assertRaisesRegexp(ValueError, 'options must include a schema.'):
2807+
with self.assertRaisesRegex(ValueError, 'options must include a schema.'):
28082808
_ = validation_api.validate_instance(instance, options)
28092809

28102810

@@ -3201,7 +3201,7 @@ def __eq__(self, other):
32013201
def test_identify_anomalous_examples_options_of_wrong_type(self):
32023202
examples = [{'annotated_enum': np.array(['D'], dtype=object)}]
32033203
options = 1
3204-
with self.assertRaisesRegexp(ValueError, 'options must be a `StatsOptions` '
3204+
with self.assertRaisesRegex(ValueError, 'options must be a `StatsOptions` '
32053205
'object.'):
32063206
with beam.Pipeline() as p:
32073207
_ = (
@@ -3211,7 +3211,7 @@ def test_identify_anomalous_examples_options_of_wrong_type(self):
32113211
def test_identify_anomalous_examples_options_without_schema(self):
32123212
examples = [{'annotated_enum': np.array(['D'], dtype=object)}]
32133213
options = stats_options.StatsOptions()
3214-
with self.assertRaisesRegexp(ValueError, 'options must include a schema'):
3214+
with self.assertRaisesRegex(ValueError, 'options must include a schema'):
32153215
with beam.Pipeline() as p:
32163216
_ = (
32173217
p | beam.Create(examples)

tensorflow_data_validation/statistics/generators/natural_language_domain_inferring_stats_generator_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ def test_average_word_heuristic_min_words(self):
7676

7777
def test_nl_generator_bad_initialization(self):
7878
"""Tests bad initialization values."""
79-
with self.assertRaisesRegexp(
79+
with self.assertRaisesRegex(
8080
ValueError,
8181
'NLDomainInferringStatsGenerator expects values_threshold > 0.'):
8282
nlsg.NLDomainInferringStatsGenerator(values_threshold=0)
83-
with self.assertRaisesRegexp(
83+
with self.assertRaisesRegex(
8484
ValueError,
8585
r'NLDomainInferringStatsGenerator expects a match_ratio in \[0, 1\].'):
8686
nlsg.NLDomainInferringStatsGenerator(match_ratio=1.1)

tensorflow_data_validation/utils/stats_gen_lib_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def test_stats_gen_with_invalid_csv_header_in_multiple_files(self):
428428
self._write_records_to_csv(records2, tmp_dir, 'input_data2.csv')
429429
input_data_path = os.path.join(tmp_dir, 'input_data*')
430430

431-
with self.assertRaisesRegexp(
431+
with self.assertRaisesRegex(
432432
ValueError, 'Files have different headers.'):
433433
_ = stats_gen_lib.generate_statistics_from_csv(
434434
data_location=input_data_path, column_names=None, delimiter=',')
@@ -479,7 +479,7 @@ def test_stats_gen_with_header_in_empty_csv_file(self):
479479
input_data_path = self._write_records_to_csv([], self._get_temp_dir(),
480480
'input_data.csv')
481481

482-
with self.assertRaisesRegexp(
482+
with self.assertRaisesRegex(
483483
ValueError, 'Found empty file when reading the header.*'):
484484
_ = stats_gen_lib.generate_statistics_from_csv(
485485
data_location=input_data_path, column_names=None, delimiter=',')
@@ -526,7 +526,7 @@ def test_stats_gen_with_dataframe_invalid_njobs_zero(self):
526526
input_data_path = self._write_records_to_csv(records, self._get_temp_dir(),
527527
'input_data.csv')
528528
dataframe = pd.read_csv(input_data_path)
529-
with self.assertRaisesRegexp(
529+
with self.assertRaisesRegex(
530530
ValueError, 'Invalid n_jobs parameter.*'):
531531
_ = stats_gen_lib.generate_statistics_from_dataframe(
532532
dataframe=dataframe,
@@ -537,7 +537,7 @@ def test_stats_gen_with_dataframe_invalid_njobs_negative(self):
537537
input_data_path = self._write_records_to_csv(records, self._get_temp_dir(),
538538
'input_data.csv')
539539
dataframe = pd.read_csv(input_data_path)
540-
with self.assertRaisesRegexp(
540+
with self.assertRaisesRegex(
541541
ValueError, 'Invalid n_jobs parameter.*'):
542542
_ = stats_gen_lib.generate_statistics_from_dataframe(
543543
dataframe=dataframe,
@@ -557,14 +557,14 @@ def test_get_csv_header(self):
557557
def test_get_csv_header_no_file(self):
558558
data_location = os.path.join(self._get_temp_dir(), 'fileA.csv')
559559
delimiter = ','
560-
with self.assertRaisesRegexp(ValueError, 'No file found.*'):
560+
with self.assertRaisesRegex(ValueError, 'No file found.*'):
561561
_ = stats_gen_lib.get_csv_header(data_location, delimiter)
562562

563563
def test_get_csv_header_empty_file(self):
564564
empty_file = os.path.join(self._get_temp_dir(), 'empty.csv')
565565
open(empty_file, 'w+').close()
566566
delimiter = ','
567-
with self.assertRaisesRegexp(ValueError, 'Found empty file.*'):
567+
with self.assertRaisesRegex(ValueError, 'Found empty file.*'):
568568
_ = stats_gen_lib.get_csv_header(empty_file, delimiter)
569569

570570
def test_get_csv_header_different_headers(self):
@@ -575,7 +575,7 @@ def test_get_csv_header_different_headers(self):
575575
self._write_records_to_csv(records_1, temp_directory, 'input_data_1.csv')
576576
self._write_records_to_csv(records_2, temp_directory, 'input_data_2.csv')
577577
data_location = os.path.join(temp_directory, 'input_data_*.csv')
578-
with self.assertRaisesRegexp(ValueError, 'Files have different headers.'):
578+
with self.assertRaisesRegex(ValueError, 'Files have different headers.'):
579579
_ = stats_gen_lib.get_csv_header(data_location, delimiter)
580580

581581
def test_get_csv_header_gzip(self):

tensorflow_data_validation/utils/test_util_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def test_two_protos_with_same_features_in_different_order(self):
304304
self._test.assert_on_two_protos_with_same_features_in_different_order())
305305

306306
def test_two_protos_with_different_features(self):
307-
with self.assertRaisesRegexp(AssertionError, 'Feature path .*'):
307+
with self.assertRaisesRegex(AssertionError, 'Feature path .*'):
308308
self._test.assert_on_two_protos_with_different_features()
309309

310310
def test_two_protos_with_different_numbers_of_features(self):

tensorflow_data_validation/utils/validation_lib_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def test_validate_examples_in_tfrecord_no_schema(self):
254254
input_data_path = os.path.join(temp_dir_path, 'input_data.tfrecord')
255255
# By default, StatsOptions does not include a schema.
256256
options = stats_options.StatsOptions()
257-
with self.assertRaisesRegexp(
257+
with self.assertRaisesRegex(
258258
ValueError, 'The specified stats_options must include a schema.'):
259259
validation_lib.validate_examples_in_tfrecord(
260260
data_location=input_data_path, stats_options=options)
@@ -532,7 +532,7 @@ def test_validate_examples_in_csv_no_schema(self):
532532
has_schema=False))
533533

534534
assert options.schema is None
535-
with self.assertRaisesRegexp(ValueError, 'The specified stats_options.*'):
535+
with self.assertRaisesRegex(ValueError, 'The specified stats_options.*'):
536536
validation_lib.validate_examples_in_csv(
537537
data_location=data_location,
538538
stats_options=options,

0 commit comments

Comments
 (0)