@@ -247,3 +247,64 @@ def test_copy_directory_error(self):
247247 source .copy (destination )
248248
249249 self .assertTrue (destination .is_dir ())
250+
251+ def test_copytree (self ):
252+ with tempfile .TemporaryDirectory () as directory :
253+ source = ResourcePath ("Packages/test_package" )
254+ destination = Path (directory ) / 'tree'
255+
256+ source .copytree (destination )
257+
258+ self .assertEqual (
259+ {
260+ path .relative_to (destination ).parts
261+ for path in destination .rglob ('*' )
262+ if path .is_file ()
263+ },
264+ {
265+ path .relative_to (source )
266+ for path in source .rglob ('*' )
267+ }
268+ )
269+
270+ def test_copytree_exists_error (self ):
271+ with tempfile .TemporaryDirectory () as directory :
272+ source = ResourcePath ("Packages/test_package" )
273+ destination = Path (directory ) / 'tree'
274+ destination .mkdir ()
275+
276+ with self .assertRaises (FileExistsError ):
277+ source .copytree (destination )
278+
279+ def test_copytree_exists (self ):
280+ with tempfile .TemporaryDirectory () as directory :
281+ source = ResourcePath ("Packages/test_package" )
282+ destination = Path (directory ) / 'tree'
283+ destination .mkdir ()
284+
285+ helloworld_file = destination / 'helloworld.txt'
286+
287+ with open (str (helloworld_file ), 'w' ) as file :
288+ file .write ("Nothing to see here.\n " )
289+
290+ source .copytree (destination , exist_ok = True )
291+
292+ self .assertEqual (
293+ {
294+ path .relative_to (destination ).parts
295+ for path in destination .rglob ('*' )
296+ if path .is_file ()
297+ },
298+ {
299+ path .relative_to (source )
300+ for path in source .rglob ('*' )
301+ }
302+ )
303+
304+ with open (str (helloworld_file )) as file :
305+ helloworld_contents = file .read ()
306+
307+ self .assertEqual (
308+ helloworld_contents ,
309+ (source / 'helloworld.txt' ).read_text ()
310+ )
0 commit comments