Skip to content

Commit 1997e34

Browse files
jsamjirikuncar
authored andcommitted
test(fixture): add fixture for old repository with tests
1 parent ee71eff commit 1997e34

File tree

4 files changed

+73
-4
lines changed

4 files changed

+73
-4
lines changed

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ recursive-include renku *.sh
5656
recursive-include renku *.txt
5757
recursive-include renku *.yml
5858
recursive-include renku Dockerfile
59-
recursive-include tests *.py
59+
recursive-include tests *.py *.gz
6060
prune .github

conftest.py

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ def runner(monkeypatch):
5959
@pytest.fixture()
6060
def run(runner, capsys):
6161
"""Return a callable runner."""
62-
import contextlib
63-
6462
from renku import cli
6563
from renku._contexts import Isolation
6664

@@ -102,7 +100,6 @@ def data_file(tmpdir):
102100
def repository():
103101
"""Yield a Renku repository."""
104102
from renku import cli
105-
from renku.api import LocalClient
106103
runner = CliRunner()
107104

108105
with runner.isolated_filesystem() as project_path:
@@ -203,6 +200,55 @@ def data_repository(directory_tree):
203200
return repo
204201

205202

203+
@pytest.fixture(
204+
params=[
205+
'test-renku-v0.3.0.git',
206+
],
207+
scope='module',
208+
)
209+
def old_bare_repository(request, tmpdir_factory):
210+
"""Prepares a testing repo created by old version of renku."""
211+
import tarfile
212+
from renku._compat import Path
213+
214+
compressed_repo_path = Path(__file__).parent / 'tests' / 'fixtures' / '{0}.tar.gz'.format(request.param)
215+
working_dir_path = tmpdir_factory.mktemp(request.param)
216+
217+
with tarfile.open(str(compressed_repo_path), 'r') as fixture:
218+
fixture.extractall(working_dir_path.strpath)
219+
220+
yield working_dir_path / request.param
221+
222+
shutil.rmtree(working_dir_path.strpath)
223+
224+
225+
@pytest.fixture(scope='module')
226+
def old_repository(tmpdir_factory, old_bare_repository):
227+
"""Create git repo of old repository fixture."""
228+
import shutil
229+
from git import Repo
230+
231+
repo_path = tmpdir_factory.mktemp('repo')
232+
yield Repo(old_bare_repository.strpath).clone(repo_path.strpath)
233+
shutil.rmtree(repo_path.strpath)
234+
235+
236+
@pytest.fixture
237+
def old_project(old_repository):
238+
"""Create a test project."""
239+
repo = old_repository
240+
repository = repo.working_dir
241+
242+
commit = repo.head.commit
243+
244+
os.chdir(repository)
245+
yield repository
246+
os.chdir(repository)
247+
repo.head.reset(commit, index=True, working_tree=True)
248+
# remove any extra non-tracked files (.pyc, etc)
249+
repo.git.clean('-xdff')
250+
251+
206252
@pytest.fixture(autouse=True)
207253
def add_client(doctest_namespace):
208254
"""Add Renku client to doctest namespace."""
18.7 KB
Binary file not shown.

tests/test_cli.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,29 @@ def test_file_tracking(isolated_runner):
600600
assert 'output' in gitattributes
601601

602602

603+
def test_status_with_old_repository(isolated_runner, old_project):
604+
"""Test status on all old repositories created by old version of renku."""
605+
runner = isolated_runner
606+
607+
result = runner.invoke(cli.cli, ['status'])
608+
assert result.exit_code == 0
609+
610+
output = result.output.split('\n')
611+
assert output.pop(0) == 'On branch master'
612+
assert output.pop(0) == 'All files were generated from the latest inputs.'
613+
614+
615+
def test_update_with_old_repository(isolated_runner, old_project):
616+
"""Test update on all old repositories created by old version of renku."""
617+
runner = isolated_runner
618+
619+
result = runner.invoke(cli.cli, ['update'])
620+
assert result.exit_code == 0
621+
622+
output = result.output.split('\n')
623+
assert output.pop(0) == 'All files were generated from the latest inputs.'
624+
625+
603626
def test_status_with_submodules(isolated_runner, monkeypatch):
604627
"""Test status calculation with submodules."""
605628
runner = isolated_runner

0 commit comments

Comments
 (0)