Skip to content

Commit

Permalink
Refactor deprecated unittest aliases for Python 3.11 compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
tirkarthi committed Oct 14, 2021
1 parent ad5ddc9 commit 88ffa9a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion test/cmdline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
8 changes: 4 additions & 4 deletions test/contrib/external_daily_snapshot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 11 additions & 11 deletions test/contrib/hdfs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions test/contrib/postgres_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/contrib/s3_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions test/interface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 88ffa9a

Please sign in to comment.