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
15
from pathlib import Path
16
+ import json
16
17
17
18
18
19
def test_init (run_command , data_dir , working_dir ):
@@ -21,8 +22,117 @@ def test_init(run_command, data_dir, working_dir):
21
22
assert data_dir in result .stdout
22
23
23
24
24
- def test_init_dest (run_command , working_dir ):
25
- dest = str (Path (working_dir ) / "config" / "test" )
25
+ def test_init_dest_absolute_path (run_command , working_dir ):
26
+ dest = Path (working_dir ) / "config" / "test"
27
+ expected_config_file = dest / "arduino-cli.yaml"
28
+ assert not expected_config_file .exists ()
26
29
result = run_command (f'config init --dest-dir "{ dest } "' )
27
30
assert result .ok
28
- assert dest in result .stdout
31
+ assert str (expected_config_file ) in result .stdout
32
+ assert expected_config_file .exists ()
33
+
34
+
35
+ def test_init_dest_relative_path (run_command , working_dir ):
36
+ dest = Path (working_dir ) / "config" / "test"
37
+ expected_config_file = dest / "arduino-cli.yaml"
38
+ assert not expected_config_file .exists ()
39
+ result = run_command (f'config init --dest-dir "config/test"' )
40
+ assert result .ok
41
+ assert str (expected_config_file ) in result .stdout
42
+ assert expected_config_file .exists ()
43
+
44
+
45
+ def test_init_dest_flag_with_overwrite_flag (run_command , working_dir ):
46
+ dest = Path (working_dir ) / "config" / "test"
47
+
48
+ expected_config_file = dest / "arduino-cli.yaml"
49
+ assert not expected_config_file .exists ()
50
+
51
+ result = run_command (f'config init --dest-dir "{ dest } "' )
52
+ assert result .ok
53
+ assert expected_config_file .exists ()
54
+
55
+ result = run_command (f'config init --dest-dir "{ dest } "' )
56
+ assert result .failed
57
+ assert "Config file already exists, use --overwrite to discard the existing one." in result .stderr
58
+
59
+ result = run_command (f'config init --dest-dir "{ dest } " --overwrite' )
60
+ assert result .ok
61
+ assert str (expected_config_file ) in result .stdout
62
+
63
+
64
+ def test_init_dest_and_config_file_flags (run_command , working_dir ):
65
+ result = run_command (f'config init --config-file "some_other_path" --dest-dir "some_path"' )
66
+ assert result .failed
67
+ assert "Can't use both --config-file and --dest-dir flags at the same time." in result .stderr
68
+
69
+
70
+ def test_init_config_file_flag_absolute_path (run_command , working_dir ):
71
+ config_file = Path (working_dir ) / "config" / "test" / "config.yaml"
72
+ assert not config_file .exists ()
73
+ result = run_command (f'config init --config-file "{ config_file } "' )
74
+ assert result .ok
75
+ assert str (config_file ) in result .stdout
76
+ assert config_file .exists ()
77
+
78
+
79
+ def test_init_config_file_flag_relative_path (run_command , working_dir ):
80
+ config_file = Path (working_dir ) / "config.yaml"
81
+ assert not config_file .exists ()
82
+ result = run_command (f'config init --config-file "config.yaml"' )
83
+ assert result .ok
84
+ assert str (config_file ) in result .stdout
85
+ assert config_file .exists ()
86
+
87
+
88
+ def test_init_config_file_flag_with_overwrite_flag (run_command , working_dir ):
89
+ config_file = Path (working_dir ) / "config" / "test" / "config.yaml"
90
+ assert not config_file .exists ()
91
+
92
+ result = run_command (f'config init --config-file "{ config_file } "' )
93
+ assert result .ok
94
+ assert config_file .exists ()
95
+
96
+ result = run_command (f'config init --config-file "{ config_file } "' )
97
+ assert result .failed
98
+ assert "Config file already exists, use --overwrite to discard the existing one." in result .stderr
99
+
100
+ result = run_command (f'config init --config-file "{ config_file } " --overwrite' )
101
+ assert result .ok
102
+ assert str (config_file ) in result .stdout
103
+
104
+
105
+ def test_dump (run_command , working_dir ):
106
+ # Create a config file first
107
+ config_file = Path (working_dir ) / "config" / "test" / "config.yaml"
108
+ assert not config_file .exists ()
109
+ result = run_command (f'config init --config-file "{ config_file } "' )
110
+ assert result .ok
111
+ assert config_file .exists ()
112
+
113
+ result = run_command ("config dump --format json" )
114
+ assert result .ok
115
+ settings_json = json .loads (result .stdout )
116
+ assert [] == settings_json ["board_manager" ]["additional_urls" ]
117
+
118
+
119
+ def test_dump_with_config_file_flag (run_command , working_dir ):
120
+ # Create a config file first
121
+ config_file = Path (working_dir ) / "config" / "test" / "config.yaml"
122
+ assert not config_file .exists ()
123
+ result = run_command (f'config init --config-file "{ config_file } " --additional-urls=https://example.com' )
124
+ assert result .ok
125
+ assert config_file .exists ()
126
+
127
+ result = run_command (f'config dump --config-file "{ config_file } " --format json' )
128
+ assert result .ok
129
+ settings_json = json .loads (result .stdout )
130
+ assert ["https://example.com" ] == settings_json ["board_manager" ]["additional_urls" ]
131
+
132
+ result = run_command (
133
+ f'config dump --config-file "{ config_file } " --additional-urls=https://another-url.com --format json'
134
+ )
135
+ assert result .ok
136
+ settings_json = json .loads (result .stdout )
137
+ assert ["https://another-url.com" ] == settings_json ["board_manager" ]["additional_urls" ]
138
+
0 commit comments