15
15
import compilesketches
16
16
import reportsizetrends
17
17
18
+ test_data_path = pathlib .PurePath (os .path .dirname (os .path .realpath (__file__ )), "testdata" )
19
+
18
20
19
21
def get_compilesketches_object (
20
22
cli_version = unittest .mock .sentinel .cli_version ,
@@ -256,8 +258,7 @@ def test_compile_sketches(mocker, compilation_success_list, expected_success, do
256
258
def test_install_arduino_cli (tmpdir , mocker ):
257
259
cli_version = "1.2.3"
258
260
arduino_cli_user_directory_path = pathlib .PurePath ("/foo/arduino_cli_user_directory_path" )
259
- source_file_path = pathlib .PurePath (os .path .dirname (os .path .realpath (__file__ )),
260
- "testdata" , "githubevent.json" )
261
+ source_file_path = test_data_path .joinpath ("githubevent.json" )
261
262
# Create temporary folder
262
263
arduino_cli_installation_path = pathlib .PurePath (tmpdir .mkdir ("test_install_arduino_cli" ))
263
264
output_archive_path = arduino_cli_installation_path .joinpath ("foo_archive.tar.gz" )
@@ -580,8 +581,7 @@ def test_find_sketches(capsys, monkeypatch):
580
581
581
582
# Test sketch path doesn't exist
582
583
compile_sketches = get_compilesketches_object (
583
- sketch_paths = "\' \" " + os .path .dirname (os .path .realpath (__file__ ))
584
- + "/testdata/HasSketches\" \" " + nonexistent_sketch_path + "\" \' "
584
+ sketch_paths = "\' \" " + nonexistent_sketch_path + "\" \' "
585
585
)
586
586
with pytest .raises (expected_exception = SystemExit , match = "1" ):
587
587
compile_sketches .find_sketches ()
@@ -590,76 +590,64 @@ def test_find_sketches(capsys, monkeypatch):
590
590
591
591
# Test sketch path is a sketch file
592
592
compile_sketches = get_compilesketches_object (
593
- sketch_paths = "\" " + os . path . dirname ( os . path . realpath ( __file__ )) + "/testdata/HasSketches/ Sketch1/Sketch1 .ino\" "
593
+ sketch_paths = "\" " + str ( test_data_path . joinpath ( "HasSketches" , "Sketch1" , " Sketch1.ino" )) + " \" "
594
594
)
595
595
assert compile_sketches .find_sketches () == [
596
- pathlib . Path ( os . path . dirname ( os . path . realpath ( __file__ )), "testdata" , "HasSketches" , "Sketch1" )
596
+ test_data_path . joinpath ( "HasSketches" , "Sketch1" )
597
597
]
598
598
599
599
# Test sketch path is a non-sketch file
600
- non_sketch_path = os . path . dirname ( os . path . realpath ( __file__ )) + "/testdata/NoSketches/ NotSketch/NotSketch .foo"
600
+ non_sketch_path = str ( test_data_path . joinpath ( "NoSketches" , "NotSketch" , " NotSketch.foo"))
601
601
compile_sketches = get_compilesketches_object (sketch_paths = "\" " + non_sketch_path + "\" " )
602
602
with pytest .raises (expected_exception = SystemExit , match = "1" ):
603
603
compile_sketches .find_sketches ()
604
- assert capsys .readouterr ().out .strip () == ("::error::Sketch path: " + str (pathlib .PurePath (non_sketch_path ))
605
- + " is not a sketch" )
604
+ assert capsys .readouterr ().out .strip () == ("::error::Sketch path: " + non_sketch_path + " is not a sketch" )
606
605
607
606
# Test sketch path is a sketch folder
608
607
compile_sketches = get_compilesketches_object (
609
- sketch_paths = "\" " + os . path . dirname ( os . path . realpath ( __file__ )) + "/testdata/HasSketches/Sketch1 \" "
608
+ sketch_paths = "\" " + str ( test_data_path . joinpath ( "HasSketches" , "Sketch1" )) + "\" "
610
609
)
611
610
assert compile_sketches .find_sketches () == [
612
- pathlib . Path ( os . path . dirname ( os . path . realpath ( __file__ )), "testdata" , "HasSketches" , "Sketch1" )
611
+ test_data_path . joinpath ( "HasSketches" , "Sketch1" )
613
612
]
614
613
615
614
# Test sketch path does contain sketches
616
615
compile_sketches = get_compilesketches_object (
617
- sketch_paths = "\" " + os . path . dirname ( os . path . realpath ( __file__ )) + "/testdata/HasSketches \" " )
616
+ sketch_paths = "\" " + str ( test_data_path . joinpath ( "HasSketches" )) + "\" " )
618
617
assert compile_sketches .find_sketches () == [
619
- pathlib . Path ( os . path . dirname ( os . path . realpath ( __file__ )), "testdata" , "HasSketches" , "Sketch1" ),
620
- pathlib . Path ( os . path . dirname ( os . path . realpath ( __file__ )), "testdata" , "HasSketches" , "Sketch2" )
618
+ test_data_path . joinpath ( "HasSketches" , "Sketch1" ),
619
+ test_data_path . joinpath ( "HasSketches" , "Sketch2" )
621
620
]
622
621
623
622
# Test sketch path doesn't contain any sketches
624
- no_sketches_path = os . path . dirname ( os . path . realpath ( __file__ )) + "/testdata/ NoSketches"
623
+ no_sketches_path = str ( test_data_path . joinpath ( " NoSketches"))
625
624
compile_sketches = get_compilesketches_object (
626
625
sketch_paths = "\" " + no_sketches_path + "\" " )
627
626
with pytest .raises (expected_exception = SystemExit , match = "1" ):
628
627
compile_sketches .find_sketches ()
629
628
assert capsys .readouterr ().out .strip () == ("::error::No sketches were found in "
630
- + str ( pathlib . PurePath ( no_sketches_path )) )
629
+ + no_sketches_path )
631
630
632
631
633
632
def test_path_is_sketch ():
634
633
# Sketch file
635
- assert compilesketches .path_is_sketch (
636
- path = pathlib .Path (os .path .dirname (os .path .realpath (__file__ )),
637
- "testdata" ,
638
- "HasSketches" ,
639
- "Sketch1" ,
640
- "Sketch1.ino" )
641
- ) is True
634
+ assert compilesketches .path_is_sketch (path = test_data_path .joinpath ("HasSketches" , "Sketch1" , "Sketch1.ino" )) is True
642
635
643
636
# Not a sketch file
644
637
assert compilesketches .path_is_sketch (
645
- path = pathlib .Path (os .path .dirname (os .path .realpath (__file__ )),
646
- "testdata" ,
647
- "NoSketches" ,
648
- "NotSketch" ,
649
- "NotSketch.foo" )
650
- ) is False
638
+ path = test_data_path .joinpath ("NoSketches" , "NotSketch" , "NotSketch.foo" )) is False
651
639
652
640
# Sketch folder
653
641
assert compilesketches .path_is_sketch (
654
- path = pathlib . Path ( os . path . dirname ( os . path . realpath ( __file__ )), "testdata" , "HasSketches" , "Sketch1" )) is True
642
+ path = test_data_path . joinpath ( "HasSketches" , "Sketch1" )) is True
655
643
656
644
# No files in path
657
645
assert compilesketches .path_is_sketch (
658
- path = pathlib . Path ( os . path . dirname ( os . path . realpath ( __file__ )), "testdata" , "HasSketches" )) is False
646
+ path = test_data_path . joinpath ( "HasSketches" )) is False
659
647
660
648
# Not a sketch folder
661
649
assert compilesketches .path_is_sketch (
662
- path = pathlib . Path ( os . path . dirname ( os . path . realpath ( __file__ )), "testdata" , "NoSketches" , "NotSketch" )) is False
650
+ path = test_data_path . joinpath ( "NoSketches" , "NotSketch" )) is False
663
651
664
652
665
653
@pytest .mark .parametrize ("returncode, expected_success" , [(1 , False ),
@@ -943,7 +931,7 @@ def get_pull(self):
943
931
944
932
monkeypatch .setenv ("GITHUB_REPOSITORY" , "fooRepository/fooOwner" )
945
933
monkeypatch .setenv ("GITHUB_WORKSPACE" , "/fooWorkspace" )
946
- monkeypatch .setenv ("GITHUB_EVENT_PATH" , os . path . dirname ( os . path . realpath ( __file__ )) + "/testdata/ githubevent.json" )
934
+ monkeypatch .setenv ("GITHUB_EVENT_PATH" , str ( test_data_path . joinpath ( " githubevent.json")) )
947
935
948
936
compile_sketches = get_compilesketches_object ()
949
937
0 commit comments