From 7c5020e82d9b653a1d27ca35041c610ac90b3d9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Wed, 29 Aug 2018 09:24:37 +0200 Subject: [PATCH] Reduce duplication in tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set the dummy compose into non-debug mode in a single place, and only change it when needed. Signed-off-by: Lubomír Sedlář --- tests/helpers.py | 2 ++ tests/test_createrepophase.py | 20 -------------------- tests/test_gather_method_deps.py | 1 - tests/test_gather_method_nodeps.py | 1 - tests/test_gather_phase.py | 2 -- tests/test_gather_source_module.py | 1 - tests/test_initphase.py | 8 -------- tests/test_pkgset_source_koji.py | 6 ------ 8 files changed, 2 insertions(+), 39 deletions(-) diff --git a/tests/helpers.py b/tests/helpers.py index e9d479c8..672b6974 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -153,6 +153,8 @@ class DummyCompose(object): self.require_deliverable = mock.Mock() self.should_create_yum_database = True + self.DEBUG = False + def setup_optional(self): self.all_variants['Server-optional'] = MockVariant( uid='Server-optional', arches=['x86_64'], type='optional') diff --git a/tests/test_createrepophase.py b/tests/test_createrepophase.py index e4f982cb..f1ceef4c 100644 --- a/tests/test_createrepophase.py +++ b/tests/test_createrepophase.py @@ -129,7 +129,6 @@ class TestCreateVariantRepo(PungiTestCase): compose = DummyCompose(self.topdir, { 'createrepo_checksum': 'sha256', }) - compose.DEBUG = False compose.has_comps = False repo = CreaterepoWrapperCls.return_value @@ -161,7 +160,6 @@ class TestCreateVariantRepo(PungiTestCase): 'createrepo_checksum': 'sha256', }) compose.should_create_yum_database = False - compose.DEBUG = False compose.has_comps = False repo = CreaterepoWrapperCls.return_value @@ -192,7 +190,6 @@ class TestCreateVariantRepo(PungiTestCase): compose = DummyCompose(self.topdir, { 'createrepo_checksum': 'sha256', }) - compose.DEBUG = False compose.has_comps = False repo = CreaterepoWrapperCls.return_value @@ -225,7 +222,6 @@ class TestCreateVariantRepo(PungiTestCase): compose = DummyCompose(self.topdir, { 'createrepo_checksum': 'sha256', }) - compose.DEBUG = False compose.has_comps = False repo = CreaterepoWrapperCls.return_value @@ -258,7 +254,6 @@ class TestCreateVariantRepo(PungiTestCase): 'createrepo_c': False, 'createrepo_checksum': 'sha256', }) - compose.DEBUG = False compose.has_comps = False repo = CreaterepoWrapperCls.return_value @@ -290,7 +285,6 @@ class TestCreateVariantRepo(PungiTestCase): 'createrepo_checksum': 'sha256', 'createrepo_num_workers': 10, }) - compose.DEBUG = False compose.has_comps = False repo = CreaterepoWrapperCls.return_value @@ -324,7 +318,6 @@ class TestCreateVariantRepo(PungiTestCase): 'createrepo_checksum': 'sha256', 'createrepo_use_xz': True, }) - compose.DEBUG = False compose.has_comps = False repo = CreaterepoWrapperCls.return_value @@ -356,7 +349,6 @@ class TestCreateVariantRepo(PungiTestCase): 'createrepo_checksum': 'sha256', 'createrepo_deltas': True, }) - compose.DEBUG = False compose.has_comps = False compose.old_composes = [self.topdir + '/old'] touch(os.path.join(self.topdir, 'old', 'test-1.0-20151203.0', 'STATUS'), 'FINISHED') @@ -391,7 +383,6 @@ class TestCreateVariantRepo(PungiTestCase): 'createrepo_checksum': 'sha256', 'createrepo_deltas': [('^Server$', {'*': True})], }) - compose.DEBUG = False compose.has_comps = False compose.old_composes = [self.topdir + '/old'] touch(os.path.join(self.topdir, 'old', 'test-1.0-20151203.0', 'STATUS'), 'FINISHED') @@ -426,7 +417,6 @@ class TestCreateVariantRepo(PungiTestCase): 'createrepo_checksum': 'sha256', 'createrepo_deltas': [('^Everything$', {'x86_64': True})], }) - compose.DEBUG = False compose.has_comps = False compose.old_composes = [self.topdir + '/old'] touch(os.path.join(self.topdir, 'old', 'test-1.0-20151203.0', 'STATUS'), 'FINISHED') @@ -461,7 +451,6 @@ class TestCreateVariantRepo(PungiTestCase): 'createrepo_checksum': 'sha256', 'createrepo_deltas': [('^Server$', {'s390x': True})], }) - compose.DEBUG = False compose.has_comps = False compose.old_composes = [self.topdir + '/old'] touch(os.path.join(self.topdir, 'old', 'test-1.0-20151203.0', 'STATUS'), 'FINISHED') @@ -496,7 +485,6 @@ class TestCreateVariantRepo(PungiTestCase): 'createrepo_deltas': True, 'hashed_directories': True, }) - compose.DEBUG = False compose.has_comps = False compose.old_composes = [self.topdir + '/old'] touch(os.path.join(self.topdir, 'old', 'test-1.0-20151203.0', 'STATUS'), 'FINISHED') @@ -539,7 +527,6 @@ class TestCreateVariantRepo(PungiTestCase): 'createrepo_deltas': True, 'hashed_directories': True, }) - compose.DEBUG = False compose.has_comps = False compose.old_composes = [self.topdir + '/old'] touch(os.path.join(self.topdir, 'old', 'test-1.0-20151203.0', 'STATUS'), 'FINISHED') @@ -576,7 +563,6 @@ class TestCreateVariantRepo(PungiTestCase): 'createrepo_checksum': 'sha256', 'createrepo_deltas': True, }) - compose.DEBUG = False compose.has_comps = False compose.old_composes = [self.topdir + '/old'] touch(os.path.join(self.topdir, 'old', 'test-1.0-20151203.0', 'STATUS'), 'FINISHED') @@ -613,7 +599,6 @@ class TestCreateVariantRepo(PungiTestCase): 'createrepo_checksum': 'sha256', 'createrepo_deltas': True, }) - compose.DEBUG = False compose.has_comps = False compose.old_composes = [self.topdir + '/old'] touch(os.path.join(self.topdir, 'old', 'test-1.0-20151203.0', 'STATUS'), 'FINISHED') @@ -647,7 +632,6 @@ class TestCreateVariantRepo(PungiTestCase): 'createrepo_checksum': 'sha256', 'product_id': 'yes', # Truthy value is enough for this test }) - compose.DEBUG = False compose.has_comps = False product_id = compose.paths.work.product_id('x86_64', compose.variants['Server']) repodata_dir = os.path.join( @@ -687,7 +671,6 @@ class TestCreateVariantRepo(PungiTestCase): 'createrepo_checksum': 'sha256', 'product_id': 'yes', # Truthy value is enough for this test }) - compose.DEBUG = False compose.has_comps = False repo = CreaterepoWrapperCls.return_value @@ -719,7 +702,6 @@ class TestCreateVariantRepo(PungiTestCase): 'createrepo_checksum': 'sha256', 'product_id': 'yes', # Truthy value is enough for this test }) - compose.DEBUG = False compose.has_comps = False repo = CreaterepoWrapperCls.return_value @@ -754,7 +736,6 @@ class TestCreateVariantRepo(PungiTestCase): compose = DummyCompose(self.topdir, { 'createrepo_checksum': 'sha256', }) - compose.DEBUG = False compose.has_comps = False variant = compose.variants['Server'] @@ -798,7 +779,6 @@ class TestCreateVariantRepo(PungiTestCase): compose = DummyCompose(self.topdir, { 'createrepo_checksum': 'sha256', }) - compose.DEBUG = False compose.has_comps = False variant = compose.variants['Server'] diff --git a/tests/test_gather_method_deps.py b/tests/test_gather_method_deps.py index 667eaa5e..1d577209 100644 --- a/tests/test_gather_method_deps.py +++ b/tests/test_gather_method_deps.py @@ -14,7 +14,6 @@ class TestWritePungiConfig(helpers.PungiTestCase): def setUp(self): super(TestWritePungiConfig, self).setUp() self.compose = helpers.DummyCompose(self.topdir, {}) - self.compose.DEBUG = False def assertWritten(self, PungiWrapper, **kwargs): wrapper = PungiWrapper.return_value diff --git a/tests/test_gather_method_nodeps.py b/tests/test_gather_method_nodeps.py index 4b9d5f0d..7a9f1709 100644 --- a/tests/test_gather_method_nodeps.py +++ b/tests/test_gather_method_nodeps.py @@ -16,7 +16,6 @@ class TestWritePungiConfig(helpers.PungiTestCase): def setUp(self): super(TestWritePungiConfig, self).setUp() self.compose = helpers.DummyCompose(self.topdir, {}) - self.compose.DEBUG = False self.compose.paths.work.comps = mock.Mock(return_value=COMPS_FILE) def test_expand_group(self): diff --git a/tests/test_gather_phase.py b/tests/test_gather_phase.py index e58a2408..cbcb22e6 100644 --- a/tests/test_gather_phase.py +++ b/tests/test_gather_phase.py @@ -747,7 +747,6 @@ class TestWritePrepopulate(helpers.PungiTestCase): compose = helpers.DummyCompose(self.topdir, { 'gather_prepopulate': 'input-prepopulate.json', }) - compose.DEBUG = False compose.config_dir = self.topdir helpers.copy_fixture('prepopulate.json', os.path.join(self.topdir, 'input-prepopulate.json')) @@ -762,7 +761,6 @@ class TestWritePrepopulate(helpers.PungiTestCase): 'repo': None, } }) - compose.DEBUG = False compose.config_dir = self.topdir helpers.copy_fixture('prepopulate.json', os.path.join(self.topdir, 'input-prepopulate.json')) diff --git a/tests/test_gather_source_module.py b/tests/test_gather_source_module.py index ae2a6bb7..39bc27f8 100644 --- a/tests/test_gather_source_module.py +++ b/tests/test_gather_source_module.py @@ -22,7 +22,6 @@ class TestGatherSourceModule(helpers.PungiTestCase): super(TestGatherSourceModule, self).setUp() self.compose = helpers.DummyCompose(self.topdir, {}) - self.compose.DEBUG = False self.mmd = self.compose.variants["Server"].add_fake_module( "testmodule:master:1:2017", rpm_nvrs=["pkg-0:1.0.0-1.x86_64", "pkg-0:1.0.0-1.i686"]) diff --git a/tests/test_initphase.py b/tests/test_initphase.py index 48059146..8712af3f 100644 --- a/tests/test_initphase.py +++ b/tests/test_initphase.py @@ -171,7 +171,6 @@ class TestWriteArchComps(PungiTestCase): @mock.patch('pungi.phases.init.run') def test_run(self, run): compose = DummyCompose(self.topdir, {}) - compose.DEBUG = False init.write_arch_comps(compose, 'x86_64') @@ -198,7 +197,6 @@ class TestCreateCompsRepo(PungiTestCase): compose = DummyCompose(self.topdir, { 'createrepo_checksum': 'sha256', }) - compose.DEBUG = False init.create_comps_repo(compose, 'x86_64', None) @@ -216,7 +214,6 @@ class TestCreateCompsRepo(PungiTestCase): compose = DummyCompose(self.topdir, { 'createrepo_checksum': 'sha256', }) - compose.DEBUG = False init.create_comps_repo(compose, 'x86_64', compose.variants['Server']) @@ -259,7 +256,6 @@ class TestWriteGlobalComps(PungiTestCase): @mock.patch('pungi.phases.init.get_file_from_scm') def test_run_local_file(self, get_file): compose = DummyCompose(self.topdir, {'comps_file': 'some-file.xml'}) - compose.DEBUG = False def gen_file(src, dest, logger=None): self.assertEqual(src, '/home/releng/config/some-file.xml') @@ -278,7 +274,6 @@ class TestWriteVariantComps(PungiTestCase): @mock.patch('pungi.phases.init.CompsWrapper') def test_run(self, CompsWrapper, run): compose = DummyCompose(self.topdir, {}) - compose.DEBUG = False variant = compose.variants['Server'] comps = CompsWrapper.return_value comps.filter_groups.return_value = [] @@ -302,7 +297,6 @@ class TestWriteVariantComps(PungiTestCase): @mock.patch('pungi.phases.init.CompsWrapper') def test_run_no_filter_without_groups(self, CompsWrapper, run): compose = DummyCompose(self.topdir, {}) - compose.DEBUG = False variant = compose.variants['Server'] variant.groups = [] comps = CompsWrapper.return_value @@ -327,7 +321,6 @@ class TestWriteVariantComps(PungiTestCase): @mock.patch('pungi.phases.init.CompsWrapper') def test_run_filter_for_modular(self, CompsWrapper, run): compose = DummyCompose(self.topdir, {}) - compose.DEBUG = False variant = compose.variants['Server'] variant.groups = [] variant.modules = ['testmodule:2.0'] @@ -353,7 +346,6 @@ class TestWriteVariantComps(PungiTestCase): @mock.patch('pungi.phases.init.CompsWrapper') def test_run_report_unmatched(self, CompsWrapper, run): compose = DummyCompose(self.topdir, {}) - compose.DEBUG = False variant = compose.variants['Server'] comps = CompsWrapper.return_value comps.filter_groups.return_value = ['foo', 'bar'] diff --git a/tests/test_pkgset_source_koji.py b/tests/test_pkgset_source_koji.py index a24d2e27..470a6e94 100644 --- a/tests/test_pkgset_source_koji.py +++ b/tests/test_pkgset_source_koji.py @@ -44,7 +44,6 @@ class TestGetKojiEvent(helpers.PungiTestCase): def test_use_preconfigured_event(self): koji_wrapper = mock.Mock() self.compose.koji_event = 123456 - self.compose.DEBUG = False koji_wrapper.koji_proxy.getEvent.return_value = EVENT_INFO @@ -58,7 +57,6 @@ class TestGetKojiEvent(helpers.PungiTestCase): self.assertEqual(json.load(f), EVENT_INFO) def test_gets_last_event(self): - self.compose.DEBUG = False self.compose.koji_event = None koji_wrapper = mock.Mock() @@ -94,7 +92,6 @@ class TestPopulateGlobalPkgset(helpers.PungiTestCase): 'pkgset_koji_tag': 'f25', 'sigkeys': mock.Mock(), }) - self.compose.DEBUG = False self.koji_wrapper = mock.Mock() self.pkgset_path = os.path.join(self.topdir, 'work', 'global', 'pkgset_global.pickle') self.koji_module_path = os.path.join(self.topdir, 'work', 'global', 'koji-module-Server.yaml') @@ -213,7 +210,6 @@ data: 'pkgset_koji_tag': ['f25', 'f25-extra'], 'sigkeys': mock.Mock(), }) - self.compose.DEBUG = False pickle_dumps.return_value = b'DATA' @@ -288,7 +284,6 @@ data: ('.*', {'*': ['pkg', 'foo.x86_64']}), ] }) - self.compose.DEBUG = False pickle_dumps.return_value = b'DATA' pkgset = source_koji.populate_global_pkgset( @@ -303,7 +298,6 @@ class TestGetPackageSetFromKoji(helpers.PungiTestCase): 'pkgset_koji_tag': 'f25', }) self.compose.koji_event = None - self.compose.DEBUG = False self.koji_wrapper = mock.Mock() self.koji_wrapper.koji_proxy.getLastEvent.return_value = EVENT_INFO self.koji_wrapper.koji_proxy.getTag.return_value = TAG_INFO