16
16
import shutil
17
17
from pathlib import Path
18
18
19
+ from invoke .context import Context
19
20
import pytest
20
21
21
22
@@ -28,15 +29,37 @@ def copy_sketch(working_dir):
28
29
yield str (test_sketch_path )
29
30
30
31
31
- def test_archive_no_args (run_command , copy_sketch , working_dir ):
32
- result = run_command ("echo %cd%" , copy_sketch )
33
- print (result .stdout )
34
- print (result .stderr )
35
-
36
- result = run_command ("dir" , copy_sketch )
32
+ @pytest .fixture (scope = "function" )
33
+ def run_simple (pytestconfig , data_dir , downloads_dir , working_dir ):
34
+ """
35
+ Provide a wrapper around invoke's `run` API so that every test
36
+ will work in the same temporary folder.
37
+
38
+ Useful reference:
39
+ http://docs.pyinvoke.org/en/1.4/api/runners.html#invoke.runners.Result
40
+ """
41
+
42
+ env = {
43
+ "ARDUINO_DATA_DIR" : data_dir ,
44
+ "ARDUINO_DOWNLOADS_DIR" : downloads_dir ,
45
+ "ARDUINO_SKETCHBOOK_DIR" : data_dir ,
46
+ }
47
+
48
+ def _run (cmd_string , custom_working_dir ):
49
+ run_context = Context ()
50
+ # Context.cd() is not used since it doesn't work correctly on Windows.
51
+ # It escapes spaces in the path using "\ " but it doesn't always work,
52
+ # wrapping the path in quotation marks is the safest approach
53
+ with run_context .prefix (f'cd "{ custom_working_dir } "' ):
54
+ return run_context .run (cmd_string , echo = False , hide = True , warn = True , env = env )
55
+
56
+ return _run
57
+
58
+
59
+ def test_archive_no_args (run_simple , run_command , copy_sketch , working_dir ):
60
+ result = run_simple ("dir" , copy_sketch )
37
61
print (result .stdout )
38
62
print (result .stderr )
39
-
40
63
result = run_command ("archive" , copy_sketch )
41
64
print (result .stdout )
42
65
print (result .stderr )
0 commit comments