1
+ import textwrap
2
+
1
3
from dvc .cli import parse_args
2
4
from dvc .command .metrics import CmdMetricsDiff , CmdMetricsShow , _show_diff
3
5
@@ -37,25 +39,30 @@ def test_metrics_diff(dvc, mocker):
37
39
def test_metrics_show_json_diff ():
38
40
assert _show_diff (
39
41
{"metrics.json" : {"a.b.c" : {"old" : 1 , "new" : 2 , "diff" : 3 }}}
40
- ) == (
41
- " Path Metric Value Change\n "
42
- "metrics.json a.b.c 2 3 "
42
+ ) == textwrap .dedent (
43
+ """\
44
+ Path Metric Value Change
45
+ metrics.json a.b.c 2 3"""
43
46
)
44
47
45
48
46
49
def test_metrics_show_raw_diff ():
47
- assert _show_diff ({"metrics" : {"" : {"old" : "1" , "new" : "2" }}}) == (
48
- " Path Metric Value Change \n "
49
- "metrics 2 diff not supported"
50
+ assert _show_diff (
51
+ {"metrics" : {"" : {"old" : "1" , "new" : "2" }}}
52
+ ) == textwrap .dedent (
53
+ """\
54
+ Path Metric Value Change
55
+ metrics 2 diff not supported"""
50
56
)
51
57
52
58
53
59
def test_metrics_diff_no_diff ():
54
60
assert _show_diff (
55
61
{"other.json" : {"a.b.d" : {"old" : "old" , "new" : "new" }}}
56
- ) == (
57
- " Path Metric Value Change \n "
58
- "other.json a.b.d new diff not supported"
62
+ ) == textwrap .dedent (
63
+ """\
64
+ Path Metric Value Change
65
+ other.json a.b.d new diff not supported"""
59
66
)
60
67
61
68
@@ -66,18 +73,20 @@ def test_metrics_diff_no_changes():
66
73
def test_metrics_diff_new_metric ():
67
74
assert _show_diff (
68
75
{"other.json" : {"a.b.d" : {"old" : None , "new" : "new" }}}
69
- ) == (
70
- " Path Metric Value Change \n "
71
- "other.json a.b.d new diff not supported"
76
+ ) == textwrap .dedent (
77
+ """\
78
+ Path Metric Value Change
79
+ other.json a.b.d new diff not supported"""
72
80
)
73
81
74
82
75
83
def test_metrics_diff_deleted_metric ():
76
84
assert _show_diff (
77
85
{"other.json" : {"a.b.d" : {"old" : "old" , "new" : None }}}
78
- ) == (
79
- " Path Metric Value Change \n "
80
- "other.json a.b.d None diff not supported"
86
+ ) == textwrap .dedent (
87
+ """\
88
+ Path Metric Value Change
89
+ other.json a.b.d None diff not supported"""
81
90
)
82
91
83
92
@@ -114,9 +123,10 @@ def test_metrics_show(dvc, mocker):
114
123
def test_metrics_diff_prec ():
115
124
assert _show_diff (
116
125
{"other.json" : {"a.b" : {"old" : 0.0042 , "new" : 0.0043 , "diff" : 0.0001 }}}
117
- ) == (
118
- " Path Metric Value Change\n "
119
- "other.json a.b 0.0043 0.0001"
126
+ ) == textwrap .dedent (
127
+ """\
128
+ Path Metric Value Change
129
+ other.json a.b 0.0043 0.0001"""
120
130
)
121
131
122
132
@@ -129,9 +139,38 @@ def test_metrics_diff_sorted():
129
139
"a.b.c" : {"old" : 1 , "new" : 2 , "diff" : 1 },
130
140
}
131
141
}
132
- ) == (
133
- " Path Metric Value Change\n "
134
- "metrics.yaml a.b.c 2 1 \n "
135
- "metrics.yaml a.d.e 4 1 \n "
136
- "metrics.yaml x.b 6 1 "
142
+ ) == textwrap .dedent (
143
+ """\
144
+ Path Metric Value Change
145
+ metrics.yaml a.b.c 2 1
146
+ metrics.yaml a.d.e 4 1
147
+ metrics.yaml x.b 6 1"""
148
+ )
149
+
150
+
151
+ def test_metrics_diff_markdown_empty ():
152
+ assert _show_diff ({}, markdown = True ) == textwrap .dedent (
153
+ """\
154
+ | Path | Metric | Value | Change |
155
+ |--------|----------|---------|----------|"""
156
+ )
157
+
158
+
159
+ def test_metrics_diff_markdown ():
160
+ assert _show_diff (
161
+ {
162
+ "metrics.yaml" : {
163
+ "x.b" : {"old" : 5 , "new" : 6 },
164
+ "a.d.e" : {"old" : 3 , "new" : 4 , "diff" : 1 },
165
+ "a.b.c" : {"old" : 1 , "new" : 2 , "diff" : 1 },
166
+ }
167
+ },
168
+ markdown = True ,
169
+ ) == textwrap .dedent (
170
+ """\
171
+ | Path | Metric | Value | Change |
172
+ |--------------|----------|---------|--------------------|
173
+ | metrics.yaml | a.b.c | 2 | 1 |
174
+ | metrics.yaml | a.d.e | 4 | 1 |
175
+ | metrics.yaml | x.b | 6 | diff not supported |"""
137
176
)
0 commit comments