-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
56 lines (45 loc) · 1.91 KB
/
tests.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
import unittest
import core
from core import (find_file, File, find_includes, find_related_sources,
dependencies)
class CoreTest(unittest.TestCase):
def setUp(self):
core.PATH = []
def test_File(self):
""" Test File class """
f = File('../test/../test/main.cpp')
self.assertEqual(str(f), '../test/main.cpp')
self.assertEqual(f.full, '../test/main.cpp')
self.assertEqual(f.path, '../test')
self.assertEqual(f.name, 'main')
self.assertEqual(f.ext, '.cpp')
self.assertEqual(f.path_name, '../test/main')
self.assertEqual(f.name_ext, 'main.cpp')
def test_find_file(self):
core.PATH.append('test')
core.PATH.append('test/sub')
self.assertEqual(find_file(File('a.txt')).full, 'test/a.txt')
self.assertEqual(find_file(File('b.txt')).full, 'test/sub/b.txt')
def test_find_file_path(self):
self.assertEqual(find_file(File('a.txt'), 'test').full, 'test/a.txt')
self.assertRaises(IOError, find_file, File('notfound.txt'))
def test_find_includes(self):
actual = File('test/main.cpp')
includes = find_includes(actual)
inc = includes[0]
self.assertEqual(inc.name_ext, 'pepe.h')
def test_find_related_sources(self):
includes = [File(f) for f in ['test/pepe.h', 'test/otro.h']]
sources = find_related_sources(includes)
self.assertEqual(len(sources), 1)
self.assertEqual(sources[0].full, 'test/pepe.cpp')
def test_dependencies(self):
f = File('test/main.cpp')
dependencies(f)
self.assertEqual(len(f.includes), 2)
self.assertEqual(len(f.sources), 1)
self.assertEqual(f.includes[0].full, 'test/pepe.h')
self.assertEqual(f.includes[1].full, 'test/otro.h')
self.assertEqual(f.sources[0].full, 'test/pepe.cpp')
if __name__ == '__main__':
unittest.main()