Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup proj_path fixture #379

Merged
merged 3 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,149 changes: 1,136 additions & 1,013 deletions poetry.lock

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Collection of common fixtures
References
----------
https://docs.pytest.org/en/6.2.x/fixture.html#scope-sharing-fixtures-across-classes-modules-packages-or-session
"""
import os
import pathlib
import shutil
import subprocess

import pytest


@pytest.fixture
def proj_path(tmp_path, request) -> pathlib.Path:
"""temporary directory for testing DVC calls

Parameters
----------
tmp_path
request: https://docs.pytest.org/en/6.2.x/reference.html#std-fixture-request

Returns
-------
path to temporary directory

"""
shutil.copy(request.module.__file__, tmp_path)
os.chdir(tmp_path)
subprocess.check_call(["git", "init"])
subprocess.check_call(["dvc", "init"])

subprocess.check_call(["git", "add", "."])
subprocess.check_call(["git", "commit", "-m", "init"])

return tmp_path
12 changes: 2 additions & 10 deletions tests/integration_tests/examples/test_example_01.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
""""""
import os
import shutil
from pathlib import Path

from zntrack import Node, ZnTrackProject, dvc, zn
Expand Down Expand Up @@ -53,12 +51,9 @@ def run(self):
Path(self.outs).write_text(f"{self.n_1} + {self.n_2} = {self.sum}")


def test_stage_addition(tmp_path):
def test_stage_addition(proj_path):
"""Check that the dvc repro works"""
shutil.copy(__file__, tmp_path)
os.chdir(tmp_path)
project = ZnTrackProject()
project.create_dvc_repository()

StageAddition(5, 10).write_graph()
project.name = "Test1"
Expand All @@ -78,12 +73,9 @@ def test_stage_addition(tmp_path):
assert finished_stage.sum == 150


def test_stage_io(tmp_path):
shutil.copy(__file__, tmp_path)
os.chdir(tmp_path)
def test_stage_io(proj_path):
project = ZnTrackProject()
project.name = "Test1"
project.create_dvc_repository()

deps = Path("test_example_01.py").resolve()

Expand Down
36 changes: 5 additions & 31 deletions tests/integration_tests/examples/test_example_02.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import os
import shutil

import numpy as np

from zntrack import Node, ZnTrackProject, dvc, zn
Expand Down Expand Up @@ -79,13 +76,10 @@ def run(self):
self.out = self.a.out + self.b.out


def test_stage_addition(tmp_path):
def test_stage_addition(proj_path):
"""Check that the dvc repro works"""
shutil.copy(__file__, tmp_path)
os.chdir(tmp_path)
project = ZnTrackProject()
project.name = "test01"
project.create_dvc_repository()

ComputeA(inp=2).write_graph()
ComputeB(inp=3).write_graph()
Expand All @@ -97,13 +91,10 @@ def test_stage_addition(tmp_path):
assert finished_stage.out == 31


def test_stage_addition_named(tmp_path):
def test_stage_addition_named(proj_path):
"""Check that the dvc repro works with named stages"""
shutil.copy(__file__, tmp_path)
os.chdir(tmp_path)
project = ZnTrackProject()
project.name = "test01"
project.create_dvc_repository()

ComputeANamed(inp=2).write_graph()
ComputeB(inp=3).write_graph()
Expand All @@ -114,14 +105,8 @@ def test_stage_addition_named(tmp_path):
assert finished_stage.out == 31


def test_stage_addition_run(tmp_path):
def test_stage_addition_run(proj_path):
"""Check that the PyTracks run method works"""
shutil.copy(__file__, tmp_path)
os.chdir(tmp_path)
project = ZnTrackProject()
project.name = "test01"
project.create_dvc_repository()

a = ComputeA(inp=2)
a.run_and_save() # I must save here, because of the dependency of the output in AB
b = ComputeB(inp=3)
Expand All @@ -134,14 +119,8 @@ def test_stage_addition_run(tmp_path):
assert finished_stage.out == 31


def test_stage_addition_named_run(tmp_path):
def test_stage_addition_named_run(proj_path):
"""Check that the PyTracks run method works with named stages"""
shutil.copy(__file__, tmp_path)
os.chdir(tmp_path)
project = ZnTrackProject()
project.name = "test01"
project.create_dvc_repository()

ComputeANamed(inp=2).save()
ComputeB(inp=3).save()
ComputeAB().save()
Expand All @@ -155,13 +134,8 @@ def test_stage_addition_named_run(tmp_path):
assert finished_stage.out == 31


def test_named_single_stage(tmp_path):
def test_named_single_stage(proj_path):
"""Test a single named stage"""
shutil.copy(__file__, tmp_path)
os.chdir(tmp_path)
project = ZnTrackProject()
project.create_dvc_repository()

ComputeANamed(inp=2).write_graph(no_exec=False)

assert ComputeANamed.load().out == 4
19 changes: 1 addition & 18 deletions tests/integration_tests/examples/test_example_03.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
"""
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 os
import shutil

from zntrack import Node, ZnTrackProject, dvc, zn


Expand Down Expand Up @@ -60,13 +47,9 @@ def run(self):
self.number = self.inp[0].number + self.inp[1].number


def test_repro(tmp_path):
def test_repro(proj_path):
"""Test that a single DVC.deps() can take a list of dependencies"""
shutil.copy(__file__, tmp_path)
os.chdir(tmp_path)

project = ZnTrackProject()
project.create_dvc_repository()

CreateNumbers().write_graph()
AddOne().write_graph()
Expand Down
9 changes: 1 addition & 8 deletions tests/integration_tests/examples/test_example_04.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import os
import shutil

from zntrack import Node, ZnTrackProject, zn


Expand All @@ -19,13 +16,9 @@ def run(self):
self.output = self.inputs


def test_basic_io_assertion(tmp_path):
def test_basic_io_assertion(proj_path):
"""Make a simple input/output assertion test for the nodes with different names"""
shutil.copy(__file__, tmp_path)
os.chdir(tmp_path)

project = ZnTrackProject()
project.create_dvc_repository()

HelloWorld(inputs=3).write_graph()
HelloWorld(name="Test01", inputs=17).write_graph()
Expand Down
17 changes: 2 additions & 15 deletions tests/integration_tests/examples/test_example_05.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import os
import shutil

import numpy as np

from zntrack import Node, ZnTrackProject, zn
Expand All @@ -20,13 +17,9 @@ def run(self):
self.out = np.power(2, self.inp)


def test_stage_addition(tmp_path):
def test_stage_addition(proj_path):
"""Check that the dvc repro works"""
shutil.copy(__file__, tmp_path)
os.chdir(tmp_path)
project = ZnTrackProject()
project.name = "test01"
project.create_dvc_repository()

ComputeA(inp=np.arange(5)).write_graph()

Expand All @@ -37,14 +30,8 @@ def test_stage_addition(tmp_path):
np.testing.assert_array_equal(finished_stage.inp, np.arange(5))


def test_stage_addition_run(tmp_path):
def test_stage_addition_run(proj_path):
"""Check that the PyTracks run method works"""
shutil.copy(__file__, tmp_path)
os.chdir(tmp_path)
project = ZnTrackProject()
project.name = "test01"
project.create_dvc_repository()

a = ComputeA(inp=np.arange(5))

a.save() # need to save to access the parameters zn.params
Expand Down
14 changes: 0 additions & 14 deletions tests/integration_tests/function_wrapper/test_func_func_deps.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import os
import pathlib
import shutil
import subprocess

import pytest

from zntrack.core.functions.decorator import NodeConfig, nodify


@pytest.fixture
def proj_path(tmp_path):
shutil.copy(__file__, tmp_path)
os.chdir(tmp_path)
subprocess.check_call(["git", "init"])
subprocess.check_call(["dvc", "init"])

return tmp_path


@nodify(outs=pathlib.Path("test.txt"), params={"text": "Lorem Ipsum"})
def func_1(cfg: NodeConfig):
cfg.outs.write_text(cfg.params.text)
Expand Down
14 changes: 0 additions & 14 deletions tests/integration_tests/function_wrapper/test_func_node_deps.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import os
import pathlib
import shutil
import subprocess

import pytest

from zntrack import dvc, zn
from zntrack.core.base import Node
from zntrack.core.functions.decorator import NodeConfig, nodify


@pytest.fixture
def proj_path(tmp_path):
shutil.copy(__file__, tmp_path)
os.chdir(tmp_path)
subprocess.check_call(["git", "init"])
subprocess.check_call(["dvc", "init"])

return tmp_path


@nodify(outs=pathlib.Path("text.txt"), params={"text": "Lorem Ipsum"})
def write_text(cfg: NodeConfig):
cfg.outs.write_text(cfg.params.text)
Expand Down
13 changes: 0 additions & 13 deletions tests/integration_tests/function_wrapper/test_single_function.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
import os
import pathlib
import shutil
import subprocess

import pytest

from zntrack import utils
from zntrack.core.functions.decorator import NodeConfig, nodify


@pytest.fixture
def proj_path(tmp_path):
shutil.copy(__file__, tmp_path)
os.chdir(tmp_path)
subprocess.check_call(["git", "init"])
subprocess.check_call(["dvc", "init"])

return tmp_path


@nodify(outs="test.txt", params={"text": "Lorem Ipsum"})
def example_func(cfg: NodeConfig) -> NodeConfig:
out_file = pathlib.Path(cfg.outs)
Expand Down
20 changes: 0 additions & 20 deletions tests/integration_tests/interface/test_base_interface.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
"""
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 os
import pathlib
import shutil
import subprocess

import pytest
Expand All @@ -31,14 +19,6 @@ def run(self):
self.outputs = self.inputs


@pytest.fixture
def proj_path(tmp_path):
shutil.copy(__file__, tmp_path)
os.chdir(tmp_path)
subprocess.run(["git", "init"])
subprocess.run(["dvc", "init"])


@pytest.fixture()
def single_experiment_path(proj_path):
HelloWorld(inputs=1).write_graph()
Expand Down
14 changes: 0 additions & 14 deletions tests/integration_tests/test_dvc_checkpoints.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
import os
import pathlib
import shutil
import subprocess
import typing

import pytest
import yaml

from zntrack import dvc
from zntrack.core.base import Node


@pytest.fixture
def proj_path(tmp_path):
shutil.copy(__file__, tmp_path)
os.chdir(tmp_path)
subprocess.check_call(["git", "init"])
subprocess.check_call(["dvc", "init"])

return tmp_path


class SingleNode(Node):
path1: pathlib.Path = dvc.checkpoints()

Expand Down
Loading