@@ -3657,41 +3657,53 @@ def test_copy_framework_files(self):
36573657
36583658 topdir = os .path .dirname (os .path .dirname (os .path .dirname (os .path .abspath (__file__ ))))
36593659 test_files = [
3660- os .path .join ('easybuild' , 'tools' , 'filetools.py' ),
3661- os .path .join ('test' , 'framework' , 'modules.py' ),
3662- os .path .join ('test' , 'framework' , 'sandbox' , 'sources' , 'toy' , 'toy-0.0.tar.gz' ),
3660+ (topdir , os .path .join ('test' , 'framework' , 'modules.py' )),
3661+ (topdir , os .path .join ('test' , 'framework' , 'sandbox' , 'sources' , 'toy' , 'toy-0.0.tar.gz' )),
36633662 ]
3664- expected_entries = ['easybuild' , ' test' ]
3663+ expected_entries = ['test' ]
36653664 # test/framework/modules.py is not new
3666- expected_new = [True , False , True ]
3665+ expected_new = [False , True ]
36673666
3668- # we include setup.py conditionally because it may not be there,
3667+ # CI might copy the test folder, so find source dir
3668+ possible_dirs = [topdir ,
3669+ os .environ .get ('GITHUB_WORKSPACE' , '' ),
3670+ # Fallback: If we are run from the source dir without being installed
3671+ os .getcwd (),
3672+ ] + os .environ .get ('PYTHONPATH' , '' ).split (':' ) # Or at least have it in PYTHONPATH
3673+
3674+ # we include those conditionally because it may not be there,
36693675 # for example when running the tests on an actual easybuild-framework instalation,
36703676 # as opposed to when running from a repository checkout...
36713677 # setup.py is an important test case, since it has no parent directory
36723678 # (it's straight in the easybuild-framework directory)
3673- setup_py = 'setup.py'
3674- if os .path .exists (os .path .join (topdir , setup_py )):
3675- test_files .append (os .path .join (setup_py ))
3676- expected_entries .append (setup_py )
3677- expected_new .append (True )
3679+ try :
3680+ srcdir = next (d for d in possible_dirs if os .path .basename (d ) == 'easybuild-framework' and
3681+ os .path .exists (os .path .join (d , 'easybuild' , 'framework' )))
3682+ except StopIteration :
3683+ print (f"Running on installation without source, skipping parts of the checks\n Tried: { possible_dirs } " )
3684+ else :
3685+ setup_py = 'setup.py'
3686+ filetools_py = os .path .join ('easybuild' , 'tools' , 'filetools.py' )
3687+ test_files .extend ([(srcdir , setup_py ), (srcdir , filetools_py )])
3688+ expected_entries .extend ([setup_py , 'easybuild' ])
3689+ expected_new .extend ([True , True ])
36783690
36793691 # files being copied are expected to be in a directory named 'easybuild-framework',
36803692 # so we need to make sure that's the case here as well (may not be in workspace dir on Travis from example)
36813693 framework_dir = os .path .join (self .test_prefix , 'easybuild-framework' )
3682- for test_file in test_files :
3683- ft .copy_file (os .path .join (topdir , test_file ), os .path .join (framework_dir , test_file ))
3694+ for root , test_file in test_files :
3695+ ft .copy_file (os .path .join (root , test_file ), os .path .join (framework_dir , test_file ))
36843696
3685- test_paths = [os .path .join (framework_dir , f ) for f in test_files ]
3697+ test_paths = [os .path .join (framework_dir , f ) for _root , f in test_files ]
36863698
36873699 res = ft .copy_framework_files (test_paths , target_dir )
36883700
36893701 self .assertEqual (sorted (os .listdir (target_dir )), sorted (expected_entries ))
36903702
36913703 self .assertEqual (sorted (res .keys ()), ['new' , 'paths_in_repo' ])
36923704
3693- for idx , test_file in enumerate (test_files ):
3694- orig_path = os .path .join (topdir , test_file )
3705+ for idx , ( root , test_file ) in enumerate (test_files ):
3706+ orig_path = os .path .join (root , test_file )
36953707 copied_path = os .path .join (target_dir , test_file )
36963708
36973709 self .assertExists (copied_path )
0 commit comments