Skip to content

Commit 363fbd5

Browse files
author
Massimiliano Pippi
committed
added integration tests for log format
1 parent 9e6371a commit 363fbd5

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/test_main.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
# otherwise use the software for commercial activities involving the Arduino
1313
# software without disclosing the source code of your own applications. To purchase
1414
# a commercial license, send an email to [email protected].
15+
import os
1516
import json
17+
1618
import semver
1719

1820

@@ -36,3 +38,37 @@ def test_version(run_command):
3638
assert parsed_out.get("Application", False) == "arduino-cli"
3739
assert isinstance(semver.parse(parsed_out.get("VersionString", False)), dict)
3840
assert isinstance(parsed_out.get("Commit", False), str)
41+
42+
43+
def test_log_options(run_command, data_dir):
44+
"""
45+
using `version` as a test command
46+
"""
47+
48+
# no logs
49+
out_lines = run_command("version").stdout.strip().split("\n")
50+
assert len(out_lines) == 1
51+
52+
# plain text logs on stdoud
53+
out_lines = run_command("version -v").stdout.strip().split("\n")
54+
assert len(out_lines) > 1
55+
assert out_lines[0].startswith("\x1b[36mINFO\x1b[0m") # account for the colors
56+
57+
# plain text logs on file
58+
log_file = os.path.join(data_dir, "log.txt")
59+
run_command("version --log-file " + log_file)
60+
with open(log_file) as f:
61+
lines = f.readlines()
62+
assert lines[0].startswith('time="') # file format is different from console
63+
64+
# json on stdout
65+
out_lines = run_command("version -v --log-format JSON").stdout.strip().split("\n")
66+
lg = json.loads(out_lines[0])
67+
assert "level" in lg
68+
69+
# json on file
70+
log_file = os.path.join(data_dir, "log.json")
71+
run_command("version --log-format json --log-file " + log_file)
72+
with open(log_file) as f:
73+
for line in f.readlines():
74+
json.loads(line)

0 commit comments

Comments
 (0)