@@ -630,15 +630,7 @@ def test_get_manager_dependency_name(dependency, expected_name):
630
630
(True , [{compilesketches .CompileSketches .dependency_source_path_key : pathlib .Path ("Foo" )}])]
631
631
)
632
632
def test_install_platforms_from_path (capsys , mocker , path_exists , platform_list ):
633
- class PlatformInstallationPath :
634
- def __init__ (self ):
635
- self .parent = pathlib .PurePath ()
636
- self .name = pathlib .PurePath ()
637
-
638
- platform_installation_path = PlatformInstallationPath ()
639
- platform_installation_path .base = pathlib .Path ("/foo/PlatformInstallationPathParent" )
640
- platform_installation_path .platform = pathlib .Path ("PlatformInstallationPathName" )
641
- symlink_source_path = pathlib .Path ("/foo/SymlinkSourcePath" )
633
+ platform_installation_path = pathlib .Path ("/foo/PlatformInstallationPathParent/PlatformInstallationPathName" )
642
634
643
635
compile_sketches = get_compilesketches_object ()
644
636
@@ -647,7 +639,6 @@ def __init__(self):
647
639
autospec = True ,
648
640
return_value = platform_installation_path )
649
641
mocker .patch .object (pathlib .Path , "mkdir" , autospec = True )
650
- mocker .patch .object (pathlib .Path , "joinpath" , autospec = True , return_value = symlink_source_path )
651
642
mocker .patch .object (pathlib .Path , "symlink_to" , autospec = True )
652
643
653
644
if not path_exists :
@@ -664,17 +655,14 @@ def __init__(self):
664
655
compile_sketches .install_platforms_from_path (platform_list = platform_list )
665
656
666
657
get_platform_installation_path_calls = []
667
- joinpath_calls = []
668
658
mkdir_calls = []
669
659
symlink_to_calls = []
670
660
for platform in platform_list :
671
661
get_platform_installation_path_calls .append (unittest .mock .call (compile_sketches , platform = platform ))
672
- mkdir_calls .append (unittest .mock .call (platform_installation_path .base , parents = True , exist_ok = True ))
673
- joinpath_calls .append (unittest .mock .call (platform_installation_path .base ,
674
- platform_installation_path .platform ))
662
+ mkdir_calls .append (unittest .mock .call (platform_installation_path .parent , parents = True , exist_ok = True ))
675
663
symlink_to_calls .append (
676
664
unittest .mock .call (
677
- symlink_source_path ,
665
+ platform_installation_path ,
678
666
target = compilesketches .absolute_path (
679
667
platform [compilesketches .CompileSketches .dependency_source_path_key ]
680
668
),
@@ -684,35 +672,29 @@ def __init__(self):
684
672
685
673
# noinspection PyUnresolvedReferences
686
674
pathlib .Path .mkdir .assert_has_calls (calls = mkdir_calls )
687
- # noinspection PyUnresolvedReferences
688
- pathlib .Path .joinpath .assert_has_calls (calls = joinpath_calls )
689
675
pathlib .Path .symlink_to .assert_has_calls (calls = symlink_to_calls )
690
676
691
677
692
678
@pytest .mark .parametrize (
693
679
"platform,"
694
680
"command_data_stdout,"
695
- "expected_installation_path_base,"
696
- "expected_installation_path_platform,"
681
+ "expected_installation_path,"
697
682
"expected_rmtree" ,
698
683
# No match to previously installed platforms
699
684
[({compilesketches .CompileSketches .dependency_name_key : "foo:bar" },
700
685
"[{\" ID\" : \" asdf:zxcv\" }]" ,
701
- pathlib .PurePath ("/foo/UserPlatformsPath" ),
702
- pathlib .PurePath ("foo/bar" ),
686
+ pathlib .PurePath ("/foo/UserPlatformsPath/foo/bar" ),
703
687
False ),
704
688
# Match with previously installed platform
705
689
({compilesketches .CompileSketches .dependency_name_key : "foo:bar" },
706
690
"[{\" ID\" : \" foo:bar\" , \" Installed\" : \" 1.2.3\" }]" ,
707
- pathlib .PurePath ("/foo/BoardManagerPlatformsPath" ),
708
- pathlib .PurePath ("foo/hardware/bar/1.2.3" ),
691
+ pathlib .PurePath ("/foo/BoardManagerPlatformsPath/foo/hardware/bar/1.2.3" ),
709
692
True )]
710
693
)
711
694
def test_get_platform_installation_path (mocker ,
712
695
platform ,
713
696
command_data_stdout ,
714
- expected_installation_path_base ,
715
- expected_installation_path_platform ,
697
+ expected_installation_path ,
716
698
expected_rmtree ):
717
699
class CommandData :
718
700
def __init__ (self , stdout ):
@@ -728,8 +710,7 @@ def __init__(self, stdout):
728
710
compile_sketches .board_manager_platforms_path = pathlib .PurePath ("/foo/BoardManagerPlatformsPath" )
729
711
730
712
platform_installation_path = compile_sketches .get_platform_installation_path (platform = platform )
731
- assert platform_installation_path .base == expected_installation_path_base
732
- assert platform_installation_path .platform == expected_installation_path_platform
713
+ assert platform_installation_path == expected_installation_path
733
714
734
715
run_arduino_cli_command_calls = [unittest .mock .call (compile_sketches , command = ["core" , "update-index" ]),
735
716
unittest .mock .call (compile_sketches , command = ["core" , "list" , "--format" , "json" ])]
@@ -739,7 +720,7 @@ def __init__(self, stdout):
739
720
if expected_rmtree is True :
740
721
# noinspection PyUnresolvedReferences
741
722
shutil .rmtree .assert_called_once_with (
742
- path = platform_installation_path . base . joinpath ( platform_installation_path . platform )
723
+ path = platform_installation_path
743
724
)
744
725
else :
745
726
# noinspection PyUnresolvedReferences
@@ -756,14 +737,7 @@ def test_install_platforms_from_repository(mocker):
756
737
757
738
git_ref = unittest .mock .sentinel .git_ref
758
739
759
- class PlatformInstallationPath :
760
- def __init__ (self ):
761
- self .base = pathlib .PurePath ()
762
- self .platform = pathlib .PurePath ()
763
-
764
- platform_installation_path = PlatformInstallationPath ()
765
- platform_installation_path .base = pathlib .Path ("/foo/PlatformInstallationPathParent" )
766
- platform_installation_path .platform = pathlib .Path ("PlatformInstallationPathName" )
740
+ platform_installation_path = pathlib .Path ("/foo/PlatformInstallationPathParent/PlatformInstallationPathName" )
767
741
768
742
expected_source_path_list = [unittest .mock .sentinel .source_path , "." ]
769
743
expected_destination_name_list = [unittest .mock .sentinel .destination_name , None ]
@@ -791,8 +765,8 @@ def __init__(self):
791
765
url = platform [compilesketches .CompileSketches .dependency_source_url_key ],
792
766
git_ref = git_ref ,
793
767
source_path = expected_source_path ,
794
- destination_parent_path = platform_installation_path .base ,
795
- destination_name = platform_installation_path .platform )
768
+ destination_parent_path = platform_installation_path .parent ,
769
+ destination_name = platform_installation_path .name )
796
770
)
797
771
798
772
compile_sketches .get_repository_dependency_ref .assert_has_calls (calls = get_repository_dependency_ref_calls )
@@ -817,14 +791,7 @@ def test_install_platforms_from_download(mocker):
817
791
{compilesketches .CompileSketches .dependency_source_url_key : unittest .mock .sentinel .source_url2 }
818
792
]
819
793
820
- class PlatformInstallationPath :
821
- def __init__ (self ):
822
- self .base = pathlib .PurePath ()
823
- self .platform = pathlib .PurePath ()
824
-
825
- platform_installation_path = PlatformInstallationPath ()
826
- platform_installation_path .parent = pathlib .Path ("/foo/PlatformInstallationPathParent" )
827
- platform_installation_path .name = pathlib .Path ("PlatformInstallationPathName" )
794
+ platform_installation_path = pathlib .Path ("/foo/PlatformInstallationPathParent/PlatformInstallationPathName" )
828
795
829
796
expected_source_path_list = [unittest .mock .sentinel .source_path , "." ]
830
797
@@ -844,8 +811,8 @@ def __init__(self):
844
811
install_platforms_from_download_calls .append (
845
812
unittest .mock .call (url = platform [compilesketches .CompileSketches .dependency_source_url_key ],
846
813
source_path = expected_source_path ,
847
- destination_parent_path = platform_installation_path .base ,
848
- destination_name = platform_installation_path .platform )
814
+ destination_parent_path = platform_installation_path .parent ,
815
+ destination_name = platform_installation_path .name )
849
816
)
850
817
compilesketches .install_from_download .assert_has_calls (calls = install_platforms_from_download_calls )
851
818
0 commit comments