| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
import os |
| 18 |
import shutil |
| 19 |
import tempfile |
| 20 |
import unittest |
| 21 |
from unittest import TestCase |
| 22 |
|
| 23 |
__all__ = ["TestCaseInTempDir"] |
| 24 |
|
| 25 |
|
| 26 |
class TestCaseInTempDir(TestCase): |
| 27 |
"""Minimal TestCase that runs in a temporary directory. |
| 28 |
|
| 29 |
Only implements the functionality actually needed by vcsgraph tests. |
| 30 |
""" |
| 31 |
|
| 32 |
def setUp(self): |
| 33 |
super().setUp() |
| 34 |
self.test_dir = tempfile.mkdtemp(prefix="vcsgraph_test_") |
| 35 |
self.original_dir = os.getcwd() |
| 36 |
os.chdir(self.test_dir) |
| 37 |
|
| 38 |
def tearDown(self): |
| 39 |
os.chdir(self.original_dir) |
| 40 |
shutil.rmtree(self.test_dir) |
| 41 |
super().tearDown() |
| 42 |
|
| 43 |
def assertPathExists(self, path): |
| 44 |
"""Fail unless path exists.""" |
| 45 |
self.assertTrue(os.path.lexists(path), f"{path} does not exist") |
| 46 |
|
| 47 |
def assertPathDoesNotExist(self, path): |
| 48 |
"""Fail if path exists.""" |
| 49 |
self.assertFalse(os.path.lexists(path), f"{path} exists") |
| 50 |
|
| 51 |
|
| 52 |
def test_suite() -> unittest.TestSuite: |
| 53 |
names = [ |
| 54 |
"known_graph", |
| 55 |
"graph", |
| 56 |
"tsort", |
| 57 |
] |
| 58 |
module_names = ["vcsgraph.tests.test_" + name for name in names] |
| 59 |
loader = unittest.TestLoader() |
| 60 |
return loader.loadTestsFromNames(module_names) |