Skip to content

Commit

Permalink
dvc: initial unittests
Browse files Browse the repository at this point in the history
Initial unittests for new design.

Signed-off-by: Ruslan Kuprieiev <[email protected]>
  • Loading branch information
efiop committed Jan 1, 2018
1 parent 0d7862e commit f47a2c7
Show file tree
Hide file tree
Showing 29 changed files with 483 additions and 1,273 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ install:
- printf "[default]\naws_access_key_id = $AWS_ACCESS_KEY_ID\naws_secret_access_key = $AWS_SECRET_ACCESS_KEY\n" > ~/.aws/credentials
- printf "[default]\n" > ~/.aws/config
script:
# Temporarily disabled untill dvc is stable
# - ./unittests.sh
- ./unittests.sh
- ./functests.sh
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./build_macos.sh; else ./build_linux.sh; fi
- ./build_package.sh
Expand Down
2 changes: 1 addition & 1 deletion dvc/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Cache(object):
CACHE_DIR = 'cache'

def __init__(self, dvc_dir):
self.cache_dir = os.path.join(dvc_dir, self.CACHE_DIR)
self.cache_dir = os.path.abspath(os.path.realpath(os.path.join(dvc_dir, self.CACHE_DIR)))

@staticmethod
def init(dvc_dir):
Expand Down
91 changes: 0 additions & 91 deletions dvc/command/common/traverse.py

This file was deleted.

2 changes: 1 addition & 1 deletion dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Config(object):
'''

def __init__(self, dvc_dir):
self.dvc_dir = dvc_dir
self.dvc_dir = os.path.abspath(os.path.realpath(dvc_dir))
self.config_file = os.path.join(dvc_dir, self.CONFIG)

self._config = configparser.SafeConfigParser()
Expand Down
49 changes: 43 additions & 6 deletions dvc/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Project(object):
DVC_DIR = '.dvc'

def __init__(self, root_dir):
self.root_dir = os.path.abspath(root_dir)
self.root_dir = os.path.abspath(os.path.realpath(root_dir))
self.dvc_dir = os.path.join(self.root_dir, self.DVC_DIR)

self.scm = SCM(self.root_dir)
Expand All @@ -73,6 +73,18 @@ def __init__(self, root_dir):

@staticmethod
def init(root_dir):
"""
Initiate dvc project in directory.
Args:
root_dir: Path to project's root directory.
Returns:
Project instance.
Raises:
KeyError: Raises an exception.
"""
root_dir = os.path.abspath(root_dir)
dvc_dir = os.path.join(root_dir, Project.DVC_DIR)
os.mkdir(dvc_dir)
Expand Down Expand Up @@ -106,12 +118,23 @@ def add(self, fname):
locked=True)
stage.save()
stage.dump()
return stage

def remove(self, fname):
path = os.path.abspath(fname)
stages = []
output = Output.loads(self, fname)
for out in self.outs():
if out.path == path:
out.stage().remove()
if out.path == output.path:
stage = out.stage()
stages.append(stage)

if len(stages) == 0:
raise StageNotFoundError(fname)

for stage in stages:
stage.remove()

return stages

def _add_orphans(self, deps):
outs = [out.path for out in self.outs()]
Expand All @@ -120,7 +143,15 @@ def _add_orphans(self, deps):
continue
self.add(dep.path)

def run(self, cmd, deps, deps_no_cache, outs, outs_no_cache, locked, fname, cwd):
def run(self,
cmd=None,
deps=[],
deps_no_cache=[],
outs=[],
outs_no_cache=[],
locked=False,
fname=Stage.STAGE_FILE,
cwd=os.curdir):
cwd = os.path.abspath(cwd)
path = os.path.join(cwd, fname)
outputs = Output.loads_from(self, outs, use_cache=True, cwd=cwd)
Expand All @@ -140,8 +171,10 @@ def run(self, cmd, deps, deps_no_cache, outs, outs_no_cache, locked, fname, cwd)
locked=locked)
stage.run()
stage.dump()
return stage

def reproduce(self, targets, recursive=False, force=False):
def reproduce(self, targets, recursive=True, force=False):
reproduced = []
stages = nx.get_node_attributes(self.graph(), 'stage')
for target in targets:
node = os.path.relpath(os.path.abspath(target), self.root_dir)
Expand All @@ -152,9 +185,13 @@ def reproduce(self, targets, recursive=False, force=False):
for n in nx.dfs_postorder_nodes(self.graph(), node):
stages[n].reproduce(force=force)
stages[n].dump()
reproduced.append(stages[n])

stages[node].reproduce(force=force)
stages[node].dump()
reproduced.append(stages[node])

return reproduced

def checkout(self):
for stage in self.stages():
Expand Down
129 changes: 0 additions & 129 deletions dvc/repository_change.py

This file was deleted.

Loading

0 comments on commit f47a2c7

Please sign in to comment.