@@ -836,6 +836,16 @@ def test_show_ec(self):
836
836
def test_copy_ec (self ):
837
837
"""Test --copy-ec."""
838
838
839
+ def mocked_main (args ):
840
+ self .mock_stderr (True )
841
+ self .mock_stdout (True )
842
+ self .eb_main (args , raise_error = True )
843
+ stderr , stdout = self .get_stderr (), self .get_stdout ()
844
+ self .mock_stderr (False )
845
+ self .mock_stdout (False )
846
+ self .assertEqual (stderr , '' )
847
+ return stdout .strip ()
848
+
839
849
topdir = os .path .dirname (os .path .abspath (__file__ ))
840
850
test_easyconfigs_dir = os .path .join (topdir , 'easyconfigs' , 'test_ecs' )
841
851
@@ -845,7 +855,8 @@ def test_copy_ec(self):
845
855
# basic test: copying one easyconfig file to a non-existing absolute path
846
856
test_ec = os .path .join (self .test_prefix , 'test.eb' )
847
857
args = ['--copy-ec' , 'toy-0.0.eb' , test_ec ]
848
- self .eb_main (args )
858
+ stdout = mocked_main (args )
859
+ self .assertEqual (stdout , 'toy-0.0.eb copied to %s' % test_ec )
849
860
850
861
self .assertTrue (os .path .exists (test_ec ))
851
862
self .assertEqual (toy_ec_txt , read_file (test_ec ))
@@ -858,7 +869,8 @@ def test_copy_ec(self):
858
869
self .assertFalse (os .path .exists (target_fn ))
859
870
860
871
args = ['--copy-ec' , 'toy-0.0.eb' , target_fn ]
861
- self .eb_main (args )
872
+ stdout = mocked_main (args )
873
+ self .assertEqual (stdout , 'toy-0.0.eb copied to test.eb' )
862
874
863
875
change_dir (cwd )
864
876
@@ -869,7 +881,8 @@ def test_copy_ec(self):
869
881
test_target_dir = os .path .join (self .test_prefix , 'test_target_dir' )
870
882
mkdir (test_target_dir )
871
883
args = ['--copy-ec' , 'toy-0.0.eb' , test_target_dir ]
872
- self .eb_main (args )
884
+ stdout = mocked_main (args )
885
+ self .assertEqual (stdout , 'toy-0.0.eb copied to %s' % test_target_dir )
873
886
874
887
copied_toy_ec = os .path .join (test_target_dir , 'toy-0.0.eb' )
875
888
self .assertTrue (os .path .exists (copied_toy_ec ))
@@ -890,7 +903,8 @@ def check_copied_files():
890
903
891
904
# copying multiple easyconfig files to a non-existing target directory (which is created automatically)
892
905
args = ['--copy-ec' , 'toy-0.0.eb' , 'bzip2-1.0.6-GCC-4.9.2.eb' , test_target_dir ]
893
- self .eb_main (args )
906
+ stdout = mocked_main (args )
907
+ self .assertEqual (stdout , '2 file(s) copied to %s' % test_target_dir )
894
908
895
909
check_copied_files ()
896
910
@@ -901,7 +915,8 @@ def check_copied_files():
901
915
args [- 1 ] = os .path .basename (test_target_dir )
902
916
self .assertFalse (os .path .exists (args [- 1 ]))
903
917
904
- self .eb_main (args )
918
+ stdout = mocked_main (args )
919
+ self .assertEqual (stdout , '2 file(s) copied to test_target_dir' )
905
920
906
921
check_copied_files ()
907
922
@@ -912,6 +927,24 @@ def check_copied_files():
912
927
error_pattern = ".*/test.eb exists but is not a directory"
913
928
self .assertErrorRegex (EasyBuildError , error_pattern , self .eb_main , args , raise_error = True )
914
929
930
+ # test use of --copy-ec with only one argument: copy to current working directory
931
+ test_working_dir = os .path .join (self .test_prefix , 'test_working_dir' )
932
+ mkdir (test_working_dir )
933
+ change_dir (test_working_dir )
934
+ self .assertEqual (len (os .listdir (os .getcwd ())), 0 )
935
+ args = ['--copy-ec' , 'toy-0.0.eb' ]
936
+ stdout = mocked_main (args )
937
+ regex = re .compile ('toy-0.0.eb copied to .*/%s' % os .path .basename (test_working_dir ))
938
+ self .assertTrue (regex .match (stdout ), "Pattern '%s' found in: %s" % (regex .pattern , stdout ))
939
+ copied_toy_cwd = os .path .join (test_working_dir , 'toy-0.0.eb' )
940
+ self .assertTrue (os .path .exists (copied_toy_cwd ))
941
+ self .assertEqual (read_file (copied_toy_cwd ), toy_ec_txt )
942
+
943
+ # --copy-ec without arguments results in a proper error
944
+ args = ['--copy-ec' ]
945
+ error_pattern = "One of more files to copy should be specified!"
946
+ self .assertErrorRegex (EasyBuildError , error_pattern , self .eb_main , args , raise_error = True )
947
+
915
948
def test_dry_run (self ):
916
949
"""Test dry run (long format)."""
917
950
fd , dummylogfn = tempfile .mkstemp (prefix = 'easybuild-dummy' , suffix = '.log' )
0 commit comments