Skip to content

Commit

Permalink
Merge pull request #1 from boegel/include_expand_tilde
Browse files Browse the repository at this point in the history
add/enhance tests to verify expanding of ~
  • Loading branch information
tobbez committed May 23, 2016
2 parents d382246 + 7e71ff2 commit f89c666
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
27 changes: 27 additions & 0 deletions test/framework/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,33 @@ def test_weld_paths(self):
self.assertEqual(ft.weld_paths('/foo/bar', '/foo/bar'), '/foo/bar/')
self.assertEqual(ft.weld_paths('/foo', '/foo/bar/baz'), '/foo/bar/baz/')

def test_expand_glob_paths(self):
"""Test expand_glob_paths function."""
for dirname in ['empty_dir', 'test_dir']:
ft.mkdir(os.path.join(self.test_prefix, dirname), parents=True)
for filename in ['file1.txt', 'test_dir/file2.txt', 'test_dir/file3.txt', 'test_dir2/file4.dat']:
ft.write_file(os.path.join(self.test_prefix, filename), 'gibberish')

globs = [os.path.join(self.test_prefix, '*.txt'), os.path.join(self.test_prefix, '*', '*')]
expected = [
os.path.join(self.test_prefix, 'file1.txt'),
os.path.join(self.test_prefix, 'test_dir', 'file2.txt'),
os.path.join(self.test_prefix, 'test_dir', 'file3.txt'),
os.path.join(self.test_prefix, 'test_dir2', 'file4.dat'),
]
self.assertEqual(ft.expand_glob_paths(globs), expected)

# passing non-glob patterns is fine too
file2 = os.path.join(self.test_prefix, 'test_dir', 'file2.txt')
self.assertEqual(ft.expand_glob_paths([file2]), [file2])

# test expanding of '~' into $HOME value
# hard overwrite $HOME in environment (used by os.path.expanduser) so we can reliably test this
new_home = os.path.join(self.test_prefix, 'home')
ft.mkdir(new_home, parents=True)
ft.write_file(os.path.join(new_home, 'test.txt'), 'test')
os.environ['HOME'] = new_home
self.assertEqual(ft.expand_glob_paths(['~/*.txt']), [os.path.join(new_home, 'test.txt')])

def test_adjust_permissions(self):
"""Test adjust_permissions"""
Expand Down
5 changes: 4 additions & 1 deletion test/framework/include.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ def test_include_easyblocks(self):
])
write_file(os.path.join(myeasyblocks, 'generic', 'mybar.py'), mybar_easyblock_txt)

# hijack $HOME to test expanding ~ in locations passed to include_easyblocks
os.environ['HOME'] = myeasyblocks

# expand set of known easyblocks with our custom ones
glob_paths = [os.path.join(myeasyblocks, '*'), os.path.join(myeasyblocks, '*/*.py')]
glob_paths = [os.path.join('~', '*'), os.path.join(myeasyblocks, '*/*.py')]
included_easyblocks_path = include_easyblocks(self.test_prefix, glob_paths)

expected_paths = ['__init__.py', 'easyblocks/__init__.py', 'easyblocks/myfoo.py',
Expand Down

0 comments on commit f89c666

Please sign in to comment.