Skip to content

Commit

Permalink
[tests] Drop obsolete TestCase.assertEquals()
Browse files Browse the repository at this point in the history
`unittest.TestCase.assertEquals()` was deprecated in Python 3 [1], and
finally dropped in Python 3.12. This now causes the unit tests to fail [2].

[1] https://docs.python.org/3.5/library/unittest.html#deprecated-aliases
[2] https://bugs.debian.org/1058214

Signed-off-by: Martin Pitt <[email protected]>
  • Loading branch information
Martin Pitt authored and TurboTurtle committed Jan 11, 2024
1 parent 68aef93 commit 769768a
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 78 deletions.
10 changes: 5 additions & 5 deletions tests/report_tests/timeout/timeout_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PluginTimeoutTest(StageTwoReportTest):

def test_correct_plugin_timeout(self):
man = self.get_plugin_manifest('timeout_test')
self.assertEquals(man['timeout'], 10)
self.assertEqual(man['timeout'], 10)

def test_plugin_timed_out(self):
self.assertSosLogNotContains('collected plugin \'timeout_test\' in')
Expand All @@ -41,9 +41,9 @@ class NativeCmdTimeoutTest(StageTwoReportTest):

def test_correct_plugin_timeout(self):
man = self.get_plugin_manifest('timeout_test')
self.assertEquals(man['timeout'], 100)
self.assertEqual(man['timeout'], 100)
hman = self.get_plugin_manifest('host')
self.assertEquals(hman['timeout'], 300)
self.assertEqual(hman['timeout'], 300)

def test_plugin_completed(self):
self.assertSosLogContains('collected plugin \'timeout_test\' in')
Expand All @@ -64,6 +64,6 @@ class MultipleTimeoutValues(NativeCmdTimeoutTest):

def test_correct_plugin_timeout(self):
man = self.get_plugin_manifest('timeout_test')
self.assertEquals(man['timeout'], 60)
self.assertEqual(man['timeout'], 60)
hman = self.get_plugin_manifest('host')
self.assertEquals(hman['timeout'], 30)
self.assertEqual(hman['timeout'], 30)
4 changes: 2 additions & 2 deletions tests/unittests/archive_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_get_file(self):
self.tf.add_string('this is my content', 'tests/string_test.txt')

afp = self.tf.open_file('tests/string_test.txt')
self.assertEquals('this is my content', afp.read())
self.assertEqual('this is my content', afp.read())

def test_rewrite_file(self):
"""Test that re-writing a file with add_string() modifies the content.
Expand All @@ -101,7 +101,7 @@ def test_rewrite_file(self):
self.tf.add_string('this is my new content', 'tests/string_test.txt')

afp = self.tf.open_file('tests/string_test.txt')
self.assertEquals('this is my new content', afp.read())
self.assertEqual('this is my new content', afp.read())

def test_make_link(self):
self.tf.add_file('tests/ziptest')
Expand Down
6 changes: 3 additions & 3 deletions tests/unittests/cleaner_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ def test_mac_map_obfuscate_valid_v6_quad(self):

def test_mac_map_skip_ignores(self):
_test = self.mac_map.get('ff:ff:ff:ff:ff:ff')
self.assertEquals(_test, 'ff:ff:ff:ff:ff:ff')
self.assertEqual(_test, 'ff:ff:ff:ff:ff:ff')

def test_mac_map_avoid_duplicate_obfuscation(self):
_test = self.mac_map.get('ab:cd:ef:fe:dc:ba')
_dup = self.mac_map.get(_test)
self.assertEquals(_test, _dup)
self.assertEqual(_test, _dup)

def test_ip_map_obfuscate_v4_with_cidr(self):
_test = self.ip_map.get('192.168.1.0/24')
Expand All @@ -77,7 +77,7 @@ def test_ip_map_get_same_with_or_without_cidr(self):

def test_ip_skip_ignores(self):
_test = self.ip_map.get('127.0.0.1')
self.assertEquals(_test, '127.0.0.1')
self.assertEqual(_test, '127.0.0.1')

def test_hostname_obfuscate_domain_options(self):
_test = self.host_map.get('www.redhat.com')
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/option_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ def setUp(self):
self.plugin = MockPlugin(self.commons)

def test_simple_lookup(self):
self.assertEquals(self.plugin.get_option('test_option'), 'foobar')
self.assertEqual(self.plugin.get_option('test_option'), 'foobar')

def test_cascade(self):
self.assertEquals(self.plugin.get_option(('baz')), False)
self.assertEqual(self.plugin.get_option(('baz')), False)


if __name__ == "__main__":
Expand Down
70 changes: 35 additions & 35 deletions tests/unittests/plugin_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,36 +133,36 @@ def test_regex_findall(self):
['this is only a test', 'there are only two lines'])
test_fo = StringIO(test_s)
matches = regex_findall(r".*lines$", test_fo)
self.assertEquals(matches, ['there are only two lines'])
self.assertEqual(matches, ['there are only two lines'])

def test_regex_findall_miss(self):
test_s = u"\n".join(
['this is only a test', 'there are only two lines'])
test_fo = StringIO(test_s)
matches = regex_findall(r".*not_there$", test_fo)
self.assertEquals(matches, [])
self.assertEqual(matches, [])

def test_regex_findall_bad_input(self):
matches = regex_findall(r".*", None)
self.assertEquals(matches, [])
self.assertEqual(matches, [])
matches = regex_findall(r".*", [])
self.assertEquals(matches, [])
self.assertEqual(matches, [])
matches = regex_findall(r".*", 1)
self.assertEquals(matches, [])
self.assertEqual(matches, [])

def test_mangle_command(self):
name_max = 255
self.assertEquals("foo", _mangle_command("/usr/bin/foo", name_max))
self.assertEquals(
self.assertEqual("foo", _mangle_command("/usr/bin/foo", name_max))
self.assertEqual(
"foo_-x", _mangle_command("/usr/bin/foo -x", name_max))
self.assertEquals(
self.assertEqual(
"foo_--verbose", _mangle_command("/usr/bin/foo --verbose",
name_max))
self.assertEquals("foo_.path.to.stuff", _mangle_command(
self.assertEqual("foo_.path.to.stuff", _mangle_command(
"/usr/bin/foo /path/to/stuff", name_max))
longcmd = "foo is " + "a" * 256 + " long_command"
expected = longcmd[0:name_max].replace(' ', '_')
self.assertEquals(expected, _mangle_command(longcmd, name_max))
self.assertEqual(expected, _mangle_command(longcmd, name_max))


class PluginTests(unittest.TestCase):
Expand All @@ -185,7 +185,7 @@ def test_plugin_default_name(self):
'cmdlineopts': MockOptions(),
'devices': {}
})
self.assertEquals(p.name(), "mockplugin")
self.assertEqual(p.name(), "mockplugin")

def test_plugin_set_name(self):
p = NamedMockPlugin({
Expand All @@ -194,7 +194,7 @@ def test_plugin_set_name(self):
'cmdlineopts': MockOptions(),
'devices': {}
})
self.assertEquals(p.name(), "testing")
self.assertEqual(p.name(), "testing")

def test_plugin_no_descrip(self):
p = MockPlugin({
Expand All @@ -203,7 +203,7 @@ def test_plugin_no_descrip(self):
'cmdlineopts': MockOptions(),
'devices': {}
})
self.assertEquals(p.get_description(), "<no description available>")
self.assertEqual(p.get_description(), "<no description available>")

def test_plugin_has_descrip(self):
p = NamedMockPlugin({
Expand All @@ -212,7 +212,7 @@ def test_plugin_has_descrip(self):
'cmdlineopts': MockOptions(),
'devices': {}
})
self.assertEquals(p.get_description(),
self.assertEqual(p.get_description(),
"This plugin has a description.")

def test_set_plugin_option(self):
Expand All @@ -223,7 +223,7 @@ def test_set_plugin_option(self):
'devices': {}
})
p.set_option("opt", "testing")
self.assertEquals(p.get_option("opt"), "testing")
self.assertEqual(p.get_option("opt"), "testing")

def test_set_nonexistant_plugin_option(self):
p = MockPlugin({
Expand All @@ -241,7 +241,7 @@ def test_get_nonexistant_plugin_option(self):
'cmdlineopts': MockOptions(),
'devices': {}
})
self.assertEquals(p.get_option("badopt"), 0)
self.assertEqual(p.get_option("badopt"), 0)

def test_get_unset_plugin_option(self):
p = MockPlugin({
Expand All @@ -250,7 +250,7 @@ def test_get_unset_plugin_option(self):
'cmdlineopts': MockOptions(),
'devices': {}
})
self.assertEquals(p.get_option("opt"), None)
self.assertEqual(p.get_option("opt"), None)

def test_get_unset_plugin_option_with_default(self):
# this shows that even when we pass in a default to get,
Expand All @@ -262,7 +262,7 @@ def test_get_unset_plugin_option_with_default(self):
'cmdlineopts': MockOptions(),
'devices': {}
})
self.assertEquals(p.get_option("opt", True), True)
self.assertEqual(p.get_option("opt", True), True)

def test_get_unset_plugin_option_with_default_not_none(self):
# this shows that even when we pass in a default to get,
Expand All @@ -275,17 +275,17 @@ def test_get_unset_plugin_option_with_default_not_none(self):
'cmdlineopts': MockOptions(),
'devices': {}
})
self.assertEquals(p.get_option("opt2", True), False)
self.assertEqual(p.get_option("opt2", True), False)

def test_copy_dir(self):
self.mp._do_copy_path("tests")
self.assertEquals(
self.assertEqual(
self.mp.archive.m["tests/unittests/plugin_tests.py"],
'tests/unittests/plugin_tests.py')

def test_copy_dir_bad_path(self):
self.mp._do_copy_path("not_here_tests")
self.assertEquals(self.mp.archive.m, {})
self.assertEqual(self.mp.archive.m, {})

def test_copy_dir_forbidden_path(self):
p = ForbiddenMockPlugin({
Expand All @@ -297,7 +297,7 @@ def test_copy_dir_forbidden_path(self):
p.archive = MockArchive()
p.setup()
p.collect_plugin()
self.assertEquals(p.archive.m, {})
self.assertEqual(p.archive.m, {})

def test_postproc_default_on(self):
p = PostprocMockPlugin({
Expand All @@ -318,11 +318,11 @@ def test_set_default_cmd_env(self):
})
e = {'TORVALDS': 'Linus'}
p.set_default_cmd_environment(e)
self.assertEquals(p.default_environment, e)
self.assertEqual(p.default_environment, e)
add_e = {'GREATESTSPORT': 'hockey'}
p.add_default_cmd_environment(add_e)
self.assertEquals(p.default_environment['GREATESTSPORT'], 'hockey')
self.assertEquals(p.default_environment['TORVALDS'], 'Linus')
self.assertEqual(p.default_environment['GREATESTSPORT'], 'hockey')
self.assertEqual(p.default_environment['TORVALDS'], 'Linus')


class AddCopySpecTests(unittest.TestCase):
Expand All @@ -344,7 +344,7 @@ def pathmunge(path):
path = path[1:]
return os.path.join(self.mp.sysroot, path)
expected_paths = set(map(pathmunge, self.expect_paths))
self.assertEquals(self.mp.copy_paths, expected_paths)
self.assertEqual(self.mp.copy_paths, expected_paths)

def test_single_file_no_limit(self):
self.mp.add_copy_spec("tests/unittests/tail_test.txt")
Expand All @@ -361,7 +361,7 @@ def test_single_file_over_limit(self):
fname, _size = self.mp._tail_files_list[0]
self.assertTrue(fname == fn)
self.assertTrue("tmp" in fname)
self.assertEquals(1024 * 1024, _size)
self.assertEqual(1024 * 1024, _size)
os.unlink(fn)

def test_bad_filename(self):
Expand All @@ -379,7 +379,7 @@ def test_glob_file_limit_no_limit(self):
create_file(2, dir=tmpdir)
create_file(2, dir=tmpdir)
self.mp.add_copy_spec(tmpdir + "/*")
self.assertEquals(len(self.mp.copy_paths), 2)
self.assertEqual(len(self.mp.copy_paths), 2)
shutil.rmtree(tmpdir)

def test_glob_file_over_limit(self):
Expand All @@ -388,18 +388,18 @@ def test_glob_file_over_limit(self):
create_file(2, dir=tmpdir)
create_file(2, dir=tmpdir)
self.mp.add_copy_spec(tmpdir + "/*", 1)
self.assertEquals(len(self.mp._tail_files_list), 1)
self.assertEqual(len(self.mp._tail_files_list), 1)
fname, _size = self.mp._tail_files_list[0]
self.assertEquals(1024 * 1024, _size)
self.assertEqual(1024 * 1024, _size)
shutil.rmtree(tmpdir)

def test_multiple_files_no_limit(self):
self.mp.add_copy_spec(['tests/unittests/tail_test.txt', 'tests/unittests/test.txt'])
self.assertEquals(len(self.mp.copy_paths), 2)
self.assertEqual(len(self.mp.copy_paths), 2)

def test_multiple_files_under_limit(self):
self.mp.add_copy_spec(['tests/unittests/tail_test.txt', 'tests/unittests/test.txt'], 1)
self.assertEquals(len(self.mp.copy_paths), 2)
self.assertEqual(len(self.mp.copy_paths), 2)


class CheckEnabledTests(unittest.TestCase):
Expand Down Expand Up @@ -443,7 +443,7 @@ def setUp(self):
self.mp.archive = MockArchive()

def test_file_never_copied(self):
self.assertEquals(0, self.mp.do_file_sub(
self.assertEqual(0, self.mp.do_file_sub(
"never_copied", r"^(.*)$", "foobar"))

def test_no_replacements(self):
Expand All @@ -452,7 +452,7 @@ def test_no_replacements(self):
self.mp.collect_plugin()
replacements = self.mp.do_file_sub(
j("tail_test.txt"), r"wont_match", "foobar")
self.assertEquals(0, replacements)
self.assertEqual(0, replacements)

def test_replacements(self):
# test uses absolute paths
Expand All @@ -461,7 +461,7 @@ def test_replacements(self):
self.mp.collect_plugin()
replacements = self.mp.do_file_sub(
j("tail_test.txt"), r"(tail)", "foobar")
self.assertEquals(1, replacements)
self.assertEqual(1, replacements)
self.assertTrue("foobar" in self.mp.archive.m.get(j('tail_test.txt')))


Expand Down
16 changes: 8 additions & 8 deletions tests/unittests/policy_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ def setUp(self):
self.pm = PackageManager()

def test_default_all_pkgs(self):
self.assertEquals(self.pm.packages, {})
self.assertEqual(self.pm.packages, {})

def test_default_all_pkgs_by_name(self):
self.assertEquals(self.pm.all_pkgs_by_name('doesntmatter'), [])
self.assertEqual(self.pm.all_pkgs_by_name('doesntmatter'), [])

def test_default_all_pkgs_by_name_regex(self):
self.assertEquals(
self.assertEqual(
self.pm.all_pkgs_by_name_regex('.*doesntmatter$'), [])

def test_default_pkg_by_name(self):
self.assertEquals(self.pm.pkg_by_name('foo'), None)
self.assertEqual(self.pm.pkg_by_name('foo'), None)


class RpmPackageManagerTests(unittest.TestCase):
Expand All @@ -115,7 +115,7 @@ def test_pkg_is_formatted(self):
kpkg = self.pm.pkg_by_name('coreutils')
self.assertIsInstance(kpkg, dict)
self.assertIsInstance(kpkg['version'], list)
self.assertEquals(kpkg['pkg_manager'], 'rpm')
self.assertEqual(kpkg['pkg_manager'], 'rpm')


class DpkgPackageManagerTests(unittest.TestCase):
Expand All @@ -132,7 +132,7 @@ def test_pkg_is_formatted(self):
kpkg = self.pm.pkg_by_name('coreutils')
self.assertIsInstance(kpkg, dict)
self.assertIsInstance(kpkg['version'], list)
self.assertEquals(kpkg['pkg_manager'], 'dpkg')
self.assertEqual(kpkg['pkg_manager'], 'dpkg')


class MultiPackageManagerTests(unittest.TestCase):
Expand All @@ -150,9 +150,9 @@ def test_pkg_is_formatted(self):
self.assertIsInstance(kpkg['version'], list)
_local = distro.detect().name
if _local in ['Ubuntu', 'debian']:
self.assertEquals(kpkg['pkg_manager'], 'dpkg')
self.assertEqual(kpkg['pkg_manager'], 'dpkg')
else:
self.assertEquals(kpkg['pkg_manager'], 'rpm')
self.assertEqual(kpkg['pkg_manager'], 'rpm')


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 769768a

Please sign in to comment.