def test_streams_cleanup(runner, project, run): """Test cleanup of standard streams.""" source = Path(project) / 'source.txt' stdout = Path(project) / 'result.txt' with source.open('w') as fp: fp.write('first,second,third') # File outside the Git index should be deleted. assert 1 == run( args=('run', 'cat', source.name), stdout=stdout, ), 'The repo must be dirty.' with source.open('r') as fp: assert fp.read() == 'first,second,third' assert not stdout.exists() result = runner.invoke(cli.cli, ['status']) assert 1 == result.exit_code # File from the Git index should be restored. repo = git.Repo(project) with stdout.open('w') as fp: fp.write('1') repo.index.add(['result.txt']) assert 1 == run( args=('run', 'cat', 'source.txt'), stdout=stdout, ), 'The repo must be dirty.' with stdout.open('r') as fp: assert fp.read() == '1'
def test_do_not_override_existing_files(isolated_runner): """Run init with existing files.""" runner = isolated_runner dockerfile = Path('Dockerfile') dockerfile_content = 'FROM alpine' with dockerfile.open('w') as fp: fp.write(dockerfile_content) requirements = Path('requirements.txt') requirements_content = 'pandas' with requirements.open('w') as fp: fp.write(requirements_content) # The order of answers depends on CI_TEMPLATES. # from renku.cli.runner import CI_TEMPLATES result = runner.invoke(cli.cli, ['init'], input='y\nn\n') assert 1 == result.exit_code with dockerfile.open() as fp: assert dockerfile_content != fp.read().strip() with requirements.open() as fp: assert requirements_content == fp.read().strip()