From 908a6a759d9e19c75de0ddf172bef03c82c748af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Fri, 4 Oct 2019 15:10:14 +0200 Subject: [PATCH] Use custom assertion for checking content of files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lubomír Sedlář --- tests/test_buildinstall.py | 14 ++++---- tests/test_createrepophase.py | 60 ++++++++++++++--------------------- 2 files changed, 30 insertions(+), 44 deletions(-) diff --git a/tests/test_buildinstall.py b/tests/test_buildinstall.py index 0327d0fa..c064c927 100644 --- a/tests/test_buildinstall.py +++ b/tests/test_buildinstall.py @@ -1018,10 +1018,9 @@ class TestTweakConfigs(PungiTestCase): touch(configs[-1], ':LABEL=baz') tweak_configs(self.topdir, 'new volid', os.path.join(self.topdir, 'ks.cfg')) for cfg in configs: - with open(cfg) as f: - self.assertEqual( - f.read().strip(), - ':LABEL=new\\x20volid ks=hd:LABEL=new\\x20volid:/ks.cfg') + self.assertFileContent( + cfg, ":LABEL=new\\x20volid ks=hd:LABEL=new\\x20volid:/ks.cfg\n" + ) def test_tweak_configs_yaboot(self): configs = [] @@ -1031,7 +1030,6 @@ class TestTweakConfigs(PungiTestCase): touch(configs[-1], ':LABEL=baz') tweak_configs(self.topdir, 'new volid', os.path.join(self.topdir, 'ks.cfg')) for cfg in configs: - with open(os.path.join(self.topdir, cfg)) as f: - self.assertEqual( - f.read().strip(), - ':LABEL=new\\\\x20volid ks=hd:LABEL=new\\\\x20volid:/ks.cfg') + self.assertFileContent( + cfg, ":LABEL=new\\\\x20volid ks=hd:LABEL=new\\\\x20volid:/ks.cfg\n" + ) diff --git a/tests/test_createrepophase.py b/tests/test_createrepophase.py index fbe00d4b..021bae90 100644 --- a/tests/test_createrepophase.py +++ b/tests/test_createrepophase.py @@ -185,8 +185,7 @@ class TestCreateVariantRepo(PungiTestCase): update_md_path="/repo/x86_64", deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), 'Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n') + self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -216,8 +215,7 @@ class TestCreateVariantRepo(PungiTestCase): update_md_path="/repo/x86_64", deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), 'Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n') + self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -246,8 +244,7 @@ class TestCreateVariantRepo(PungiTestCase): update_md_path="/repo/global", deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), "Packages/b/bash-4.3.30-2.fc21.src.rpm\n") + self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.src.rpm\n") @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -277,8 +274,9 @@ class TestCreateVariantRepo(PungiTestCase): update_md_path="/repo/x86_64", deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), 'Packages/b/bash-debuginfo-4.3.30-2.fc21.x86_64.rpm\n') + self.assertFileContent( + list_file, 'Packages/b/bash-debuginfo-4.3.30-2.fc21.x86_64.rpm\n' + ) @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -308,8 +306,7 @@ class TestCreateVariantRepo(PungiTestCase): update_md_path="/repo/x86_64", deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), 'Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n') + self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -343,8 +340,7 @@ class TestCreateVariantRepo(PungiTestCase): update_md_path="/repo/x86_64", deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), 'Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n') + self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -374,8 +370,7 @@ class TestCreateVariantRepo(PungiTestCase): update_md_path="/repo/x86_64", deltas=False, oldpackagedirs=None, use_xz=True, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), 'Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n') + self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -408,8 +403,7 @@ class TestCreateVariantRepo(PungiTestCase): oldpackagedirs=self.topdir + '/old/test-1.0-20151203.0/compose/Server/x86_64/os/Packages', use_xz=False, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), 'Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n') + self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -442,8 +436,7 @@ class TestCreateVariantRepo(PungiTestCase): oldpackagedirs=self.topdir + '/old/test-1.0-20151203.0/compose/Server/x86_64/os/Packages', use_xz=False, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), 'Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n') + self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -475,8 +468,7 @@ class TestCreateVariantRepo(PungiTestCase): update_md_path="/repo/x86_64", deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), 'Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n') + self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -509,8 +501,7 @@ class TestCreateVariantRepo(PungiTestCase): update_md_path="/repo/x86_64", deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), 'Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n') + self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -551,8 +542,7 @@ class TestCreateVariantRepo(PungiTestCase): ], use_xz=False, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), 'Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n') + self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -587,8 +577,7 @@ class TestCreateVariantRepo(PungiTestCase): oldpackagedirs=[], use_xz=False, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), 'Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n') + self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -621,8 +610,7 @@ class TestCreateVariantRepo(PungiTestCase): update_md_path="/repo/global", deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), "Packages/b/bash-4.3.30-2.fc21.src.rpm\n") + self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.src.rpm\n") @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -655,8 +643,9 @@ class TestCreateVariantRepo(PungiTestCase): update_md_path="/repo/x86_64", deltas=False, oldpackagedirs=None, use_xz=False, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), 'Packages/b/bash-debuginfo-4.3.30-2.fc21.x86_64.rpm\n') + self.assertFileContent( + list_file, "Packages/b/bash-debuginfo-4.3.30-2.fc21.x86_64.rpm\n" + ) @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -697,8 +686,7 @@ class TestCreateVariantRepo(PungiTestCase): repo.get_modifyrepo_cmd.mock_calls, [mock.call(repodata_dir, product_id, compress_type="gz")] ) - with open(list_file) as f: - self.assertEqual(f.read(), 'Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n') + self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.x86_64.rpm\n") @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -730,8 +718,9 @@ class TestCreateVariantRepo(PungiTestCase): oldpackagedirs=None, use_xz=False, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), 'Packages/b/bash-debuginfo-4.3.30-2.fc21.x86_64.rpm\n') + self.assertFileContent( + list_file, "Packages/b/bash-debuginfo-4.3.30-2.fc21.x86_64.rpm\n" + ) @mock.patch('pungi.phases.createrepo.run') @mock.patch('pungi.phases.createrepo.CreaterepoWrapper') @@ -763,8 +752,7 @@ class TestCreateVariantRepo(PungiTestCase): oldpackagedirs=None, use_xz=False, extra_args=[])]) self.assertEqual(repo.get_modifyrepo_cmd.mock_calls, []) - with open(list_file) as f: - self.assertEqual(f.read(), 'Packages/b/bash-4.3.30-2.fc21.src.rpm\n') + self.assertFileContent(list_file, "Packages/b/bash-4.3.30-2.fc21.src.rpm\n") @unittest.skipUnless(Modulemd is not None, 'Skipped test, no module support.') @mock.patch('pungi.phases.createrepo.find_file_in_repodata')