12
12
# otherwise use the software for commercial activities involving the Arduino
13
13
# software without disclosing the source code of your own applications. To purchase
14
14
# a commercial license, send an email to [email protected] .
15
+ import os
15
16
import json
17
+
16
18
import semver
17
19
18
20
@@ -36,3 +38,37 @@ def test_version(run_command):
36
38
assert parsed_out .get ("Application" , False ) == "arduino-cli"
37
39
assert isinstance (semver .parse (parsed_out .get ("VersionString" , False )), dict )
38
40
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