From 53e3e18f2fd304f5787d12965c33bbea3dccb5af Mon Sep 17 00:00:00 2001 From: Mattijs Korpershoek Date: Wed, 17 Jan 2024 13:43:49 +0100 Subject: [PATCH] common: tests: use assertEqual for python-3.12 compatibility On recent systems with python-3.12, the unit tests fail with a syntax error: ====================================================================== ERROR: test_get_metadata (repo_resource.test_in.TestIn.test_get_metadata) ---------------------------------------------------------------------- Traceback (most recent call last): File "/root/repo_resource/test_in.py", line 85, in test_get_metadata self.assertEquals(result['metadata'][0]['name'], expected_project) ^^^^^^^^^^^^^^^^^ AttributeError: 'TestIn' object has no attribute 'assertEquals'. Did you mean: 'assertEqual'? Fix it by using assertEqual instead of assertEquals. Signed-off-by: Mattijs Korpershoek --- repo_resource/test_check.py | 4 ++-- repo_resource/test_in.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/repo_resource/test_check.py b/repo_resource/test_check.py index 6320e03..039a966 100644 --- a/repo_resource/test_check.py +++ b/repo_resource/test_check.py @@ -251,7 +251,7 @@ def test_ssh_private_key_without_project_access(self): with self.assertRaises(SystemExit): versions = check.check(instream) - self.assertEquals(len(versions), 0) + self.assertEqual(len(versions), 0) def test_ssh_private_key_without_manifest_access(self): data = self.demo_ssh_manifests_source @@ -306,7 +306,7 @@ def test_ssh_private_key_without_manifest_access(self): with self.assertRaises(SystemExit): versions = check.check(instream) - self.assertEquals(len(versions), 0) + self.assertEqual(len(versions), 0) # test that we can specify an amount of jobs # This is a little flaky because it depends on network diff --git a/repo_resource/test_in.py b/repo_resource/test_in.py index 7413dbe..00626c7 100644 --- a/repo_resource/test_in.py +++ b/repo_resource/test_in.py @@ -69,7 +69,7 @@ def test_valid_in(self): instream = StringIO(json.dumps(data)) fetched_version = in_.in_(instream, str(common.CACHEDIR)) - self.assertEquals(fetched_version['version'], data['version']) + self.assertEqual(fetched_version['version'], data['version']) def test_get_metadata(self): data = self.demo_manifests_source @@ -82,8 +82,8 @@ def test_get_metadata(self): expected_project = 'device/generic/common' expected_revision = '033d50e2298811d81de7db8cdea63e349a96c9ba' - self.assertEquals(result['metadata'][0]['name'], expected_project) - self.assertEquals(result['metadata'][0]['value'], expected_revision) + self.assertEqual(result['metadata'][0]['name'], expected_project) + self.assertEqual(result['metadata'][0]['value'], expected_revision) @unittest.skipUnless( Path('development/ssh/test_key').exists(), "requires ssh test key") @@ -115,4 +115,4 @@ def test_manifest_is_saved(self): common.CACHEDIR / '.repo_manifest.xml') expected_manifest_version = common.Version(data['version']['version']) - self.assertEquals(saved_manifest_version, expected_manifest_version) + self.assertEqual(saved_manifest_version, expected_manifest_version)