fix cmd/clean tests
This commit is contained in:
committed by
Tamara Dahlgren
parent
d6a497540d
commit
e5a9a376bf
@@ -41,6 +41,8 @@
|
||||
'fix_darwin_install_name',
|
||||
'force_remove',
|
||||
'force_symlink',
|
||||
'chgrp',
|
||||
'chmod_x',
|
||||
'copy',
|
||||
'install',
|
||||
'copy_tree',
|
||||
@@ -51,6 +53,7 @@
|
||||
'partition_path',
|
||||
'prefixes',
|
||||
'remove_dead_links',
|
||||
'remove_directory_contents',
|
||||
'remove_if_dead_link',
|
||||
'remove_linked_tree',
|
||||
'set_executable',
|
||||
@@ -1796,3 +1799,13 @@ def md5sum(file):
|
||||
with open(file, "rb") as f:
|
||||
md5.update(f.read())
|
||||
return md5.digest()
|
||||
|
||||
|
||||
def remove_directory_contents(dir):
|
||||
"""Remove all contents of a directory."""
|
||||
if os.path.exists(dir):
|
||||
for entry in [os.path.join(dir, entry) for entry in os.listdir(dir)]:
|
||||
if os.path.isfile(entry) or os.path.islink(entry):
|
||||
os.unlink(entry)
|
||||
else:
|
||||
shutil.rmtree(entry)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
import shutil
|
||||
|
||||
import llnl.util.tty as tty
|
||||
import llnl.util.filesystem as fs
|
||||
|
||||
import spack.caches
|
||||
import spack.cmd
|
||||
@@ -88,17 +89,9 @@ def clean(parser, args):
|
||||
|
||||
if args.test_stage:
|
||||
tty.msg("Removing files in test stage")
|
||||
|
||||
# get stage
|
||||
test_stage_root = sup.canonicalize_path(
|
||||
spack.config.get('config:test_stage', ''))
|
||||
|
||||
# delete any subdirectories
|
||||
if os.path.exists(test_stage_root):
|
||||
contents = [os.path.join(test_stage_root, entry)
|
||||
for entry in os.listdir(test_stage_root)]
|
||||
for entry in contents:
|
||||
shutil.rmtree(entry)
|
||||
fs.remove_directory_contents(test_stage_root)
|
||||
|
||||
if args.python_cache:
|
||||
tty.msg('Removing python cache files')
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
import spack.caches
|
||||
import spack.main
|
||||
import spack.package
|
||||
import llnl.util.filesystem as fs
|
||||
|
||||
clean = spack.main.SpackCommand('clean')
|
||||
|
||||
@@ -30,6 +31,7 @@ def __call__(self, *args, **kwargs):
|
||||
spack.caches.misc_cache, 'destroy', Counter())
|
||||
monkeypatch.setattr(
|
||||
spack.installer, 'clear_failures', Counter())
|
||||
monkeypatch.setattr(fs, 'remove_directory_contents', Counter())
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
@@ -41,6 +43,7 @@ def __call__(self, *args, **kwargs):
|
||||
('-sd', [0, 1, 1, 0, 0]),
|
||||
('-m', [0, 0, 0, 1, 0]),
|
||||
('-f', [0, 0, 0, 0, 1]),
|
||||
('-t', [0, 0, 0, 0, 1]),
|
||||
('-a', [0, 1, 1, 1, 1]),
|
||||
('', [0, 0, 0, 0, 0]),
|
||||
])
|
||||
@@ -56,3 +59,4 @@ def test_function_calls(command_line, counters):
|
||||
assert spack.caches.fetch_cache.destroy.call_count == counters[2]
|
||||
assert spack.caches.misc_cache.destroy.call_count == counters[3]
|
||||
assert spack.installer.clear_failures.call_count == counters[4]
|
||||
assert fs.remove_directory_contents.call_count == counters[4]
|
||||
|
||||
Reference in New Issue
Block a user