From 88ffa9a438c36dc1149b54f2eb0b3192a1835f17 Mon Sep 17 00:00:00 2001 From: Karthikeyan Singaravelan Date: Thu, 14 Oct 2021 11:50:06 +0000 Subject: [PATCH] Refactor deprecated unittest aliases for Python 3.11 compatibility. --- test/cmdline_test.py | 2 +- test/contrib/external_daily_snapshot_test.py | 8 +++---- test/contrib/hdfs_test.py | 22 ++++++++++---------- test/contrib/postgres_test.py | 4 ++-- test/contrib/s3_test.py | 8 +++---- test/interface_test.py | 4 ++-- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/test/cmdline_test.py b/test/cmdline_test.py index 7db317ded2..f8d2b4ced8 100644 --- a/test/cmdline_test.py +++ b/test/cmdline_test.py @@ -362,7 +362,7 @@ def test_cmd_line_params_are_available_for_execution_summary(self): print(stdout) print(stderr) - self.assertNotEquals(returncode, 1) + self.assertNotEqual(returncode, 1) self.assertFalse(b'required_test_param' in stderr) diff --git a/test/contrib/external_daily_snapshot_test.py b/test/contrib/external_daily_snapshot_test.py index ff273dd751..53c9d8a0b5 100644 --- a/test/contrib/external_daily_snapshot_test.py +++ b/test/contrib/external_daily_snapshot_test.py @@ -32,18 +32,18 @@ class ExternalDailySnapshotTest(unittest.TestCase): def test_latest(self): MockTarget('data-xyz-zebra-Congo-2012-01-01').open('w').close() d = DataDump.latest(date=datetime.date(2012, 1, 10), param='xyz') - self.assertEquals(d.date, datetime.date(2012, 1, 1)) + self.assertEqual(d.date, datetime.date(2012, 1, 1)) def test_latest_not_exists(self): MockTarget('data-abc-zebra-Congo-2012-01-01').open('w').close() d = DataDump.latest(date=datetime.date(2012, 1, 11), param='abc', lookback=5) - self.assertEquals(d.date, datetime.date(2012, 1, 7)) + self.assertEqual(d.date, datetime.date(2012, 1, 7)) def test_deterministic(self): MockTarget('data-pqr-zebra-Congo-2012-01-01').open('w').close() d = DataDump.latest(date=datetime.date(2012, 1, 10), param='pqr', a='zebra', aa='Congo') - self.assertEquals(d.date, datetime.date(2012, 1, 1)) + self.assertEqual(d.date, datetime.date(2012, 1, 1)) MockTarget('data-pqr-zebra-Congo-2012-01-05').open('w').close() d = DataDump.latest(date=datetime.date(2012, 1, 10), param='pqr', aa='Congo', a='zebra') - self.assertEquals(d.date, datetime.date(2012, 1, 1)) # Should still be the same + self.assertEqual(d.date, datetime.date(2012, 1, 1)) # Should still be the same diff --git a/test/contrib/hdfs_test.py b/test/contrib/hdfs_test.py index a7ab79c1fd..82db156f08 100644 --- a/test/contrib/hdfs_test.py +++ b/test/contrib/hdfs_test.py @@ -168,7 +168,7 @@ def test_glob_exists(self): self.assertFalse(files.glob_exists(3)) self.assertFalse(files.glob_exists(1)) - def assertRegexpMatches(self, text, expected_regexp, msg=None): + def assertRegex(self, text, expected_regexp, msg=None): """Python 2.7 backport.""" if isinstance(expected_regexp, str): expected_regexp = re.compile(expected_regexp) @@ -201,21 +201,21 @@ def test_tmppath_not_configured(self): res9 = hdfs.tmppath(path9, include_unix_username=False) # Then: I should get correct results relative to Luigi temporary directory - self.assertRegexpMatches(res1, "^/tmp/dir1/dir2/file-luigitemp-\\d+") + self.assertRegex(res1, "^/tmp/dir1/dir2/file-luigitemp-\\d+") # it would be better to see hdfs:///path instead of hdfs:/path, but single slash also works well - self.assertRegexpMatches(res2, "^hdfs:/tmp/dir1/dir2/file-luigitemp-\\d+") - self.assertRegexpMatches(res3, "^hdfs://somehost/tmp/dir1/dir2/file-luigitemp-\\d+") - self.assertRegexpMatches(res4, "^file:///tmp/dir1/dir2/file-luigitemp-\\d+") - self.assertRegexpMatches(res5, "^/tmp/dir/file-luigitemp-\\d+") + self.assertRegex(res2, "^hdfs:/tmp/dir1/dir2/file-luigitemp-\\d+") + self.assertRegex(res3, "^hdfs://somehost/tmp/dir1/dir2/file-luigitemp-\\d+") + self.assertRegex(res4, "^file:///tmp/dir1/dir2/file-luigitemp-\\d+") + self.assertRegex(res5, "^/tmp/dir/file-luigitemp-\\d+") # known issue with duplicated "tmp" if schema is present - self.assertRegexpMatches(res6, "^file:///tmp/tmp/dir/file-luigitemp-\\d+") + self.assertRegex(res6, "^file:///tmp/tmp/dir/file-luigitemp-\\d+") # known issue with duplicated "tmp" if schema is present - self.assertRegexpMatches(res7, "^hdfs://somehost/tmp/tmp/dir/file-luigitemp-\\d+") - self.assertRegexpMatches(res8, "^/tmp/luigitemp-\\d+") - self.assertRegexpMatches(res9, "/tmp/tmpdir/file") + self.assertRegex(res7, "^hdfs://somehost/tmp/tmp/dir/file-luigitemp-\\d+") + self.assertRegex(res8, "^/tmp/luigitemp-\\d+") + self.assertRegex(res9, "/tmp/tmpdir/file") def test_tmppath_username(self): - self.assertRegexpMatches(hdfs.tmppath('/path/to/stuff', include_unix_username=True), + self.assertRegex(hdfs.tmppath('/path/to/stuff', include_unix_username=True), "^/tmp/[a-z0-9_]+/path/to/stuff-luigitemp-\\d+") def test_pickle(self): diff --git a/test/contrib/postgres_test.py b/test/contrib/postgres_test.py index f08a330f84..bf9c0b89ac 100644 --- a/test/contrib/postgres_test.py +++ b/test/contrib/postgres_test.py @@ -132,11 +132,11 @@ def test_bulk_complete(self, mock_connect): def test_override_port(self): output = DummyPostgresQueryWithPort(date=datetime.datetime(1991, 3, 24)).output() - self.assertEquals(output.port, 1234) + self.assertEqual(output.port, 1234) def test_port_encoded_in_host(self): output = DummyPostgresQueryWithPortEncodedInHost(date=datetime.datetime(1991, 3, 24)).output() - self.assertEquals(output.port, '1234') + self.assertEqual(output.port, '1234') @pytest.mark.postgres diff --git a/test/contrib/s3_test.py b/test/contrib/s3_test.py index 845806606b..6655667a6c 100644 --- a/test/contrib/s3_test.py +++ b/test/contrib/s3_test.py @@ -342,7 +342,7 @@ def test_get(self): s3_client.get('s3://mybucket/putMe', tmp_file_path) with open(tmp_file_path, 'r') as f: content = f.read() - self.assertEquals(content, self.tempFileContents.decode("utf-8")) + self.assertEqual(content, self.tempFileContents.decode("utf-8")) tmp_file.close() def test_get_as_bytes(self): @@ -352,7 +352,7 @@ def test_get_as_bytes(self): contents = s3_client.get_as_bytes('s3://mybucket/putMe') - self.assertEquals(contents, self.tempFileContents) + self.assertEqual(contents, self.tempFileContents) def test_get_as_string(self): create_bucket() @@ -361,7 +361,7 @@ def test_get_as_string(self): contents = s3_client.get_as_string('s3://mybucket/putMe2') - self.assertEquals(contents, self.tempFileContents.decode('utf-8')) + self.assertEqual(contents, self.tempFileContents.decode('utf-8')) def test_get_as_string_latin1(self): create_bucket() @@ -370,7 +370,7 @@ def test_get_as_string_latin1(self): contents = s3_client.get_as_string('s3://mybucket/putMe3', encoding='ISO-8859-1') - self.assertEquals(contents, self.tempFileContents.decode('ISO-8859-1')) + self.assertEqual(contents, self.tempFileContents.decode('ISO-8859-1')) def test_get_key(self): create_bucket() diff --git a/test/interface_test.py b/test/interface_test.py index 8418683a34..502a408640 100644 --- a/test/interface_test.py +++ b/test/interface_test.py @@ -204,9 +204,9 @@ class CoreConfigTest(LuigiTestCase): @with_config({}) def test_parallel_scheduling_processes_default(self): - self.assertEquals(0, core().parallel_scheduling_processes) + self.assertEqual(0, core().parallel_scheduling_processes) @with_config({'core': {'parallel-scheduling-processes': '1234'}}) def test_parallel_scheduling_processes(self): from luigi.interface import core - self.assertEquals(1234, core().parallel_scheduling_processes) + self.assertEqual(1234, core().parallel_scheduling_processes)