-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from zincware/development
Update to [PyTrack 0.1.2]
- Loading branch information
Showing
30 changed files
with
3,233 additions
and
2,446 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
This program and the accompanying materials are made available under the terms of the | ||
Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
https://www.eclipse.org/legal/epl-v20.html | ||
SPDX-License-Identifier: EPL-2.0 | ||
Copyright Contributors to the Zincware Project. | ||
Description: | ||
""" | ||
import pytest | ||
from pytrack import PyTrack, PyTrackProject | ||
import shutil | ||
import os | ||
from subprocess import CalledProcessError | ||
|
||
|
||
@PyTrack() | ||
class RaiseValueError: | ||
"""BasicTest class""" | ||
|
||
def run(self): | ||
"""Run method of the PyTrack test instance""" | ||
raise ValueError("Testing ValueError") | ||
|
||
|
||
def test_project(tmp_path): | ||
"""Test that an ValueError is raised | ||
Currently it is not checked, which Error occurs in the subprocess but just that the subprocess call fails. | ||
It only works within `project.repro` and not with `project.run` | ||
""" | ||
shutil.copy(__file__, tmp_path) | ||
os.chdir(tmp_path) | ||
|
||
project = PyTrackProject() | ||
project.create_dvc_repository() | ||
|
||
error_stage = RaiseValueError() | ||
error_stage() | ||
|
||
with pytest.raises(CalledProcessError): | ||
project.repro() | ||
|
||
# with pytest.raises(CalledProcessError): | ||
# project.run() | ||
|
||
with pytest.raises(ValueError): | ||
error_stage.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
""" | ||
This program and the accompanying materials are made available under the terms of the | ||
Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
https://www.eclipse.org/legal/epl-v20.html | ||
SPDX-License-Identifier: EPL-2.0 | ||
Copyright Contributors to the Zincware Project. | ||
Description: | ||
""" | ||
from pytrack import PyTrack, DVC, PyTrackProject | ||
import os | ||
|
||
|
||
@PyTrack() | ||
class HelloWorld: | ||
def __init__(self): | ||
self.argument_1 = DVC.params() | ||
|
||
def __call__(self, argument_1): | ||
self.argument_1 = argument_1 | ||
|
||
def run(self): | ||
pass | ||
|
||
|
||
@PyTrack() | ||
class HelloWorldwDefault: | ||
def __init__(self): | ||
self.argument_1 = DVC.params(314159) | ||
|
||
def __call__(self, argument_1): | ||
self.argument_1 = argument_1 | ||
|
||
def run(self): | ||
pass | ||
|
||
|
||
def test_init_without_overwriting(tmp_path): | ||
"""Test that initializing empty DVC.params does not result in changing values""" | ||
os.chdir(tmp_path) | ||
project = PyTrackProject() | ||
project.create_dvc_repository() | ||
|
||
hello_world_1 = HelloWorld() | ||
hello_world_1(argument_1=11235) | ||
|
||
hello_world_2 = HelloWorld() | ||
|
||
# it should not overwrite the given param values, | ||
# when they are not set explicitly! | ||
|
||
assert hello_world_1.argument_1 == 11235 | ||
|
||
|
||
def test_load_works(tmp_path): | ||
"""Test that pre-initializing DVC.params does result in changing values""" | ||
os.chdir(tmp_path) | ||
project = PyTrackProject() | ||
project.create_dvc_repository() | ||
|
||
hello_world_1 = HelloWorldwDefault() | ||
hello_world_1(argument_1=11235) | ||
|
||
assert HelloWorldwDefault().argument_1 == 314159 | ||
assert HelloWorldwDefault(load=True).argument_1 == 11235 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
""" | ||
This program and the accompanying materials are made available under the terms of the | ||
Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
https://www.eclipse.org/legal/epl-v20.html | ||
SPDX-License-Identifier: EPL-2.0 | ||
Copyright Contributors to the Zincware Project. | ||
Description: | ||
""" | ||
from pytrack import PyTrack, DVC | ||
import shutil | ||
import os | ||
|
||
|
||
@PyTrack() | ||
class Stage1: | ||
args = DVC.params() | ||
|
||
def __call__(self, args): | ||
self.args = args | ||
|
||
def run(self): | ||
pass | ||
|
||
|
||
@PyTrack() | ||
class Stage2: | ||
stage_1: Stage1 = DVC.deps(Stage1(load=True)) | ||
|
||
def __call__(self, *args, **kwargs): | ||
pass | ||
|
||
def run(self): | ||
pass | ||
|
||
|
||
def test_stage_stage_dependency(tmp_path): | ||
"""Test that stage dependencies including load work as expected""" | ||
shutil.copy(__file__, tmp_path) | ||
os.chdir(tmp_path) | ||
|
||
stage_1 = Stage1() | ||
stage_1(args="Test01") | ||
# Need to call the stage, to create the config file | ||
# it does not make sense to access the results of a stage | ||
# that has not at least been called | ||
stage_2 = Stage2() | ||
stage_2() | ||
|
||
stage_2a = Stage2(load=True) | ||
|
||
# changing the value of Stage1 in the config file | ||
stage_1 = Stage1() | ||
stage_1(args="Test02") | ||
|
||
# Loading the stage it should now have the new value | ||
stage_2b = Stage2(load=True) | ||
|
||
assert stage_2a.stage_1.args == "Test01" | ||
assert stage_2b.stage_1.args == "Test02" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.