diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2024-03-11 11:31:05 -0700 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2024-03-15 09:24:06 -0700 |
| commit | 6db1d2bca5eaf9ff3f92249340da7b66c91d26c5 (patch) | |
| tree | 8bac7000090c16cff39b9f7570dd103cdb487053 | |
| parent | dacb25db101e7ede60b6ba3dd5a7d1935dc5ff73 (diff) | |
| download | meson-6db1d2bca5eaf9ff3f92249340da7b66c91d26c5.tar.gz | |
unittests: Add a helper for copying source trees
This is a useful thing to do when a test needs to modify the source
tree, as it prevents races between tests.
| -rw-r--r-- | unittests/baseplatformtests.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/unittests/baseplatformtests.py b/unittests/baseplatformtests.py index 6125ed933..93bfc8905 100644 --- a/unittests/baseplatformtests.py +++ b/unittests/baseplatformtests.py @@ -1,6 +1,8 @@ # SPDX-License-Identifier: Apache-2.0 # Copyright 2016-2021 The Meson development team +# Copyright © 2024 Intel Corporation +from __future__ import annotations from pathlib import PurePath from unittest import mock, TestCase, SkipTest import json @@ -9,6 +11,7 @@ import os import re import subprocess import sys +import shutil import tempfile import typing as T @@ -492,3 +495,23 @@ class BasePlatformTests(TestCase): def assertLength(self, val, length): assert len(val) == length, f'{val} is not length {length}' + + def copy_srcdir(self, srcdir: str) -> str: + """Copies a source tree and returns that copy. + + ensures that the copied tree is deleted after running. + + :param srcdir: The locaiton of the source tree to copy + :return: The location of the copy + """ + dest = tempfile.mkdtemp() + self.addCleanup(windows_proof_rmtree, dest) + + # shutil.copytree expects the destinatin directory to not exist, Once + # python 3.8 is required the `dirs_exist_ok` parameter negates the need + # for this + dest = os.path.join(dest, 'subdir') + + shutil.copytree(srcdir, dest) + + return dest |
