1
Test the manifest parser
2
========================
4
You must have ManifestDestiny installed before running these tests.
5
Run ``python manifestparser.py setup develop`` with setuptools installed.
7
Ensure basic parser is sane::
9
>>> from manifestparser import ManifestParser
10
>>> parser = ManifestParser()
11
>>> parser.read('mozmill-example.ini')
12
>>> tests = parser.tests
13
>>> len(tests) == len(file('mozmill-example.ini').read().strip().splitlines())
16
Ensure that capitalization and order aren't an issue:
18
>>> lines = ['[%s]' % test['name'] for test in tests]
19
>>> lines == file('mozmill-example.ini').read().strip().splitlines()
22
Show how you select subsets of tests:
24
>>> parser.read('mozmill-restart-example.ini')
25
>>> restart_tests = parser.get(type='restart')
26
>>> len(restart_tests) < len(parser.tests)
29
>>> len(restart_tests) == len(parser.get(manifest=os.path.abspath('mozmill-restart-example.ini')))
31
>>> assert not [test for test in restart_tests if test['manifest'] != os.path.abspath('mozmill-restart-example.ini')]
32
>>> parser.get('name', tags=['foo'])
33
['restartTests/testExtensionInstallUninstall/test2.js', 'restartTests/testExtensionInstallUninstall/test1.js']
34
>>> parser.get('name', foo='bar')
35
['restartTests/testExtensionInstallUninstall/test2.js']
37
Illustrate how include works::
39
>>> parser = ManifestParser(manifests=('include-example.ini',))
41
All of the tests should be included, in order::
43
>>> parser.get('name')
44
['crash-handling', 'fleem', 'flowers']
45
>>> [(test['name'], os.path.basename(test['manifest'])) for test in parser.tests]
46
[('crash-handling', 'bar.ini'), ('fleem', 'include-example.ini'), ('flowers', 'foo.ini')]
48
The manifests should be there too::
50
>>> len(parser.manifests())
53
We're already in the root directory::
55
>>> os.getcwd() == parser.rootdir
58
DEFAULT values should persist across includes, unless they're
59
overwritten. In this example, include-example.ini sets foo=bar, but
60
its overridden to fleem in bar.ini::
62
>>> parser.get('name', foo='bar')
64
>>> parser.get('name', foo='fleem')
67
Passing parameters in the include section allows defining variables in
70
>>> parser.get('name', tags=['red'])
73
However, this should be overridable from the DEFAULT section in the
74
included file and that overridable via the key directly connected to
77
>>> parser.get(name='flowers')[0]['blue']
79
>>> parser.get(name='flowers')[0]['yellow']
82
You can query multiple times if you need to::
84
>>> flowers = parser.get(foo='bar')
87
>>> roses = parser.get(tests=flowers, red='roses')
89
Using the inverse flag should invert the set of tests returned::
91
>>> parser.get('name', inverse=True, tags=['red'])
92
['crash-handling', 'fleem']
94
All of the included tests actually exist::
96
>>> [i['name'] for i in parser.missing()]
99
Write the output to a manifest:
101
>>> from StringIO import StringIO
102
>>> buffer = StringIO()
103
>>> parser.write(fp=buffer, global_kwargs={'foo': 'bar'})
104
>>> buffer.getvalue().strip()
105
'[DEFAULT]\nfoo = bar\n\n[fleem]\n\n[include/flowers]\nblue = ocean\nred = roses\nyellow = submarine'
107
Test our ability to convert a static directory structure to a
108
manifest. First, stub out a directory with files in it::
110
>>> import shutil, tempfile
111
>>> def create_stub():
112
... directory = tempfile.mkdtemp()
113
... for i in 'foo', 'bar', 'fleem':
114
... file(os.path.join(directory, i), 'w').write(i)
115
... subdir = os.path.join(directory, 'subdir')
117
... file(os.path.join(subdir, 'subfile'), 'w').write('baz')
119
>>> stub = create_stub()
120
>>> os.path.exists(stub) and os.path.isdir(stub)
123
Make a manifest for it::
125
>>> from manifestparser import convert
126
>>> print convert([stub])
131
>>> shutil.rmtree(stub)
133
Now do the same thing but keep the manifests in place::
135
>>> stub = create_stub()
136
>>> convert([stub], write='manifest.ini')
137
>>> sorted(os.listdir(stub))
138
['bar', 'fleem', 'foo', 'manifest.ini', 'subdir']
139
>>> parser = ManifestParser()
140
>>> parser.read(os.path.join(stub, 'manifest.ini'))
141
>>> [i['name'] for i in parser.tests]
142
['subfile', 'bar', 'fleem', 'foo']
143
>>> parser = ManifestParser()
144
>>> parser.read(os.path.join(stub, 'subdir', 'manifest.ini'))
145
>>> len(parser.tests)
147
>>> parser.tests[0]['name']
149
>>> shutil.rmtree(stub)
151
Test our ability to copy a set of manifests::
153
>>> tempdir = tempfile.mkdtemp()
154
>>> manifest = ManifestParser(manifests=('include-example.ini',))
155
>>> manifest.copy(tempdir)
156
>>> sorted(os.listdir(tempdir))
157
['fleem', 'include', 'include-example.ini']
158
>>> sorted(os.listdir(os.path.join(tempdir, 'include')))
159
['bar.ini', 'crash-handling', 'flowers', 'foo.ini']
160
>>> from_manifest = ManifestParser(manifests=('include-example.ini',))
161
>>> to_manifest = os.path.join(tempdir, 'include-example.ini')
162
>>> to_manifest = ManifestParser(manifests=(to_manifest,))
163
>>> to_manifest.get('name') == from_manifest.get('name')
165
>>> shutil.rmtree(tempdir)
167
Test our ability to update tests from a manifest and a directory of
170
>>> tempdir = tempfile.mkdtemp()
171
>>> for i in range(10):
172
... file(os.path.join(tempdir, str(i)), 'w').write(str(i))
174
First, make a manifest::
176
>>> manifest = convert([tempdir])
177
>>> newtempdir = tempfile.mkdtemp()
178
>>> manifest_file = os.path.join(newtempdir, 'manifest.ini')
179
>>> file(manifest_file,'w').write(manifest)
180
>>> manifest = ManifestParser(manifests=(manifest_file,))
181
>>> manifest.get('name') == [str(i) for i in range(10)]
184
All of the tests are initially missing::
186
>>> [i['name'] for i in manifest.missing()] == [str(i) for i in range(10)]
189
But then we copy one over::
191
>>> manifest.get('name', name='1')
193
>>> manifest.update(tempdir, name='1')
194
>>> sorted(os.listdir(newtempdir))
195
['1', 'manifest.ini']
197
Update that one file and copy all the "tests"::
199
>>> file(os.path.join(tempdir, '1'), 'w').write('secret door')
200
>>> manifest.update(tempdir)
201
>>> sorted(os.listdir(newtempdir))
202
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'manifest.ini']
203
>>> file(os.path.join(newtempdir, '1')).read().strip()
208
>>> shutil.rmtree(tempdir)
209
>>> shutil.rmtree(newtempdir)
211
You can override the path in the section too. This shows that you can
212
use a relative path::
214
>>> manifest = ManifestParser(manifests=('path-example.ini',))
215
>>> manifest.tests[0]['path'] == os.path.abspath('fleem')