-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_api.py
62 lines (46 loc) · 1.89 KB
/
test_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# isort:skip_file
import os.path
import unittest
from projectionist import find_alternate_file
from Projectionist.plugin import cache
from Projectionist.plugin.root import Root
from Projectionist.tests import FIXTURES_PATH
class PublicAPITestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cache.clear()
def setUp(self):
self.root = Root(os.path.join(FIXTURES_PATH, "dummy"))
def test_find_alternate_file(self):
exists, alternate = find_alternate_file(
self.root.path, self.root.file("folder4", "file4.py").path
)
self.assertTrue(exists)
self.assertIsInstance(alternate, str)
# as per .projections.json
self.assertEqual(alternate, self.root.file("folder2", "file2.py").path)
def test_find_alternate_file_non_existing_alternate(self):
exists, alternate = find_alternate_file(
self.root.path, self.root.file("folder1", "file1.py").path
)
self.assertFalse(exists)
self.assertIsInstance(alternate, str)
# as per .projections.json
self.assertEqual(alternate, self.root.file("folder10", "file10.py").path)
def test_find_alternate_file_undefined_projection(self):
exists, alternate = find_alternate_file(
self.root.path, self.root.file("folder10", "file10.py").path
)
self.assertFalse(exists)
self.assertIsNone(alternate)
def test_find_alternate_file_errors(self):
with self.assertRaises(TypeError):
find_alternate_file(None, None)
with self.assertRaises(TypeError):
find_alternate_file(None, "smth")
with self.assertRaises(TypeError):
find_alternate_file("smth", None)
with self.assertRaises(ValueError):
find_alternate_file(
self.root.join("subfolder1"), self.root.file("subfolder2", "file2.py")
)