Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
Stabilize test that was depending on RELEASED VERSION of self
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Jul 20, 2020
1 parent 9f5a2e3 commit 320fcbc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/rkd/standardlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down
12 changes: 10 additions & 2 deletions test/test_standardlib_createstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 320fcbc

Please sign in to comment.