14
14
15
15
import compilesketches
16
16
17
+ os .environ ["GITHUB_WORKSPACE" ] = "/foo/github-workspace"
18
+
17
19
test_data_path = pathlib .PurePath (os .path .dirname (os .path .realpath (__file__ )), "testdata" )
18
20
19
21
@@ -376,9 +378,7 @@ def test_get_fqbn_platform_dependency(fqbn_arg, expected_platform, expected_addi
376
378
([{compilesketches .CompileSketches .dependency_source_url_key : "git://example.com/foo/bar" }], ["repository" ]),
377
379
]
378
380
)
379
- def test_sort_dependency_list (monkeypatch , dependency_list , expected_dependency_type_list ):
380
- monkeypatch .setenv ("GITHUB_WORKSPACE" , "/foo/GitHubWorkspace" )
381
-
381
+ def test_sort_dependency_list (dependency_list , expected_dependency_type_list ):
382
382
compile_sketches = get_compilesketches_object ()
383
383
384
384
for dependency , expected_dependency_type in zip (dependency_list , expected_dependency_type_list ):
@@ -546,7 +546,7 @@ def test_get_manager_dependency_name(dependency, expected_name):
546
546
[(False , [{compilesketches .CompileSketches .dependency_source_path_key : pathlib .Path ("Foo" )}]),
547
547
(True , [{compilesketches .CompileSketches .dependency_source_path_key : pathlib .Path ("Foo" )}])]
548
548
)
549
- def test_install_platforms_from_path (capsys , monkeypatch , mocker , path_exists , platform_list ):
549
+ def test_install_platforms_from_path (capsys , mocker , path_exists , platform_list ):
550
550
class PlatformInstallationPath :
551
551
def __init__ (self ):
552
552
self .parent = pathlib .PurePath ()
@@ -557,8 +557,6 @@ def __init__(self):
557
557
platform_installation_path .platform = pathlib .Path ("PlatformInstallationPathName" )
558
558
symlink_source_path = pathlib .Path ("/foo/SymlinkSourcePath" )
559
559
560
- monkeypatch .setenv ("GITHUB_WORKSPACE" , "/foo/GitHubWorkspace" )
561
-
562
560
compile_sketches = get_compilesketches_object ()
563
561
564
562
mocker .patch .object (pathlib .Path , "exists" , autospec = True , return_value = path_exists )
@@ -771,30 +769,53 @@ def __init__(self):
771
769
772
770
@pytest .mark .parametrize (
773
771
"libraries, expected_manager, expected_path, expected_repository, expected_download" ,
774
- [("" , [], [{compilesketches .CompileSketches .dependency_source_path_key : pathlib .PurePath ("/foo/GitHubWorkspace" )}],
775
- [], []),
776
- ("foo bar" , [{compilesketches .CompileSketches .dependency_name_key : "foo" },
777
- {compilesketches .CompileSketches .dependency_name_key : "bar" }],
778
- [{compilesketches .CompileSketches .dependency_source_path_key : pathlib .PurePath ("/foo/GitHubWorkspace" )}], [], []),
779
- ("\" foo\" \" bar\" " , [{compilesketches .CompileSketches .dependency_name_key : "foo" },
780
- {compilesketches .CompileSketches .dependency_name_key : "bar" }],
781
- [{compilesketches .CompileSketches .dependency_source_path_key : pathlib .PurePath ("/foo/GitHubWorkspace" )}], [], []),
782
- ("-" , [], [], [], []),
772
+ [("" ,
773
+ [],
774
+ [{compilesketches .CompileSketches .dependency_source_path_key : pathlib .PurePath (os .environ ["GITHUB_WORKSPACE" ])}],
775
+ [],
776
+ []),
777
+ ("foo bar" ,
778
+ [{compilesketches .CompileSketches .dependency_name_key : "foo" },
779
+ {compilesketches .CompileSketches .dependency_name_key : "bar" }],
780
+ [{compilesketches .CompileSketches .dependency_source_path_key : pathlib .PurePath (os .environ ["GITHUB_WORKSPACE" ])}],
781
+ [],
782
+ []),
783
+ ("\" foo\" \" bar\" " ,
784
+ [{compilesketches .CompileSketches .dependency_name_key : "foo" },
785
+ {compilesketches .CompileSketches .dependency_name_key : "bar" }],
786
+ [{compilesketches .CompileSketches .dependency_source_path_key : pathlib .PurePath (os .environ ["GITHUB_WORKSPACE" ])}],
787
+ [],
788
+ []),
789
+ ("-" ,
790
+ [],
791
+ [],
792
+ [],
793
+ []),
783
794
("- " + compilesketches .CompileSketches .dependency_name_key + ": foo" ,
784
- [{compilesketches .CompileSketches .dependency_name_key : "foo" }], [], [], []),
785
- ("- " + compilesketches .CompileSketches .dependency_source_path_key + ": /foo/bar" , [],
786
- [{compilesketches .CompileSketches .dependency_source_path_key : "/foo/bar" }], [], []),
787
- ("- " + compilesketches .CompileSketches .dependency_source_url_key + ": https://example.com/foo.git" , [], [],
788
- [{"source-url" : "https://example.com/foo.git" }], []),
789
- ("- " + compilesketches .CompileSketches .dependency_source_url_key + ": https://example.com/foo.zip" , [], [], [],
795
+ [{compilesketches .CompileSketches .dependency_name_key : "foo" }],
796
+ [],
797
+ [],
798
+ []),
799
+ ("- " + compilesketches .CompileSketches .dependency_source_path_key + ": /foo/bar" ,
800
+ [],
801
+ [{compilesketches .CompileSketches .dependency_source_path_key : "/foo/bar" }],
802
+ [],
803
+ []),
804
+ ("- " + compilesketches .CompileSketches .dependency_source_url_key + ": https://example.com/foo.git" ,
805
+ [],
806
+ [],
807
+ [{"source-url" : "https://example.com/foo.git" }],
808
+ []),
809
+ ("- " + compilesketches .CompileSketches .dependency_source_url_key + ": https://example.com/foo.zip" ,
810
+ [],
811
+ [],
812
+ [],
790
813
[{"source-url" : "https://example.com/foo.zip" }])]
791
814
)
792
- def test_install_libraries (monkeypatch , mocker , libraries , expected_manager , expected_path , expected_repository ,
815
+ def test_install_libraries (mocker , libraries , expected_manager , expected_path , expected_repository ,
793
816
expected_download ):
794
817
libraries_path = pathlib .Path ("/foo/LibrariesPath" )
795
818
796
- monkeypatch .setenv ("GITHUB_WORKSPACE" , "/foo/GitHubWorkspace" )
797
-
798
819
compile_sketches = get_compilesketches_object (libraries = libraries )
799
820
compile_sketches .libraries_path = libraries_path
800
821
@@ -852,23 +873,27 @@ def test_install_libraries_from_library_manager(mocker):
852
873
enable_output = run_command_output_level )
853
874
854
875
855
- @pytest .mark .parametrize ("path_exists, library_list, expected_destination_name_list" ,
856
- [(False , [{compilesketches .CompileSketches .dependency_source_path_key : pathlib .Path (
857
- "/foo/GitHubWorkspace/Nonexistent" )}], []),
858
- (True , [{compilesketches .CompileSketches .dependency_destination_name_key : "FooName" ,
859
- compilesketches .CompileSketches .dependency_source_path_key : pathlib .Path (
860
- "/foo/GitHubWorkspace/FooLibrary" )}], ["FooName" ]),
861
- (True , [{compilesketches .CompileSketches .dependency_source_path_key : pathlib .Path (
862
- "/foo/GitHubWorkspace" )}], ["FooRepoName" ]),
863
- (True ,
864
- [{compilesketches .CompileSketches .dependency_source_path_key : pathlib .Path (
865
- "/foo/GitHubWorkspace/Bar" )}], ["Bar" ])])
876
+ @pytest .mark .parametrize (
877
+ "path_exists, library_list, expected_destination_name_list" ,
878
+ [(False ,
879
+ [{compilesketches .CompileSketches .dependency_source_path_key : os .environ ["GITHUB_WORKSPACE" ] + "/Nonexistent" }],
880
+ []),
881
+ (True ,
882
+ [{compilesketches .CompileSketches .dependency_destination_name_key : "FooName" ,
883
+ compilesketches .CompileSketches .dependency_source_path_key : os .environ ["GITHUB_WORKSPACE" ] + "/FooLibrary" }],
884
+ ["FooName" ]),
885
+ (True ,
886
+ [{compilesketches .CompileSketches .dependency_source_path_key : os .environ ["GITHUB_WORKSPACE" ]}],
887
+ ["FooRepoName" ]),
888
+ (True ,
889
+ [{compilesketches .CompileSketches .dependency_source_path_key : os .environ ["GITHUB_WORKSPACE" ] + "/Bar" }],
890
+ ["Bar" ])]
891
+ )
866
892
def test_install_libraries_from_path (capsys , monkeypatch , mocker , path_exists , library_list ,
867
893
expected_destination_name_list ):
868
894
libraries_path = pathlib .Path ("/foo/LibrariesPath" )
869
895
symlink_source_path = pathlib .Path ("/foo/SymlinkSourcePath" )
870
896
871
- monkeypatch .setenv ("GITHUB_WORKSPACE" , "/foo/GitHubWorkspace" )
872
897
monkeypatch .setenv ("GITHUB_REPOSITORY" , "foo/FooRepoName" )
873
898
874
899
compile_sketches = get_compilesketches_object ()
@@ -977,11 +1002,9 @@ def test_install_libraries_from_download(mocker):
977
1002
compilesketches .install_from_download .assert_has_calls (calls = install_libraries_from_download_calls )
978
1003
979
1004
980
- def test_find_sketches (capsys , monkeypatch ):
1005
+ def test_find_sketches (capsys ):
981
1006
nonexistent_sketch_path = "/foo/NonexistentSketch"
982
1007
983
- monkeypatch .setenv ("GITHUB_WORKSPACE" , "/foo/bar" )
984
-
985
1008
# Test sketch path doesn't exist
986
1009
compile_sketches = get_compilesketches_object (
987
1010
sketch_paths = "\' \" " + nonexistent_sketch_path + "\" \' "
@@ -1055,7 +1078,7 @@ def test_path_is_sketch():
1055
1078
1056
1079
@pytest .mark .parametrize ("returncode, expected_success" , [(1 , False ),
1057
1080
(0 , True )])
1058
- def test_compile_sketch (capsys , monkeypatch , mocker , returncode , expected_success ):
1081
+ def test_compile_sketch (capsys , mocker , returncode , expected_success ):
1059
1082
stdout = unittest .mock .sentinel .stdout
1060
1083
relative_sketch_path = pathlib .PurePath ("FooSketch" , "FooSketch.ino" )
1061
1084
@@ -1066,8 +1089,6 @@ class CompilationData:
1066
1089
CompilationData .returncode = returncode
1067
1090
CompilationData .stdout = stdout
1068
1091
1069
- monkeypatch .setenv ("GITHUB_WORKSPACE" , "/foo/bar" )
1070
-
1071
1092
compile_sketches = get_compilesketches_object ()
1072
1093
1073
1094
mocker .patch ("compilesketches.CompileSketches.run_arduino_cli_command" , autospec = True ,
@@ -1092,7 +1113,7 @@ class CompilationData:
1092
1113
1093
1114
1094
1115
@pytest .mark .parametrize ("do_size_deltas_report" , [True , False ])
1095
- def test_get_sketch_report (monkeypatch , mocker , do_size_deltas_report ):
1116
+ def test_get_sketch_report (mocker , do_size_deltas_report ):
1096
1117
original_git_ref = unittest .mock .sentinel .original_git_ref
1097
1118
sketch_report_list = [unittest .mock .sentinel .sketch_report_list1 , unittest .mock .sentinel .sketch_report_list2 ]
1098
1119
sketch = unittest .mock .sentinel .sketch
@@ -1119,8 +1140,6 @@ def __init__(self):
1119
1140
def checkout (self ):
1120
1141
pass
1121
1142
1122
- monkeypatch .setenv ("GITHUB_WORKSPACE" , "/foo/bar" )
1123
-
1124
1143
compile_sketches = get_compilesketches_object ()
1125
1144
1126
1145
mocker .patch ("compilesketches.CompileSketches.get_sketch_report_from_output" , autospec = True ,
@@ -1333,7 +1352,6 @@ def get_pull(self):
1333
1352
pass
1334
1353
1335
1354
monkeypatch .setenv ("GITHUB_REPOSITORY" , "fooRepository/fooOwner" )
1336
- monkeypatch .setenv ("GITHUB_WORKSPACE" , "/fooWorkspace" )
1337
1355
monkeypatch .setenv ("GITHUB_EVENT_PATH" , str (test_data_path .joinpath ("githubevent.json" )))
1338
1356
1339
1357
compile_sketches = get_compilesketches_object ()
@@ -1417,7 +1435,6 @@ def rev_parse(self):
1417
1435
pass
1418
1436
1419
1437
monkeypatch .setenv ("GITHUB_REPOSITORY" , "fooRepository/fooOwner" )
1420
- monkeypatch .setenv ("GITHUB_WORKSPACE" , "/fooWorkspace" )
1421
1438
1422
1439
sketches_report_path = tmp_path
1423
1440
fqbn_arg = "arduino:avr:uno"
@@ -1504,12 +1521,10 @@ def test_parse_boolean_input(boolean_input, expected_output):
1504
1521
1505
1522
@pytest .mark .parametrize ("path, expected_relative_path" ,
1506
1523
# Path under workspace
1507
- [("/fooWorkspace /baz" , pathlib .PurePath ("baz" )),
1524
+ [(os . environ [ "GITHUB_WORKSPACE" ] + " /baz" , pathlib .PurePath ("baz" )),
1508
1525
# Path outside workspace
1509
1526
("/bar/foo" , pathlib .Path ("/" ).resolve ().joinpath ("bar" , "foo" ))])
1510
- def test_path_relative_to_workspace (monkeypatch , path , expected_relative_path ):
1511
- monkeypatch .setenv ("GITHUB_WORKSPACE" , "/fooWorkspace" )
1512
-
1527
+ def test_path_relative_to_workspace (path , expected_relative_path ):
1513
1528
assert compilesketches .path_relative_to_workspace (path = path ) == expected_relative_path
1514
1529
assert compilesketches .path_relative_to_workspace (path = pathlib .PurePath (path )) == expected_relative_path
1515
1530
@@ -1518,15 +1533,13 @@ def test_path_relative_to_workspace(monkeypatch, path, expected_relative_path):
1518
1533
# Absolute path
1519
1534
[("/asdf" , pathlib .Path ("/" ).resolve ().joinpath ("asdf" )),
1520
1535
# Relative path
1521
- ("asdf" , pathlib .Path ("/" ).resolve ().joinpath ("fooWorkspace" , "asdf" )),
1536
+ ("asdf" , pathlib .Path (os . environ [ "GITHUB_WORKSPACE" ] ).resolve ().joinpath ("asdf" )),
1522
1537
# Use of ~
1523
1538
("~/foo" , pathlib .Path .home ().joinpath ("foo" )),
1524
1539
# Use of ..
1525
1540
("/foo/bar/../baz" , pathlib .Path ("/" ).resolve ().joinpath ("foo" , "baz" ))
1526
1541
])
1527
- def test_absolute_path (monkeypatch , path , expected_absolute_path ):
1528
- monkeypatch .setenv ("GITHUB_WORKSPACE" , "/fooWorkspace" )
1529
-
1542
+ def test_absolute_path (path , expected_absolute_path ):
1530
1543
assert compilesketches .absolute_path (path = path ) == expected_absolute_path
1531
1544
assert compilesketches .absolute_path (path = pathlib .PurePath (path )) == expected_absolute_path
1532
1545
@@ -1536,8 +1549,7 @@ def test_absolute_path(monkeypatch, path, expected_absolute_path):
1536
1549
[("foo/bar-relative-path" , pathlib .PurePath ("foo/bar-relative-path" )),
1537
1550
("/foo/bar-absolute-path" , pathlib .Path ("/" ).resolve ().joinpath ("foo" , "bar-absolute-path" ))]
1538
1551
)
1539
- def test_absolute_relative_path_conversion (monkeypatch , path , expected_path ):
1540
- monkeypatch .setenv ("GITHUB_WORKSPACE" , "/fooWorkspace" )
1552
+ def test_absolute_relative_path_conversion (path , expected_path ):
1541
1553
assert compilesketches .path_relative_to_workspace (
1542
1554
path = compilesketches .absolute_path (
1543
1555
path = path
0 commit comments