~ubuntu-branches/ubuntu/quantal/enigmail/quantal-security

« back to all changes in this revision

Viewing changes to testing/mozbase/manifestdestiny/tests/test_manifestparser.txt

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2013-09-13 16:02:15 UTC
  • mfrom: (0.12.16)
  • Revision ID: package-import@ubuntu.com-20130913160215-u3g8nmwa0pdwagwc
Tags: 2:1.5.2-0ubuntu0.12.10.1
* New upstream release v1.5.2 for Thunderbird 24

* Build enigmail using a stripped down Thunderbird 17 build system, as it's
  now quite difficult to build the way we were doing previously, with the
  latest Firefox build system
* Add debian/patches/no_libxpcom.patch - Don't link against libxpcom, as it
  doesn't exist anymore (but exists in the build system)
* Add debian/patches/use_sdk.patch - Use the SDK version of xpt.py and
  friends
* Drop debian/patches/ipc-pipe_rename.diff (not needed anymore)
* Drop debian/patches/makefile_depth.diff (not needed anymore)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Test the manifest parser
2
 
========================
3
 
 
4
 
You must have ManifestDestiny installed before running these tests.
5
 
Run ``python manifestparser.py setup develop`` with setuptools installed.
6
 
 
7
 
Ensure basic parser is sane::
8
 
 
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())
14
 
    True
15
 
    
16
 
Ensure that capitalization and order aren't an issue:
17
 
 
18
 
    >>> lines = ['[%s]' % test['name'] for test in tests]
19
 
    >>> lines == file('mozmill-example.ini').read().strip().splitlines()
20
 
    True
21
 
 
22
 
Show how you select subsets of tests:
23
 
 
24
 
    >>> parser.read('mozmill-restart-example.ini')
25
 
    >>> restart_tests = parser.get(type='restart')
26
 
    >>> len(restart_tests) < len(parser.tests)
27
 
    True
28
 
    >>> import os
29
 
    >>> len(restart_tests) == len(parser.get(manifest=os.path.abspath('mozmill-restart-example.ini')))
30
 
    True
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']
36
 
 
37
 
Illustrate how include works::
38
 
 
39
 
    >>> parser = ManifestParser(manifests=('include-example.ini',))
40
 
 
41
 
All of the tests should be included, in order::
42
 
 
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')]
47
 
 
48
 
The manifests should be there too::
49
 
 
50
 
    >>> len(parser.manifests())
51
 
    3
52
 
 
53
 
We're already in the root directory::
54
 
 
55
 
    >>> os.getcwd() == parser.rootdir
56
 
    True
57
 
 
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::
61
 
 
62
 
    >>> parser.get('name', foo='bar')
63
 
    ['fleem', 'flowers']
64
 
    >>> parser.get('name', foo='fleem')
65
 
    ['crash-handling']
66
 
 
67
 
Passing parameters in the include section allows defining variables in
68
 
the submodule scope:
69
 
 
70
 
    >>> parser.get('name', tags=['red'])
71
 
    ['flowers']
72
 
 
73
 
However, this should be overridable from the DEFAULT section in the
74
 
included file and that overridable via the key directly connected to
75
 
the test::
76
 
 
77
 
    >>> parser.get(name='flowers')[0]['blue']
78
 
    'ocean'
79
 
    >>> parser.get(name='flowers')[0]['yellow']
80
 
    'submarine'
81
 
 
82
 
You can query multiple times if you need to::
83
 
 
84
 
    >>> flowers = parser.get(foo='bar')
85
 
    >>> len(flowers)
86
 
    2
87
 
    >>> roses = parser.get(tests=flowers, red='roses')
88
 
 
89
 
Using the inverse flag should invert the set of tests returned::
90
 
 
91
 
    >>> parser.get('name', inverse=True, tags=['red'])
92
 
    ['crash-handling', 'fleem']
93
 
 
94
 
All of the included tests actually exist::
95
 
 
96
 
    >>> [i['name'] for i in parser.missing()]
97
 
    []
98
 
 
99
 
Write the output to a manifest:
100
 
 
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'
106
 
 
107
 
Test our ability to convert a static directory structure to a
108
 
manifest. First, stub out a directory with files in it::
109
 
 
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')
116
 
    ...     os.mkdir(subdir)
117
 
    ...     file(os.path.join(subdir, 'subfile'), 'w').write('baz')
118
 
    ...     return directory
119
 
    >>> stub = create_stub()
120
 
    >>> os.path.exists(stub) and os.path.isdir(stub)
121
 
    True
122
 
 
123
 
Make a manifest for it::
124
 
 
125
 
    >>> from manifestparser import convert
126
 
    >>> print convert([stub])
127
 
    [bar]
128
 
    [fleem]
129
 
    [foo]
130
 
    [subdir/subfile]
131
 
    >>> shutil.rmtree(stub)
132
 
 
133
 
Now do the same thing but keep the manifests in place::
134
 
 
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)
146
 
    1
147
 
    >>> parser.tests[0]['name']
148
 
    'subfile'
149
 
    >>> shutil.rmtree(stub)
150
 
 
151
 
Test our ability to copy a set of manifests::
152
 
 
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')
164
 
    True
165
 
    >>> shutil.rmtree(tempdir)
166
 
 
167
 
Test our ability to update tests from a manifest and a directory of
168
 
files::
169
 
 
170
 
    >>> tempdir = tempfile.mkdtemp()
171
 
    >>> for i in range(10):
172
 
    ...     file(os.path.join(tempdir, str(i)), 'w').write(str(i))
173
 
 
174
 
First, make a manifest::
175
 
 
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)]
182
 
    True
183
 
 
184
 
All of the tests are initially missing::
185
 
 
186
 
    >>> [i['name'] for i in manifest.missing()] == [str(i) for i in range(10)]
187
 
    True
188
 
 
189
 
But then we copy one over::
190
 
 
191
 
    >>> manifest.get('name', name='1')
192
 
    ['1']
193
 
    >>> manifest.update(tempdir, name='1')
194
 
    >>> sorted(os.listdir(newtempdir))
195
 
    ['1', 'manifest.ini']
196
 
 
197
 
Update that one file and copy all the "tests"::
198
 
   
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()
204
 
    'secret door'
205
 
 
206
 
Clean up::
207
 
 
208
 
    >>> shutil.rmtree(tempdir)
209
 
    >>> shutil.rmtree(newtempdir)
210
 
 
211
 
You can override the path in the section too.  This shows that you can
212
 
use a relative path::
213
 
 
214
 
    >>> manifest = ManifestParser(manifests=('path-example.ini',))
215
 
    >>> manifest.tests[0]['path'] == os.path.abspath('fleem')
216
 
    True
217