@@ -90,6 +90,69 @@ def test_must_delete_if_path_exist(self, patched_rmtree, patched_path):
9090 patched_rmtree .assert_called_with (mock_path_obj )
9191
9292
93+ class Test_copytree (TestCase ):
94+ @patch ("samcli.lib.utils.osutils.Path" )
95+ @patch ("samcli.lib.utils.osutils.os" )
96+ @patch ("samcli.lib.utils.osutils.shutil.copy2" )
97+ def test_must_copytree (self , patched_copy2 , patched_os , patched_path ):
98+ source_path = "mock-source/path"
99+ destination_path = "mock-destination/path"
100+ mock_path_obj = Mock ()
101+ patched_path .exists .return_value = True
102+ patched_os .path .return_value = mock_path_obj
103+
104+ patched_os .path .join .side_effect = [source_path , destination_path ]
105+ patched_os .path .isdir .return_value = False
106+ patched_os .listdir .return_value = ["mock-source-file1" ]
107+ osutils .copytree (source_path , destination_path )
108+
109+ patched_os .path .join .assert_called ()
110+ patched_copy2 .assert_called_with (source_path , destination_path )
111+
112+ @patch ("samcli.lib.utils.osutils.Path" )
113+ @patch ("samcli.lib.utils.osutils.os" )
114+ @patch ("samcli.lib.utils.osutils.shutil.copy2" )
115+ def test_copytree_throws_oserror_path_exists (self , patched_copy2 , patched_os , patched_path ):
116+ source_path = "mock-source/path"
117+ destination_path = "mock-destination/path"
118+ mock_path_obj = Mock ()
119+ patched_path .exists .return_value = True
120+ patched_os .path .return_value = mock_path_obj
121+ patched_copy2 .side_effect = OSError ("mock-os-error" )
122+
123+ patched_os .path .join .side_effect = [source_path , destination_path ]
124+ patched_os .path .isdir .return_value = False
125+ patched_os .listdir .return_value = ["mock-source-file1" ]
126+ with self .assertRaises (OSError ):
127+ osutils .copytree (source_path , destination_path )
128+
129+ patched_os .path .join .assert_called ()
130+ patched_copy2 .assert_called_with (source_path , destination_path )
131+
132+ @patch ("samcli.lib.utils.osutils.create_symlink_or_copy" )
133+ @patch ("samcli.lib.utils.osutils.Path" )
134+ @patch ("samcli.lib.utils.osutils.os" )
135+ @patch ("samcli.lib.utils.osutils.shutil.copy2" )
136+ def test_copytree_symlink_copy_error_handling (
137+ self , patched_copy2 , patched_os , patched_path , patched_create_symlink_or_copy
138+ ):
139+ source_path = "mock-source/path"
140+ destination_path = "mock-destination/path"
141+ mock_path_obj = Mock ()
142+ patched_path .exists .return_value = True
143+ patched_os .path .return_value = mock_path_obj
144+ patched_copy2 .side_effect = OSError (22 , "mock-os-error" )
145+
146+ patched_os .path .join .side_effect = [source_path , destination_path ]
147+ patched_os .path .isdir .return_value = False
148+ patched_os .listdir .return_value = ["mock-source-file1" ]
149+ osutils .copytree (source_path , destination_path )
150+
151+ patched_os .path .join .assert_called ()
152+ patched_copy2 .assert_called_with (source_path , destination_path )
153+ patched_create_symlink_or_copy .assert_called_with (source_path , destination_path )
154+
155+
93156class Test_create_symlink_or_copy (TestCase ):
94157 @patch ("samcli.lib.utils.osutils.Path" )
95158 @patch ("samcli.lib.utils.osutils.os" )
0 commit comments