mcward-cli 1.4.0__tar.gz → 1.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/PKG-INFO +1 -1
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/reporters/github.py +4 -2
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/reporters/live.py +17 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/reports/coverage.css +1 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/reports/html.py +19 -6
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/reports/junit.py +5 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/tests/test_github.py +11 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/tests/test_live.py +25 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/tests/test_reports.py +25 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/.gitignore +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/README.md +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/pyproject.toml +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/__init__.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/commands/__init__.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/commands/bench.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/commands/daemon.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/commands/install.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/commands/list.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/commands/test.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/datapacks.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/environments.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/reporters/__init__.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/reporters/bench.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/reporters/coverage.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/reports/__init__.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/reports/coverage.js +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/reports/lcov.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/session.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/src/mcward/cli/ui.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/tests/conftest.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/tests/test_bench.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/tests/test_cli.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/tests/test_coverage_report.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/tests/test_discovery.py +0 -0
- {mcward_cli-1.4.0 → mcward_cli-1.5.0}/tests/test_environments.py +0 -0
|
@@ -15,7 +15,7 @@ from mcward import (
|
|
|
15
15
|
|
|
16
16
|
from ..datapacks import FileResolver, pack_resolver
|
|
17
17
|
from ..ui import console
|
|
18
|
-
from .live import describe_failure, render_header, render_session
|
|
18
|
+
from .live import describe_failure, describe_log, render_header, render_session
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
def run(
|
|
@@ -73,7 +73,9 @@ def _annotate_test(result: TestResult, resolve: FileResolver) -> str:
|
|
|
73
73
|
file = resolve("test", result.name)
|
|
74
74
|
line = outcome.line if file else None
|
|
75
75
|
level = "error" if failed else "warning"
|
|
76
|
-
|
|
76
|
+
logs = [describe_log(log) for log in result.logs.get(versions[0], [])]
|
|
77
|
+
message = "\n".join([describe_failure(outcome), *logs])
|
|
78
|
+
return _command(level, title, message, file=file, line=line)
|
|
77
79
|
|
|
78
80
|
|
|
79
81
|
def _annotate_diagnostic(
|
|
@@ -10,6 +10,7 @@ from rich.text import Text
|
|
|
10
10
|
from mcward import (
|
|
11
11
|
RunningEnvironment,
|
|
12
12
|
TestBatch,
|
|
13
|
+
TestLog,
|
|
13
14
|
TestResult,
|
|
14
15
|
TestSession,
|
|
15
16
|
TestStatus,
|
|
@@ -77,6 +78,13 @@ def describe_failure(outcome: VersionOutcome, file: str | None = None) -> str:
|
|
|
77
78
|
return f"{outcome.error} ({file}:{outcome.line}, tick {outcome.tick})"
|
|
78
79
|
|
|
79
80
|
|
|
81
|
+
def describe_log(log: TestLog, file: str | None = None) -> str:
|
|
82
|
+
"""The logged text, with its position the way failures show theirs."""
|
|
83
|
+
if file is None:
|
|
84
|
+
return f"log: {log.message} (line {log.line}, tick {log.tick})"
|
|
85
|
+
return f"log: {log.message} ({file}:{log.line}, tick {log.tick})"
|
|
86
|
+
|
|
87
|
+
|
|
80
88
|
def render_header(datapacks: Sequence[str], versions: Sequence[Version]) -> Text:
|
|
81
89
|
"""The single-line ``Testing <packs> on <versions>`` banner."""
|
|
82
90
|
text = Text()
|
|
@@ -219,6 +227,15 @@ def _render_result(text: Text, result: TestResult, resolve: FileResolver | None
|
|
|
219
227
|
if result.outcomes[version].status is TestStatus.SKIPPED
|
|
220
228
|
]
|
|
221
229
|
_render_failure(text, result, skipped, "Skipped", "yellow", resolve)
|
|
230
|
+
_render_logs(text, result, resolve)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def _render_logs(text: Text, result: TestResult, resolve: FileResolver | None = None) -> None:
|
|
234
|
+
file = resolve("test", result.name) if resolve and result.logs else None
|
|
235
|
+
for version in result.versions:
|
|
236
|
+
prefix = f"{version.name}: " if len(result.versions) > 1 else ""
|
|
237
|
+
for log in result.logs.get(version, ()):
|
|
238
|
+
text.append(f" {prefix}{describe_log(log, file)}\n", "dim")
|
|
222
239
|
|
|
223
240
|
|
|
224
241
|
def _render_failure(
|
|
@@ -41,6 +41,7 @@ h1 em { color: var(--muted); font-style: normal; font-weight: normal; }
|
|
|
41
41
|
.counts span { margin-right: 1rem; }
|
|
42
42
|
.passed { color: var(--green); } .failed { color: var(--red); } .skipped { color: var(--yellow); }
|
|
43
43
|
.errors li { margin: .3rem 0; } .errors .message { color: var(--red); }
|
|
44
|
+
.errors .logs { margin: .2rem 0; color: var(--muted); } .errors .logs span { font-size: .85rem; }
|
|
44
45
|
input { margin: 1rem 0 .5rem; padding: .4rem; width: 20rem; }
|
|
45
46
|
.legend { color: var(--muted); font-size: .85rem; margin: .5rem 0 1rem; }
|
|
46
47
|
.legend span { padding: .1rem .65rem; margin-right: .5rem; color: var(--fg); }
|
|
@@ -12,10 +12,11 @@ from mcward import (
|
|
|
12
12
|
FunctionReport,
|
|
13
13
|
ResolvedCoverage,
|
|
14
14
|
ResourceReport,
|
|
15
|
+
TestLog,
|
|
16
|
+
TestResult,
|
|
15
17
|
TestSession,
|
|
16
18
|
TestStatus,
|
|
17
19
|
Version,
|
|
18
|
-
VersionOutcome,
|
|
19
20
|
)
|
|
20
21
|
|
|
21
22
|
_RESOURCES = Path(__file__).parent
|
|
@@ -81,7 +82,8 @@ def _header(session: TestSession, version: Version, coverage: ResolvedCoverage)
|
|
|
81
82
|
files = CoverageTotals.of(coverage.reports)
|
|
82
83
|
touched = f"{files.touched / files.files:.1%}" if files.files else "—"
|
|
83
84
|
|
|
84
|
-
|
|
85
|
+
results = _results(session, version)
|
|
86
|
+
outcomes = {name: result.outcomes[version] for name, result in results.items()}
|
|
85
87
|
passed = sum(o.status is TestStatus.PASSED for o in outcomes.values())
|
|
86
88
|
skipped = sum(o.status is TestStatus.SKIPPED for o in outcomes.values())
|
|
87
89
|
failed = {name: o for name, o in outcomes.items() if o.status is TestStatus.FAILED}
|
|
@@ -104,22 +106,33 @@ def _header(session: TestSession, version: Version, coverage: ResolvedCoverage)
|
|
|
104
106
|
if failed:
|
|
105
107
|
items = "".join(
|
|
106
108
|
f"<li><code>{escape(name)}</code> "
|
|
107
|
-
f'<span class="message">{escape(outcome.error)}</span
|
|
109
|
+
f'<span class="message">{escape(outcome.error)}</span>'
|
|
110
|
+
f"{_logs(results[name].logs.get(version, []))}</li>"
|
|
108
111
|
for name, outcome in failed.items()
|
|
109
112
|
)
|
|
110
113
|
parts.append(f'<ul class="errors">{items}</ul>')
|
|
111
114
|
return "\n".join(parts)
|
|
112
115
|
|
|
113
116
|
|
|
114
|
-
def
|
|
117
|
+
def _results(session: TestSession, version: Version) -> dict[str, TestResult]:
|
|
115
118
|
return {
|
|
116
|
-
result.name:
|
|
119
|
+
result.name: result
|
|
117
120
|
for batch in session.batches
|
|
118
121
|
for result in batch.results
|
|
119
|
-
if
|
|
122
|
+
if version in result.outcomes
|
|
120
123
|
}
|
|
121
124
|
|
|
122
125
|
|
|
126
|
+
def _logs(logs: Sequence[TestLog]) -> str:
|
|
127
|
+
if not logs:
|
|
128
|
+
return ""
|
|
129
|
+
items = "".join(
|
|
130
|
+
f"<li>{escape(log.message)} <span>(line {log.line}, tick {log.tick})</span></li>"
|
|
131
|
+
for log in logs
|
|
132
|
+
)
|
|
133
|
+
return f'<ul class="logs">{items}</ul>'
|
|
134
|
+
|
|
135
|
+
|
|
123
136
|
def _grouped(
|
|
124
137
|
members: Sequence[CoverageReport],
|
|
125
138
|
by_namespace: bool,
|
|
@@ -32,6 +32,11 @@ def write_junit(session: TestSession, path: Path) -> None:
|
|
|
32
32
|
elif outcome.status is TestStatus.SKIPPED:
|
|
33
33
|
skipped += 1
|
|
34
34
|
SubElement(case, "skipped", message=outcome.error)
|
|
35
|
+
if logs := result.logs.get(version):
|
|
36
|
+
output = SubElement(case, "system-out")
|
|
37
|
+
output.text = "".join(
|
|
38
|
+
f"line {log.line}, tick {log.tick}: {log.message}\n" for log in logs
|
|
39
|
+
)
|
|
35
40
|
|
|
36
41
|
errors = 0
|
|
37
42
|
if message := session.aborted.get(version):
|
|
@@ -12,6 +12,7 @@ from mcward._protocol import (
|
|
|
12
12
|
Diagnostic,
|
|
13
13
|
StreamError,
|
|
14
14
|
TestFailed as Failed,
|
|
15
|
+
TestLog as Log,
|
|
15
16
|
TestsStarted as Started,
|
|
16
17
|
)
|
|
17
18
|
from mcward._runner import TestSession as Session
|
|
@@ -138,6 +139,16 @@ class TestFailedTests:
|
|
|
138
139
|
[command] = annotations(session, pack_resolver([]))
|
|
139
140
|
assert command.endswith("::first%0Asecond")
|
|
140
141
|
|
|
142
|
+
def test_logs_follow_the_failure(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
143
|
+
monkeypatch.chdir(tmp_path)
|
|
144
|
+
session = Session([V1])
|
|
145
|
+
start_run(session, V1)
|
|
146
|
+
session._dispatch(V1, Log("ward:logged", message="hello", line=2, tick=3))
|
|
147
|
+
fail_test(session, V1, "ward:logged", "boom", line=4, tick=5)
|
|
148
|
+
|
|
149
|
+
[command] = annotations(session, pack_resolver([]))
|
|
150
|
+
assert command.endswith("::boom (line 4, tick 5)%0Alog: hello (line 2, tick 3)")
|
|
151
|
+
|
|
141
152
|
def test_pack_outside_cwd_but_inside_workspace(
|
|
142
153
|
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
143
154
|
) -> None:
|
|
@@ -8,6 +8,7 @@ from mcward._protocol import (
|
|
|
8
8
|
Diagnostic,
|
|
9
9
|
StreamError,
|
|
10
10
|
TestFailed as Failed,
|
|
11
|
+
TestLog as Log,
|
|
11
12
|
TestPassed as Passed,
|
|
12
13
|
TestsFinished as Finished,
|
|
13
14
|
TestsStarted as Started,
|
|
@@ -191,6 +192,30 @@ class TestRenderSession:
|
|
|
191
192
|
|
|
192
193
|
assert any("boom (line 4, tick 12)" in line for line in rendered_lines(session))
|
|
193
194
|
|
|
195
|
+
def test_logs_show_under_a_failure(self) -> None:
|
|
196
|
+
session = Session([V1])
|
|
197
|
+
start_run(session, V1)
|
|
198
|
+
session._dispatch(V1, Log("a:one", message="hello", line=2, tick=3))
|
|
199
|
+
session._dispatch(V1, Failed("a:one", time=5, error="boom", required=True, line=4, tick=12))
|
|
200
|
+
finish_run(session, V1)
|
|
201
|
+
|
|
202
|
+
lines = rendered_lines(session)
|
|
203
|
+
failure = lines.index(" boom (line 4, tick 12)")
|
|
204
|
+
assert failure < lines.index(" log: hello (line 2, tick 3)")
|
|
205
|
+
|
|
206
|
+
def test_logs_of_a_passed_test_only_show_when_verbose(self) -> None:
|
|
207
|
+
session = Session([V1, V2])
|
|
208
|
+
start_run(session, V1, V2)
|
|
209
|
+
for version in (V1, V2):
|
|
210
|
+
session._dispatch(version, Log("a:one", message="hello", line=2, tick=3))
|
|
211
|
+
session._dispatch(version, Passed(name="a:one", time=5))
|
|
212
|
+
finish_run(session, V1, V2)
|
|
213
|
+
|
|
214
|
+
assert not any("hello" in line for line in rendered_lines(session))
|
|
215
|
+
verbose = render_session(session, verbose=True).plain.splitlines()
|
|
216
|
+
assert " 26.1.2: log: hello (line 2, tick 3)" in verbose
|
|
217
|
+
assert " 26.1.1: log: hello (line 2, tick 3)" in verbose
|
|
218
|
+
|
|
194
219
|
def test_failure_position_shows_resolved_file(self) -> None:
|
|
195
220
|
"""With a resolver the position is the root-relative path:line."""
|
|
196
221
|
session = Session([V1])
|
|
@@ -13,6 +13,7 @@ from mcward._protocol import (
|
|
|
13
13
|
FunctionCoverage,
|
|
14
14
|
StreamError,
|
|
15
15
|
TestFailed as Failed,
|
|
16
|
+
TestLog as Log,
|
|
16
17
|
TestPassed as Passed,
|
|
17
18
|
)
|
|
18
19
|
from mcward._runner import TestSession as Session
|
|
@@ -104,6 +105,18 @@ class TestWriteJunit:
|
|
|
104
105
|
assert find(cases["a:bad"], "failure").get("message") == "boom"
|
|
105
106
|
assert find(cases["a:opt"], "skipped").get("message") == "meh"
|
|
106
107
|
|
|
108
|
+
def test_logs_go_to_system_out(self, tmp_path: Path) -> None:
|
|
109
|
+
session = make_session(V1)
|
|
110
|
+
session._dispatch(V1, Log("a:bad", message="hello", line=2, tick=3))
|
|
111
|
+
session._dispatch(V1, Log("a:bad", message="again", line=4, tick=5))
|
|
112
|
+
out = tmp_path / "results.xml"
|
|
113
|
+
write_junit(session, out)
|
|
114
|
+
|
|
115
|
+
cases = {case.get("name"): case for case in fromstring(out.read_text("utf-8"))[0]}
|
|
116
|
+
output = find(cases["a:bad"], "system-out").text
|
|
117
|
+
assert output == "line 2, tick 3: hello\nline 4, tick 5: again\n"
|
|
118
|
+
assert cases["a:good"].find("system-out") is None
|
|
119
|
+
|
|
107
120
|
def test_aborted_version_becomes_an_error(self, tmp_path: Path) -> None:
|
|
108
121
|
session = Session([V1])
|
|
109
122
|
session._dispatch(V1, StreamError("server died"))
|
|
@@ -155,6 +168,18 @@ class TestWriteCoverageReports:
|
|
|
155
168
|
# The run summary carries the failing test
|
|
156
169
|
assert "a:bad" in page and "boom" in page
|
|
157
170
|
|
|
171
|
+
def test_html_lists_the_logs_of_a_failure(self, tmp_path: Path) -> None:
|
|
172
|
+
pack = self.make_pack(tmp_path)
|
|
173
|
+
session = self.coverage_session(V1)
|
|
174
|
+
session._dispatch(V1, Log("a:bad", message="<state>", line=2, tick=3))
|
|
175
|
+
session._dispatch(V1, Log("a:good", message="quiet", line=1, tick=0))
|
|
176
|
+
|
|
177
|
+
specs = [("html", tmp_path / "cov.html")]
|
|
178
|
+
write_coverage_reports(session, resolved(session, pack), specs)
|
|
179
|
+
page = (tmp_path / "cov.html").read_text(encoding="utf-8")
|
|
180
|
+
assert '<ul class="logs"><li><state> <span>(line 2, tick 3)</span></li></ul>' in page
|
|
181
|
+
assert "quiet" not in page
|
|
182
|
+
|
|
158
183
|
def test_html_tints_continuation_lines(self, tmp_path: Path) -> None:
|
|
159
184
|
folder = tmp_path / "pack" / "data" / "demo" / "function"
|
|
160
185
|
folder.mkdir(parents=True)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|