From 74001d5aa5a49f8d5eac37c491e7901adb83be65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 12 May 2016 13:50:34 +0200 Subject: [PATCH] [extra-files] Skip whole phase if not configured MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This checks the configuration in one place rather than doing it for each variant/arch combination. Signed-off-by: Lubomír Sedlář --- pungi/phases/extra_files.py | 11 ++++------- tests/test_extra_files_phase.py | 20 ++++++++------------ 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/pungi/phases/extra_files.py b/pungi/phases/extra_files.py index cac6af66..0be75511 100644 --- a/pungi/phases/extra_files.py +++ b/pungi/phases/extra_files.py @@ -22,10 +22,10 @@ import fnmatch from pungi.util import get_arch_variant_data, pkg_is_rpm, copy_all from pungi.arch import split_name_arch from pungi.wrappers.scm import get_file_from_scm, get_dir_from_scm -from pungi.phases.base import PhaseBase +from pungi.phases.base import ConfigGuardedPhase -class ExtraFilesPhase(PhaseBase): +class ExtraFilesPhase(ConfigGuardedPhase): """EXTRA_FILES""" name = "extra_files" @@ -38,8 +38,8 @@ class ExtraFilesPhase(PhaseBase): ) def __init__(self, compose, pkgset_phase): - PhaseBase.__init__(self, compose) - # pkgset_phase provides package_sets and path_prefix + super(ExtraFilesPhase, self).__init__(compose) + # pkgset_phase provides package_sets self.pkgset_phase = pkgset_phase def run(self): @@ -49,9 +49,6 @@ class ExtraFilesPhase(PhaseBase): def copy_extra_files(compose, arch, variant, package_sets): - if "extra_files" not in compose.conf: - return - var_dict = { "arch": arch, "variant_id": variant.id, diff --git a/tests/test_extra_files_phase.py b/tests/test_extra_files_phase.py index ed7e29bd..f8652f50 100755 --- a/tests/test_extra_files_phase.py +++ b/tests/test_extra_files_phase.py @@ -14,6 +14,14 @@ from tests import helpers class TestExtraFilePhase(helpers.PungiTestCase): + @mock.patch('pungi.phases.extra_files.copy_extra_files') + def test_skips_unless_has_config(self, copy_extra_files): + compose = helpers.DummyCompose(self.topdir, {}) + compose.just_phases = None + compose.skip_phases = [] + phase = extra_files.ExtraFilesPhase(compose, mock.Mock()) + self.assertTrue(phase.skip()) + @mock.patch('pungi.phases.extra_files.copy_extra_files') def test_runs_copy_files_for_each_variant(self, copy_extra_files): cfg = mock.Mock() @@ -39,18 +47,6 @@ class TestExtraFilePhase(helpers.PungiTestCase): class TestCopyFiles(helpers.PungiTestCase): - @mock.patch('pungi.phases.extra_files.copy_all') - @mock.patch('pungi.phases.extra_files.get_file_from_scm') - @mock.patch('pungi.phases.extra_files.get_dir_from_scm') - def test_run_without_config(self, get_dir_from_scm, get_file_from_scm, copy_all): - compose = helpers.DummyCompose(self.topdir, {}) - - extra_files.copy_extra_files(compose, 'x86_64', compose.variants['Server'], mock.Mock()) - - self.assertEqual(copy_all.call_args_list, []) - self.assertEqual(get_file_from_scm.call_args_list, []) - self.assertEqual(get_dir_from_scm.call_args_list, []) - def test_copy_local_file(self): tgt = os.path.join(self.topdir, 'file') helpers.touch(tgt)