• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zincware / dask4dvc / 4764305061

pending completion
4764305061

Pull #25

github

GitHub
Merge 68c2654fb into 556449cd0
Pull Request #25: Update dask4dvc arguments

132 of 132 new or added lines in 5 files covered. (100.0%)

237 of 290 relevant lines covered (81.72%)

0.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.41
/tests/test_cli.py
1
"""Test the 'dask4dvc' CLI."""
1✔
2
from typer.testing import CliRunner
1✔
3

4
from dask4dvc.cli.main import app
1✔
5
import zntrack
1✔
6
import pytest
1✔
7
import pathlib
1✔
8
import random
1✔
9
import dvc.cli
1✔
10

11
runner = CliRunner()
1✔
12

13

14
class ReadFile(zntrack.Node):
1✔
15
    """Read a file."""
1✔
16

17
    file: str = zntrack.dvc.deps()
1✔
18
    output: str = zntrack.zn.outs()
1✔
19

20
    def run(self) -> None:
1✔
21
        """ZnTrack run method."""
22
        with open(self.file, "r") as f:
×
23
            self.output = f.read()
×
24

25

26
class CreateData(zntrack.Node):
1✔
27
    """Create some data."""
1✔
28

29
    inputs = zntrack.zn.params()
1✔
30
    output = zntrack.zn.outs()
1✔
31

32
    def run(self) -> None:
1✔
33
        """ZnTrack run method."""
34
        self.output = self.inputs
×
35

36

37
class InputsToOutputs(zntrack.Node):
1✔
38
    """Create some data."""
1✔
39

40
    inputs = zntrack.zn.deps()
1✔
41
    output = zntrack.zn.outs()
1✔
42

43
    def run(self) -> None:
1✔
44
        """ZnTrack run method."""
45
        self.output = self.inputs
×
46

47

48
class RandomData(zntrack.Node):
1✔
49
    """Create some random."""
1✔
50

51
    output = zntrack.zn.outs()
1✔
52

53
    def run(self) -> None:
1✔
54
        """ZnTrack run method."""
55
        self.output = random.random()
×
56

57

58
def test_single_node_repro(repo_path: pathlib.Path) -> None:
1✔
59
    """Test repro of a single node."""
60
    with zntrack.Project() as project:
1✔
61
        node = CreateData(inputs=3.1415)
1✔
62
    project.run(repro=False)
1✔
63
    result = runner.invoke(app, ["repro"])
1✔
64
    assert result.exit_code == 0
1✔
65
    node.load()
1✔
66
    node.output == 3.1415
1✔
67

68

69
def test_multi_node_repro(repo_path: pathlib.Path) -> None:
1✔
70
    """Test repro of multiple nodes."""
71
    with zntrack.Project(automatic_node_names=True) as project:
1✔
72
        data1 = CreateData(inputs=3.1415)
1✔
73
        data2 = CreateData(inputs=2.7182)
1✔
74

75
        node1 = InputsToOutputs(inputs=data1.output)
1✔
76
        node2 = InputsToOutputs(inputs=data2.output)
1✔
77

78
    project.run(repro=False)
1✔
79
    result = runner.invoke(app, ["repro"])
1✔
80
    assert result.exit_code == 0
1✔
81

82
    node1.load()
1✔
83
    node2.load()
1✔
84

85
    assert node1.output == 3.1415
1✔
86
    assert node2.output == 2.7182
1✔
87

88

89
def test_multi_node_repro_targets(repo_path: pathlib.Path) -> None:
1✔
90
    """Test repro of selected nodes."""
91
    with zntrack.Project(automatic_node_names=True) as project:
1✔
92
        data1 = CreateData(inputs=3.1415)
1✔
93
        data2 = CreateData(inputs=2.7182)
1✔
94

95
        node1 = InputsToOutputs(inputs=data1.output)
1✔
96
        node2 = InputsToOutputs(inputs=data2.output)
1✔
97

98
    project.run(repro=False)
1✔
99
    result = runner.invoke(app, ["repro", node1.name])
1✔
100
    assert result.exit_code == 0
1✔
101

102
    node1.load()
1✔
103
    with pytest.raises(AttributeError):
1✔
104
        node2.load(lazy=False)
1✔
105
        # TODO ZnTrack: should not require lazy for the error upton access
106

107
    assert node1.output == 3.1415
1✔
108

109

110
def test_single_node_repro_force(repo_path: pathlib.Path) -> None:
1✔
111
    """Test repro of a single node."""
112
    with zntrack.Project() as project:
1✔
113
        node = RandomData()
1✔
114
    project.run(repro=False)
1✔
115
    result = runner.invoke(app, ["repro"])
1✔
116
    assert result.exit_code == 0
1✔
117
    node.load(lazy=False)
1✔
118

119
    result = runner.invoke(app, ["repro"])
1✔
120
    assert result.exit_code == 0
1✔
121

122
    node2 = RandomData.from_rev(lazy=False)
1✔
123
    assert node2.output == pytest.approx(node.output)
1✔
124

125
    result = runner.invoke(app, ["repro", "--force"])
1✔
126
    assert result.exit_code == 0
1✔
127

128
    node2 = RandomData.from_rev(lazy=False)
1✔
129
    assert node2.output != pytest.approx(node.output)
1✔
130

131

132
def test_single_node_file_deps(repo_path: pathlib.Path) -> None:
1✔
133
    """Test repro of a single node with file deps."""
134
    with open("test.txt", "w") as f:
1✔
135
        f.write("Hello World")
1✔
136
    assert dvc.cli.main(["add", "test.txt"]) == 0
1✔
137

138
    with zntrack.Project() as project:
1✔
139
        node = ReadFile(file="test.txt")
1✔
140
    project.run(repro=False)
1✔
141
    result = runner.invoke(app, ["repro"])
1✔
142
    assert result.exit_code == 0
1✔
143

144
    node.load(lazy=False)
1✔
145
    assert node.output == "Hello World"
1✔
146

147
    # Now force and target
148
    result = runner.invoke(app, ["repro", "-f", "ReadFile"])
1✔
149
    assert result.exit_code == 0
1✔
150

151
    node.load(lazy=False)
1✔
152
    assert node.output == "Hello World"
1✔
153

154

155
def test_multi_complex_graph(repo_path: pathlib.Path) -> None:
1✔
156
    """Test a more complex path that failed before."""
157
    with zntrack.Project(automatic_node_names=True) as project:
1✔
158
        data1 = CreateData(inputs=3.1415)
1✔
159
        data2 = CreateData(inputs=2.7182)
1✔
160

161
        node1 = InputsToOutputs(inputs=[data1.output, data2.output])
1✔
162
        node2 = InputsToOutputs(inputs=node1.output)
1✔
163
        node3 = InputsToOutputs(inputs=node1.output)
1✔
164

165
        node4 = InputsToOutputs(inputs=[node2.output, node3.output])
1✔
166

167
        InputsToOutputs(inputs=[node4.output, node2.output])
1✔
168

169
    project.run(repro=False)
1✔
170
    result = runner.invoke(app, ["repro"])
1✔
171
    assert result.exit_code == 0
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc