From 7ea0af73ae05839a506b72bfdea1a75d99758d50 Mon Sep 17 00:00:00 2001 From: Otto Urpelainen Date: Feb 12 2021 06:54:08 +0000 Subject: Improve automatic test suite 1. In layout tests, remove duplicate assertions. No harmful, but unnecessary. 2. In test_commands, when asserting rpmdefines, check that there are no other defines than expected. 3. In test_cli, TestImportSrpm was failing because stdout had more than one row like the test case expected. Improved assert to compare only the last item of the last line of output, which should have the expected content. Depending on rpm version, there can be multipe lines of output, notably one like `setting SOURCE_DATE_EPOCH=1136073600`, and depending on locale settings, the last row can have more than two components when split by whitespace, because the line starts with localized string "Wrote:", which may be translated to multiple works (arguably, a better fix would be to avoid using the current locale when running the tests - but since the same line of code needs changes anyhow, it makes sense to apply this simple fix now) Also, fix a typo in a method description. Signed-off-by: Otto Urpelainen --- diff --git a/pyrpkg/layout/base.py b/pyrpkg/layout/base.py index 8673b60..48a80d6 100644 --- a/pyrpkg/layout/base.py +++ b/pyrpkg/layout/base.py @@ -71,7 +71,7 @@ class BaseLayout(ABC): """ Class constructor based on a package path. - This method's implementation is madatory and + This method's implementation is mandatory and should return an instance of the object class. It should raise an exception if it can't read the path diff --git a/tests/test_cli.py b/tests/test_cli.py index cdbc241..6fde6dd 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1405,7 +1405,7 @@ class TestImportSrpm(LookasideCacheMock, CliTestCase): if proc.returncode > 0: raise rpkgError('Failed to build SRPM for test case {0}'.format( TestImportSrpm.__name__)) - _, filename = stdout.split() + filename = stdout.splitlines()[-1].split()[-1] return filename.strip() def setUp(self): diff --git a/tests/test_commands.py b/tests/test_commands.py index 4363aae..c0ac6b3 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -229,6 +229,7 @@ class LoadRPMDefinesTest(CommandTestCase): define.replace("'", '').split(' ', 1)[1] for define in self.cmd._rpmdefines)]) + self.assertEqual(len(expected_defines), len(defines)) for var, val in expected_defines.items(): self.assertTrue(var in defines) self.assertEqual(val, defines[var]) diff --git a/tests/test_layout_distgit.py b/tests/test_layout_distgit.py index 1aaa972..cc70014 100644 --- a/tests/test_layout_distgit.py +++ b/tests/test_layout_distgit.py @@ -15,7 +15,6 @@ class DistGitLayoutTestCase(unittest.TestCase): def test_layout_data(self): self.assertEqual(self.layout.sourcedir, self.workdir) self.assertEqual(self.layout.specdir, self.workdir) - self.assertEqual(self.layout.specdir, self.workdir) self.assertEqual(self.layout.root_dir, self.workdir) self.assertEqual(self.layout.builddir, self.workdir) self.assertEqual(self.layout.rpmdir, self.workdir) diff --git a/tests/test_layout_incomplete.py b/tests/test_layout_incomplete.py index 77130e0..0cef423 100644 --- a/tests/test_layout_incomplete.py +++ b/tests/test_layout_incomplete.py @@ -15,7 +15,6 @@ class IncompleteLayoutTestCase(unittest.TestCase): def test_layout_data(self): self.assertEqual(self.layout.sourcedir, None) self.assertEqual(self.layout.specdir, None) - self.assertEqual(self.layout.specdir, None) self.assertEqual(self.layout.root_dir, self.workdir) self.assertEqual(self.layout.builddir, None) self.assertEqual(self.layout.rpmdir, None) diff --git a/tests/test_layout_retired.py b/tests/test_layout_retired.py index bd40555..4e854ea 100644 --- a/tests/test_layout_retired.py +++ b/tests/test_layout_retired.py @@ -15,7 +15,6 @@ class RetiredLayoutTestCase(unittest.TestCase): def test_layout_data(self): self.assertEqual(self.layout.sourcedir, None) self.assertEqual(self.layout.specdir, None) - self.assertEqual(self.layout.specdir, None) self.assertEqual(self.layout.root_dir, self.workdir) self.assertEqual(self.layout.builddir, None) self.assertEqual(self.layout.rpmdir, None)