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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# gemato: Top-level Manifest finding tests
# vim:fileencoding=utf-8
# (c) 2017 Michał Górny
# Licensed under the terms of 2-clause BSD license
import os
import os.path
import unittest
import gemato.find_top_level
from tests.testutil import TempDirTestCase
class TestCurrentDirectory(TempDirTestCase):
"""
Test for finding top-level Manifest in a plain tree.
"""
DIRS = ['suba', 'subb', 'subc', 'subc/sub']
FILES = {
'Manifest': u'',
'subb/Manifest': u'',
'subc/sub/Manifest': u'',
}
def test_find_top_level_manifest(self):
self.assertEqual(
os.path.relpath(
gemato.find_top_level.find_top_level_manifest(self.dir),
self.dir),
'Manifest')
def test_find_top_level_manifest_from_empty_subdir(self):
self.assertEqual(
os.path.relpath(
gemato.find_top_level.find_top_level_manifest(
os.path.join(self.dir, 'suba')),
self.dir),
'Manifest')
def test_find_top_level_manifest_from_manifest_subdir(self):
self.assertEqual(
os.path.relpath(
gemato.find_top_level.find_top_level_manifest(
os.path.join(self.dir, 'subb')),
self.dir),
'Manifest')
def test_find_top_level_manifest_from_deep_manifest_subdir(self):
self.assertEqual(
os.path.relpath(
gemato.find_top_level.find_top_level_manifest(
os.path.join(self.dir, 'subc', 'sub')),
self.dir),
'Manifest')
class TestUnreadableManifest(TempDirTestCase):
"""
Test whether the function fails correctly when it can not read
a Manifest file.
"""
FILES = {
'Manifest': u'',
}
def setUp(self):
super(TestUnreadableManifest, self).setUp()
os.chmod(os.path.join(self.dir, 'Manifest'), 0)
def test_find_top_level_manifest(self):
self.assertRaises(IOError,
gemato.find_top_level.find_top_level_manifest, self.dir)
class TestIgnoredSubdir(TempDirTestCase):
"""
Test for ignoring irrelevant Manifest.
"""
DIRS = ['sub', 'sub/sub', 'subb', 'subempty']
FILES = {
'Manifest': u'''
IGNORE sub
IGNORE subempty
''',
'sub/Manifest': u'',
}
def test_find_top_level_manifest(self):
self.assertEqual(
os.path.relpath(
gemato.find_top_level.find_top_level_manifest(self.dir),
self.dir),
'Manifest')
def test_find_top_level_manifest_from_ignored_subdir(self):
self.assertEqual(
os.path.relpath(
gemato.find_top_level.find_top_level_manifest(
os.path.join(self.dir, 'sub')),
self.dir),
'sub/Manifest')
def test_find_top_level_manifest_from_sub_subdir(self):
self.assertEqual(
os.path.relpath(
gemato.find_top_level.find_top_level_manifest(
os.path.join(self.dir, 'sub/sub')),
self.dir),
'sub/Manifest')
def test_find_top_level_manifest_from_non_ignored_subdir(self):
self.assertEqual(
os.path.relpath(
gemato.find_top_level.find_top_level_manifest(
os.path.join(self.dir, 'subb')),
self.dir),
'Manifest')
def test_find_top_level_manifest_from_ignored_empty_subdir(self):
self.assertIsNone(
gemato.find_top_level.find_top_level_manifest(
os.path.join(self.dir, 'subempty')))
class TestEmptyTree(TempDirTestCase):
"""
Test for finding top-level Manifest in a tree without a Manifest
"""
def test_find_top_level_manifest(self):
self.assertIsNone(
gemato.find_top_level.find_top_level_manifest(self.dir))
class TestRootDirectory(unittest.TestCase):
"""
Test behavior when run on the system root directory.
"""
def test_find_top_level_manifest(self):
if os.path.exists('/Manifest'):
raise unittest.SkipTest('/Manifest is present')
self.assertIsNone(
gemato.find_top_level.find_top_level_manifest('/'))
class TestCrossDevice(TempDirTestCase):
"""
Test behavior when attempting to cross device boundary.
"""
FILES = {
'Manifest': u'',
}
def setUp(self):
if not os.path.exists('/proc'):
raise unittest.SkipTest('/proc does not exist')
super(TestCrossDevice, self).setUp()
os.symlink('/proc', os.path.join(self.dir, 'test'))
def tearDown(self):
os.unlink(os.path.join(self.dir, 'test'))
super(TestCrossDevice, self).tearDown()
def test_find_top_level_manifest(self):
self.assertIsNone(
gemato.find_top_level.find_top_level_manifest(
os.path.join(self.dir, 'test')))
class TestCrossDeviceManifest(TempDirTestCase):
"""
Test behavior when attempting to use a Manifest from other device
(symlinked).
"""
DIRS = ['sub']
def setUp(self):
if not os.path.exists('/proc/version'):
raise unittest.SkipTest('/proc/version does not exist')
super(TestCrossDeviceManifest, self).setUp()
os.symlink('/proc/version', os.path.join(self.dir, 'Manifest'))
def tearDown(self):
os.unlink(os.path.join(self.dir, 'Manifest'))
super(TestCrossDeviceManifest, self).tearDown()
def test_find_top_level_manifest(self):
self.assertIsNone(
gemato.find_top_level.find_top_level_manifest(
os.path.join(self.dir, 'sub')))
|