summaryrefslogtreecommitdiff
path: root/tests/utils.py
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2020-12-07 13:49:26 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2020-12-07 13:49:26 +0100
commit714c30e429dab8083b9e5317209e44619d875d22 (patch)
treee6b4a7a4474320fff1f63388a96407a596cfff79 /tests/utils.py
parentd051e35086de44166fae87ed5edef32083d7e426 (diff)
Test compatibility with python < 3.8
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/utils.py b/tests/utils.py
new file mode 100644
index 0000000..a56a120
--- /dev/null
+++ b/tests/utils.py
@@ -0,0 +1,18 @@
+import shutil
+import sys
+
+
+def copytree(src, dest, dirs_exist_ok=False):
+ """
+ Helper function to remove existing directories
+
+ Used in the tests for compatibility with python < 3.8
+ """
+ if sys.version_info >= (3, 8):
+ shutil.copytree(src, dest, dirs_exist_ok=dirs_exist_ok)
+ else:
+ if dirs_exist_ok:
+ if not dest.startswith('/tmp'):
+ raise ValueError("Refusing to delete a directory outside /tmp")
+ shutil.rmtree(dest)
+ shutil.copytree(src, dest)