@@ -1324,7 +1324,7 @@ def test_apply_patch(self):
13241324 self .assertErrorRegex (EasyBuildError , "Couldn't apply patch file" , ft .apply_patch , toy_patch , path )
13251325
13261326 def test_copy_file (self ):
1327- """ Test copy_file """
1327+ """Test copy_file function. """
13281328 testdir = os .path .dirname (os .path .abspath (__file__ ))
13291329 to_copy = os .path .join (testdir , 'easyconfigs' , 'test_ecs' , 't' , 'toy' , 'toy-0.0.eb' )
13301330 target_path = os .path .join (self .test_prefix , 'toy.eb' )
@@ -1385,8 +1385,44 @@ def test_copy_file(self):
13851385 self .assertTrue (ft .read_file (to_copy ) == ft .read_file (target_path ))
13861386 self .assertEqual (txt , '' )
13871387
1388+ def test_copy_files (self ):
1389+ """Test copy_files function."""
1390+ test_ecs = os .path .join (os .path .dirname (os .path .abspath (__file__ )), 'easyconfigs' , 'test_ecs' )
1391+ toy_ec = os .path .join (test_ecs , 't' , 'toy' , 'toy-0.0.eb' )
1392+ toy_ec_txt = ft .read_file (toy_ec )
1393+ bzip2_ec = os .path .join (test_ecs , 'b' , 'bzip2' , 'bzip2-1.0.6-GCC-4.9.2.eb' )
1394+ bzip2_ec_txt = ft .read_file (bzip2_ec )
1395+
1396+ # copying a single file to a non-existing directory
1397+ target_dir = os .path .join (self .test_prefix , 'target_dir1' )
1398+ ft .copy_files ([toy_ec ], target_dir )
1399+ copied_toy_ec = os .path .join (target_dir , 'toy-0.0.eb' )
1400+ self .assertTrue (os .path .exists (copied_toy_ec ))
1401+ self .assertEqual (ft .read_file (copied_toy_ec ), toy_ec_txt )
1402+
1403+ # copying a single file to an existing directory
1404+ ft .copy_files ([bzip2_ec ], target_dir )
1405+ copied_bzip2_ec = os .path .join (target_dir , 'bzip2-1.0.6-GCC-4.9.2.eb' )
1406+ self .assertTrue (os .path .exists (copied_bzip2_ec ))
1407+ self .assertEqual (ft .read_file (copied_bzip2_ec ), bzip2_ec_txt )
1408+
1409+ # copying multiple files to a non-existing directory
1410+ target_dir = os .path .join (self .test_prefix , 'target_dir_multiple' )
1411+ ft .copy_files ([toy_ec , bzip2_ec ], target_dir )
1412+ copied_toy_ec = os .path .join (target_dir , 'toy-0.0.eb' )
1413+ self .assertTrue (os .path .exists (copied_toy_ec ))
1414+ self .assertEqual (ft .read_file (copied_toy_ec ), toy_ec_txt )
1415+ copied_bzip2_ec = os .path .join (target_dir , 'bzip2-1.0.6-GCC-4.9.2.eb' )
1416+ self .assertTrue (os .path .exists (copied_bzip2_ec ))
1417+ self .assertEqual (ft .read_file (copied_bzip2_ec ), bzip2_ec_txt )
1418+
1419+ # copying files to an existing target that is not a directory results in an error
1420+ self .assertTrue (os .path .isfile (copied_toy_ec ))
1421+ error_pattern = "/toy-0.0.eb exists but is not a directory"
1422+ self .assertErrorRegex (EasyBuildError , error_pattern , ft .copy_files , [bzip2_ec ], copied_toy_ec )
1423+
13881424 def test_copy_dir (self ):
1389- """Test copy_file """
1425+ """Test copy_dir function. """
13901426 testdir = os .path .dirname (os .path .abspath (__file__ ))
13911427 to_copy = os .path .join (testdir , 'easyconfigs' , 'test_ecs' , 'g' , 'GCC' )
13921428
0 commit comments