Skip to content

Commit 53f441f

Browse files
committed
Remove uses for binaries from test_extract_file
1 parent a0ab1ae commit 53f441f

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

test/framework/filetools.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,9 +2500,12 @@ def test_change_dir(self):
25002500
foo = os.path.join(self.test_prefix, 'foo')
25012501
self.assertErrorRegex(EasyBuildError, "Failed to change from .* to %s" % foo, ft.change_dir, foo)
25022502

2503-
def create_new_tarball(self, folder):
2503+
def create_new_tarball(self, folder, filename=None):
25042504
"""Create new tarball with contents of folder and return path"""
2505-
tarball = tempfile.mktemp(suffix='.tar.gz')
2505+
if filename is None:
2506+
tarball = tempfile.mktemp(suffix='.tar.gz')
2507+
else:
2508+
tarball = os.path.join(tempfile.mkdtemp(), filename)
25062509
with tarfile.open(tarball, "w:gz") as tar:
25072510
for name in glob.glob(os.path.join(folder, '*')):
25082511
tar.add(name, arcname=os.path.basename(name))
@@ -2512,8 +2515,10 @@ def test_extract_file(self):
25122515
"""Test extract_file"""
25132516
cwd = os.getcwd()
25142517

2515-
testdir = os.path.dirname(os.path.abspath(__file__))
2516-
toy_tarball = os.path.join(testdir, 'sandbox', 'sources', 'toy', 'toy-0.0.tar.gz')
2518+
test_src = tempfile.mkdtemp()
2519+
ft.mkdir(os.path.join(test_src, 'toy-0.0'))
2520+
ft.write_file(os.path.join(test_src, 'toy-0.0', 'toy.source'), 'content')
2521+
toy_tarball = self.create_new_tarball(test_src, filename='toy-0.0.tar.gz')
25172522

25182523
extraction_path = os.path.join(self.test_prefix, 'extraction') # New directory
25192524
toy_path = os.path.join(extraction_path, 'toy-0.0')
@@ -2603,8 +2608,15 @@ def test_extract_file(self):
26032608
self.assertExists(os.path.join(extraction_path, 'multi-bonus'))
26042609

26052610
# Extract multiple files with single folder to same folder, and file only
2606-
bar_tarball = os.path.join(testdir, 'sandbox', 'sources', 'toy', 'extensions', 'bar-0.0.tar.gz')
2607-
patch_tarball = os.path.join(testdir, 'sandbox', 'sources', 'toy', 'toy-0.0_gzip.patch.gz')
2611+
test_src = tempfile.mkdtemp()
2612+
ft.mkdir(os.path.join(test_src, 'bar-0.0'))
2613+
ft.write_file(os.path.join(test_src, 'bar-0.0', 'bar.source'), 'content')
2614+
bar_tarball = self.create_new_tarball(test_src)
2615+
2616+
test_src = tempfile.mkdtemp()
2617+
ft.write_file(os.path.join(test_src, 'main.source'), 'content')
2618+
file_tarball = self.create_new_tarball(test_src)
2619+
26082620
ft.remove_dir(extraction_path)
26092621
ft.change_dir(cwd)
26102622
with self.mocked_stdout_stderr():
@@ -2613,7 +2625,7 @@ def test_extract_file(self):
26132625
path = ft.extract_file(bar_tarball, extraction_path, change_into_dir=False)
26142626
self.assertTrue(os.path.samefile(path, os.path.join(extraction_path, 'bar-0.0')))
26152627
# Contains no folder
2616-
path = ft.extract_file(patch_tarball, extraction_path, change_into_dir=False)
2628+
path = ft.extract_file(file_tarball, extraction_path, change_into_dir=False)
26172629
self.assertTrue(os.path.samefile(path, extraction_path))
26182630

26192631
# Folder and file
@@ -2623,7 +2635,7 @@ def test_extract_file(self):
26232635
ft.write_file(os.path.join(test_src, 'main.c'), 'content')
26242636
test_tarball = self.create_new_tarball(test_src)
26252637
# When there is only a file or a file next to the folder the parent dir is returned
2626-
for tarball in (patch_tarball, test_tarball):
2638+
for tarball in (file_tarball, test_tarball):
26272639
ft.remove_dir(extraction_path)
26282640
with self.mocked_stdout_stderr():
26292641
path = ft.extract_file(tarball, extraction_path, change_into_dir=False)

0 commit comments

Comments
 (0)