Skip to content

Commit f89c666

Browse files
committed
Merge pull request #1 from boegel/include_expand_tilde
add/enhance tests to verify expanding of ~
2 parents d382246 + 7e71ff2 commit f89c666

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

test/framework/filetools.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,33 @@ def test_weld_paths(self):
452452
self.assertEqual(ft.weld_paths('/foo/bar', '/foo/bar'), '/foo/bar/')
453453
self.assertEqual(ft.weld_paths('/foo', '/foo/bar/baz'), '/foo/bar/baz/')
454454

455+
def test_expand_glob_paths(self):
456+
"""Test expand_glob_paths function."""
457+
for dirname in ['empty_dir', 'test_dir']:
458+
ft.mkdir(os.path.join(self.test_prefix, dirname), parents=True)
459+
for filename in ['file1.txt', 'test_dir/file2.txt', 'test_dir/file3.txt', 'test_dir2/file4.dat']:
460+
ft.write_file(os.path.join(self.test_prefix, filename), 'gibberish')
461+
462+
globs = [os.path.join(self.test_prefix, '*.txt'), os.path.join(self.test_prefix, '*', '*')]
463+
expected = [
464+
os.path.join(self.test_prefix, 'file1.txt'),
465+
os.path.join(self.test_prefix, 'test_dir', 'file2.txt'),
466+
os.path.join(self.test_prefix, 'test_dir', 'file3.txt'),
467+
os.path.join(self.test_prefix, 'test_dir2', 'file4.dat'),
468+
]
469+
self.assertEqual(ft.expand_glob_paths(globs), expected)
470+
471+
# passing non-glob patterns is fine too
472+
file2 = os.path.join(self.test_prefix, 'test_dir', 'file2.txt')
473+
self.assertEqual(ft.expand_glob_paths([file2]), [file2])
474+
475+
# test expanding of '~' into $HOME value
476+
# hard overwrite $HOME in environment (used by os.path.expanduser) so we can reliably test this
477+
new_home = os.path.join(self.test_prefix, 'home')
478+
ft.mkdir(new_home, parents=True)
479+
ft.write_file(os.path.join(new_home, 'test.txt'), 'test')
480+
os.environ['HOME'] = new_home
481+
self.assertEqual(ft.expand_glob_paths(['~/*.txt']), [os.path.join(new_home, 'test.txt')])
455482

456483
def test_adjust_permissions(self):
457484
"""Test adjust_permissions"""

test/framework/include.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,11 @@ def test_include_easyblocks(self):
7171
])
7272
write_file(os.path.join(myeasyblocks, 'generic', 'mybar.py'), mybar_easyblock_txt)
7373

74+
# hijack $HOME to test expanding ~ in locations passed to include_easyblocks
75+
os.environ['HOME'] = myeasyblocks
76+
7477
# expand set of known easyblocks with our custom ones
75-
glob_paths = [os.path.join(myeasyblocks, '*'), os.path.join(myeasyblocks, '*/*.py')]
78+
glob_paths = [os.path.join('~', '*'), os.path.join(myeasyblocks, '*/*.py')]
7679
included_easyblocks_path = include_easyblocks(self.test_prefix, glob_paths)
7780

7881
expected_paths = ['__init__.py', 'easyblocks/__init__.py', 'easyblocks/myfoo.py',

0 commit comments

Comments
 (0)