From 320fcbc97360155e7721013787630f6e822ba500 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 20 Jul 2020 08:26:06 +0200 Subject: [PATCH] Stabilize test that was depending on RELEASED VERSION of self --- src/rkd/standardlib/__init__.py | 8 ++++++-- test/test_standardlib_createstructure.py | 12 ++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/rkd/standardlib/__init__.py b/src/rkd/standardlib/__init__.py index 75561271..2bdc2d49 100644 --- a/src/rkd/standardlib/__init__.py +++ b/src/rkd/standardlib/__init__.py @@ -359,7 +359,6 @@ def execute(self, ctx: ExecutionContext) -> bool: 'please commit them or stash first') return False - rkd_version = pkg_resources.get_distribution("rkd").version template_structure_path = os.path.dirname(os.path.realpath(__file__)) + '/../misc/initial-structure' self.on_startup(ctx) @@ -388,7 +387,7 @@ def execute(self, ctx: ExecutionContext) -> bool: self.rkd([':file:line-in-file', 'requirements.txt', '--regexp="rkd(.*)"', - '--insert="rkd==%s"' % rkd_version + '--insert="rkd%s"' % self.get_rkd_version_selector() ]) self.on_requirements_txt_write(ctx) @@ -413,6 +412,11 @@ def execute(self, ctx: ExecutionContext) -> bool: return True + @staticmethod + def get_rkd_version_selector(): + rkd_version = pkg_resources.get_distribution("rkd").version + return '==%s' % rkd_version + def on_requirements_txt_write(self, ctx: ExecutionContext) -> None: """After requirements.txt file is written diff --git a/test/test_standardlib_createstructure.py b/test/test_standardlib_createstructure.py index ac90038a..7283e522 100644 --- a/test/test_standardlib_createstructure.py +++ b/test/test_standardlib_createstructure.py @@ -30,10 +30,13 @@ def test_functional_creates_structure_in_temporary_directory(self): try: os.chdir(tempdir) + task = CreateStructureTask() + task.get_rkd_version_selector = lambda: '' + self._execute_mocked_task({ '--commit': False, '--no-venv': False - }, {}) + }, {}, task=task) self.assertTrue(os.path.isdir(tempdir + '/.rkd'), msg='Expected that .rkd directory would be created') @@ -63,10 +66,12 @@ def test_functional_detects_git_is_dirty(self): # make the working tree dirty by editing a file without a commit subprocess.call('echo "changed" > test-file.txt', shell=True) + task = CreateStructureTask() + task.get_rkd_version_selector = lambda: '' io = self._execute_mocked_task({ '--commit': True, '--no-venv': False - }, {}) + }, {}, task=task) self.assertIn('Current working directory is dirty', io.get_value()) finally: @@ -107,6 +112,9 @@ def test_functional_interface_methods_are_called(self): # mock task = CreateStructureTask() + # do not set fixed version, as on local environment it could be some dev version not released yet + task.get_rkd_version_selector = lambda: '' + task.on_startup = lambda ctx: call_history.append('on_startup') task.on_files_copy = lambda ctx: call_history.append('on_files_copy') task.on_requirements_txt_write = lambda ctx: call_history.append('on_requirements_txt_write')