Skip to content

Commit

Permalink
fix: merged with shaun
Browse files Browse the repository at this point in the history
  • Loading branch information
ElijahCFisher committed Feb 24, 2022
1 parent 28a14df commit b7fe04c
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
venv/**/*
venv
tmp
tmp
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 88
extend-ignore = E203
44 changes: 44 additions & 0 deletions src/kedro_dvc/create_sample_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import subprocess
import sys


def create_sample_project(
name: str, from_branch: str = "sample-project-basic"
): # type: ignore
if name == "":
print("usage: python3.8 setup_sample_project.py <name> [from_branch]")
return

print("creating sample project $name from branch $from_branch")

os.makedirs(f"tmp/{name}")
os.chdir(f"tmp/{name}")
subprocess.check_call(
[
"git",
"clone",
"https://github.com/FactFiber/kedro-dvc.git",
"-b",
from_branch,
".",
]
)
# using virtualenv.create_environment no longer works
subprocess.check_call(["virtualenv", f"env/{name}"])
activate_this_file = "env/test/bin/activate_this.py"
exec(
compile(
open(activate_this_file, "rb").read(), activate_this_file, "exec"
),
dict(__file__=activate_this_file),
)
subprocess.check_call(["pip", "install", "--upgrade", "pip"])
subprocess.check_call(["pip", "install", "-r", "src/requirements.txt"])
# we should see kedro-dvc commands listed
print(subprocess.check_output(["pip", "freeze"]))
print('to use the sample project run "source env/$name/bin/activate"')


if __name__ == "__main__":
create_sample_project(name=sys.argv[1], from_branch=sys.argv[2])
Empty file added tests/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# from tests.fixtures import * # noqa

# pytest_plugins = ["fixtures"]
48 changes: 48 additions & 0 deletions tests/test_create-sample-project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import subprocess

import pytest

from src.kedro_dvc.create_sample_project import create_sample_project


def test_create_sample_project_success():
prev_dir: str = os.getcwd()
name: str = "test"
from_branch: str = "sample-project-basic"

create_sample_project(name, from_branch)

current_dir: str = os.getcwd()
dirs = [d for d in os.listdir() if not os.path.isfile(d)]
# pip.utils.get_installed_distributions() no longer exists
freeze = subprocess.check_output(["pip", "freeze"])
pip_modules = [
i[i.find("\\n") + 2 :] for i in ("\\n" + str(freeze)[2:]).split("==")
][:-1]

assert prev_dir != current_dir
assert current_dir.endswith(f"tmp/{name}")
assert "env" in dirs
assert "src" in dirs
print(pip_modules)
assert "wcwidth" in pip_modules


def test_create_sample_project_no_name():
prev_dir: str = os.getcwd()
name: str = ""
from_branch: str = "sample-project-basic"

create_sample_project(name, from_branch)

current_dir: str = os.getcwd()

assert prev_dir == current_dir


def test_create_sample_project_nonexistant_branch():
name: str = "test"
from_branch: str = "nonexistant-branch"
with pytest.raises(Exception):
create_sample_project(name, from_branch)
2 changes: 2 additions & 0 deletions tests/test_fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# check info function of returned structs of each fixture
# test correct working directory

0 comments on commit b7fe04c

Please sign in to comment.