diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-10-24 09:53:53 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-10-24 09:53:53 -0400 |
commit | 20baf284341555803d800ec4c248fd0f1b5351f1 (patch) | |
tree | 315429176663e477a732c2fe9c0ad42f63fde0f3 /tests/helpers.py | |
parent | 4902b6c53740c8e871bb03e69e4345c5cafad96e (diff) | |
download | python-coveragepy-git-20baf284341555803d800ec4c248fd0f1b5351f1.tar.gz |
refactor(test): os_sep and remove_tree helpers
Diffstat (limited to 'tests/helpers.py')
-rw-r--r-- | tests/helpers.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/helpers.py b/tests/helpers.py index 1420bed7..185f20dd 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -9,6 +9,7 @@ import glob import os import os.path import re +import shutil import subprocess import textwrap @@ -95,6 +96,11 @@ def nice_file(*fparts): return os.path.normcase(os.path.abspath(os.path.realpath(fname))) +def os_sep(s): + """Replace slashes in `s` with the correct separator for the OS.""" + return s.replace("/", os.sep) + + class CheckUniqueFilenames: """Asserts the uniqueness of file names passed to a function.""" def __init__(self, wrapped): @@ -156,6 +162,14 @@ def remove_files(*patterns): for fname in glob.glob(pattern): os.remove(fname) +def remove_tree(dirname): + """Remove a directory tree. + + It's fine for the directory to not exist in the first place. + """ + if os.path.exists(dirname): + shutil.rmtree(dirname) + # Map chars to numbers for arcz_to_arcs _arcz_map = {'.': -1} |