Debian Codegraph @

vcsgraph/tests/__init__.py

raw symbols SCIP
1 # Copyright (C) 2025 Breezy Developers
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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)