File: test_distribution.py

package info (click to toggle)
python-pkginfo 1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 416 kB
  • ctags: 354
  • sloc: python: 1,487; makefile: 76
file content (370 lines) | stat: -rw-r--r-- 15,311 bytes parent folder | download
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
import unittest

class DistributionTests(unittest.TestCase):

    def _getTargetClass(self):
        from pkginfo.distribution import Distribution
        return Distribution

    def _makeOne(self, metadata_version='1.0'):
        dist = self._getTargetClass()()
        if metadata_version is not None:
            dist.metadata_version = metadata_version
        return dist

    def test_ctor_defaults(self):
        sdist = self._makeOne(None)
        self.assertEqual(sdist.metadata_version, None)
        self.assertEqual(sdist.name, None)
        self.assertEqual(sdist.version, None)
        self.assertEqual(sdist.platforms, ())
        self.assertEqual(sdist.supported_platforms, ())
        self.assertEqual(sdist.summary, None)
        self.assertEqual(sdist.description, None)
        self.assertEqual(sdist.keywords, None)
        self.assertEqual(sdist.home_page, None)
        self.assertEqual(sdist.download_url, None)
        self.assertEqual(sdist.author, None)
        self.assertEqual(sdist.author_email, None)
        self.assertEqual(sdist.license, None)
        self.assertEqual(sdist.classifiers, ())
        self.assertEqual(sdist.requires, ())
        self.assertEqual(sdist.provides, ())
        self.assertEqual(sdist.obsoletes, ())
        self.assertEqual(sdist.maintainer, None)
        self.assertEqual(sdist.maintainer_email, None)
        self.assertEqual(sdist.requires_python, None)
        self.assertEqual(sdist.requires_external, ())
        self.assertEqual(sdist.requires_dist, ())
        self.assertEqual(sdist.provides_dist, ())
        self.assertEqual(sdist.obsoletes_dist, ())
        self.assertEqual(sdist.project_urls, ())

    def test_extractMetadata_raises_NotImplementedError(self):
        # 'extractMetadata' calls 'read', which subclasses must override.
        dist = self._makeOne(None)
        self.assertRaises(NotImplementedError, dist.extractMetadata)

    def test_read_raises_NotImplementedError(self):
        # Subclasses must override 'read'.
        dist = self._makeOne(None)
        self.assertRaises(NotImplementedError, dist.read)

    def test_parse_Metadata_Version_1_0(self):
        from pkginfo.distribution import HEADER_ATTRS_1_0
        dist = self._makeOne(None)
        dist.parse('Metadata-Version: 1.0')
        self.assertEqual(dist.metadata_version, '1.0')
        self.assertEqual(list(dist),
                         [x[1] for x in HEADER_ATTRS_1_0])

    def test_parse_Metadata_Version_unknown(self):
        dist = self._makeOne(None)
        dist.parse('Metadata-Version: 1.3')
        self.assertEqual(dist.metadata_version, '1.3')
        self.assertEqual(list(dist), [])

    def test_parse_Metadata_Version_override(self):
        dist = self._makeOne('1.2')
        dist.parse('Metadata-Version: 1.0')
        self.assertEqual(dist.metadata_version, '1.2')

    def test_parse_Name(self):
        dist = self._makeOne()
        dist.parse('Name: foobar')
        self.assertEqual(dist.name, 'foobar')

    def test_parse_Version(self):
        dist = self._makeOne()
        dist.parse('Version: 2.1.3b5')
        self.assertEqual(dist.version, '2.1.3b5')

    def test_parse_Platform_single(self):
        dist = self._makeOne()
        dist.parse('Platform: Plan9')
        self.assertEqual(list(dist.platforms), ['Plan9'])

    def test_parse_Platform_multiple(self):
        dist = self._makeOne()
        dist.parse('Platform: Plan9\nPlatform: AIX')
        self.assertEqual(list(dist.platforms), ['Plan9', 'AIX'])

    def test_parse_Supported_Platform_single(self):
        dist = self._makeOne()
        dist.parse('Supported-Platform: Plan9')
        self.assertEqual(list(dist.supported_platforms), ['Plan9'])

    def test_parse_Supported_Platform_multiple(self):
        dist = self._makeOne()
        dist.parse('Supported-Platform: i386-win32\n'
                   'Supported-Platform: RedHat 7.2')
        self.assertEqual(list(dist.supported_platforms),
                        ['i386-win32', 'RedHat 7.2'])

    def test_parse_Summary(self):
        dist = self._makeOne()
        dist.parse('Summary: Package for foo')
        self.assertEqual(dist.summary, 'Package for foo')

    def test_parse_Description(self):
        dist = self._makeOne()
        dist.parse('Description: This package enables integration with '
                   'foo servers.')
        self.assertEqual(dist.description,
                         'This package enables integration with '
                         'foo servers.')

    def test_parse_Description_multiline(self):
        dist = self._makeOne()
        dist.parse('Description: This package enables integration with\n'
                   '        foo servers.')
        self.assertEqual(dist.description,
                         'This package enables integration with\n'
                         'foo servers.')

    def test_parse_Keywords(self):
        dist = self._makeOne()
        dist.parse('Keywords: bar foo qux')
        self.assertEqual(dist.keywords, 'bar foo qux')

    def test_parse_Home_page(self):
        dist = self._makeOne()
        dist.parse('Home-page: http://example.com/package')
        self.assertEqual(dist.home_page, 'http://example.com/package')

    def test_parse_Author(self):
        dist = self._makeOne()
        dist.parse('Author: J. Phredd Bloggs')
        self.assertEqual(dist.author, 'J. Phredd Bloggs')

    def test_parse_Author_Email(self):
        dist = self._makeOne()
        dist.parse('Author-email: phreddy@example.com')
        self.assertEqual(dist.author_email, 'phreddy@example.com')

    def test_parse_License(self):
        dist = self._makeOne()
        dist.parse('License: Poetic')
        self.assertEqual(dist.license, 'Poetic')

    # Metadata version 1.1, defined in PEP 314.
    def test_parse_Classifier_single(self):
        dist = self._makeOne('1.1')
        dist.parse('Classifier: Some :: Silly Thing')
        self.assertEqual(list(dist.classifiers), ['Some :: Silly Thing'])

    def test_parse_Classifier_multiple(self):
        dist = self._makeOne('1.1')
        dist.parse('Classifier: Some :: Silly Thing\n'
                   'Classifier: Or :: Other')
        self.assertEqual(list(dist.classifiers),
                         ['Some :: Silly Thing', 'Or :: Other'])

    def test_parse_Download_URL(self):
        dist = self._makeOne('1.1')
        dist.parse('Download-URL: '
                   'http://example.com/package/mypackage-0.1.zip')
        self.assertEqual(dist.download_url,
                         'http://example.com/package/mypackage-0.1.zip')

    def test_parse_Requires_single_wo_version(self):
        dist = self._makeOne('1.1')
        dist.parse('Requires: SpanishInquisition')
        self.assertEqual(list(dist.requires), ['SpanishInquisition'])

    def test_parse_Requires_single_w_version(self):
        dist = self._makeOne('1.1')
        dist.parse('Requires: SpanishInquisition (>=1.3)')
        self.assertEqual(list(dist.requires), ['SpanishInquisition (>=1.3)'])

    def test_parse_Requires_multiple(self):
        dist = self._makeOne('1.1')
        dist.parse('Requires: SpanishInquisition\n'
                   'Requires: SillyWalks (1.4)\n'
                   'Requires: kniggits (>=2.3,<3.0)')
        self.assertEqual(list(dist.requires),
                         ['SpanishInquisition',
                          'SillyWalks (1.4)',
                          'kniggits (>=2.3,<3.0)',
                         ])

    def test_parse_Provides_single_wo_version(self):
        dist = self._makeOne('1.1')
        dist.parse('Provides: SillyWalks')
        self.assertEqual(list(dist.provides), ['SillyWalks'])

    def test_parse_Provides_single_w_version(self):
        dist = self._makeOne('1.1')
        dist.parse('Provides: SillyWalks (1.4)')
        self.assertEqual(list(dist.provides), ['SillyWalks (1.4)'])

    def test_parse_Provides_multiple(self):
        dist = self._makeOne('1.1')
        dist.parse('Provides: SillyWalks\n'
                   'Provides: DeadlyJoke (3.1.4)')
        self.assertEqual(list(dist.provides),
                         ['SillyWalks',
                          'DeadlyJoke (3.1.4)',
                         ])

    def test_parse_Obsoletes_single_no_version(self):
        dist = self._makeOne('1.1')
        dist.parse('Obsoletes: SillyWalks')
        self.assertEqual(list(dist.obsoletes), ['SillyWalks'])

    def test_parse_Obsoletes_single_w_version(self):
        dist = self._makeOne('1.1')
        dist.parse('Obsoletes: SillyWalks (<=1.3)')
        self.assertEqual(list(dist.obsoletes), ['SillyWalks (<=1.3)'])

    def test_parse_Obsoletes_multiple(self):
        dist = self._makeOne('1.1')
        dist.parse('Obsoletes: kniggits\n'
                   'Obsoletes: SillyWalks (<=2.0)')
        self.assertEqual(list(dist.obsoletes),
                         ['kniggits',
                          'SillyWalks (<=2.0)',
                         ])


    # Metadata version 1.2, defined in PEP 345.
    def test_parse_Maintainer(self):
        dist = self._makeOne(metadata_version='1.2')
        dist.parse('Maintainer: J. Phredd Bloggs')
        self.assertEqual(dist.maintainer, 'J. Phredd Bloggs')

    def test_parse_Maintainer_Email(self):
        dist = self._makeOne(metadata_version='1.2')
        dist.parse('Maintainer-email: phreddy@example.com')
        self.assertEqual(dist.maintainer_email, 'phreddy@example.com')

    def test_parse_Requires_Python_single_spec(self):
        dist = self._makeOne('1.2')
        dist.parse('Requires-Python: >2.4')
        self.assertEqual(dist.requires_python, '>2.4')

    def test_parse_Requires_External_single_wo_version(self):
        dist = self._makeOne('1.2')
        dist.parse('Requires-External: libfoo')
        self.assertEqual(list(dist.requires_external), ['libfoo'])

    def test_parse_Requires_External_single_w_version(self):
        dist = self._makeOne('1.2')
        dist.parse('Requires-External: libfoo (>=1.3)')
        self.assertEqual(list(dist.requires_external), ['libfoo (>=1.3)'])

    def test_parse_Requires_External_multiple(self):
        dist = self._makeOne('1.2')
        dist.parse('Requires-External: libfoo\n'
                   'Requires-External: libbar (1.4)\n'
                   'Requires-External: libbaz (>=2.3,<3.0)')
        self.assertEqual(list(dist.requires_external),
                         ['libfoo',
                          'libbar (1.4)',
                          'libbaz (>=2.3,<3.0)',
                         ])


    def test_parse_Requires_Dist_single_wo_version(self):
        dist = self._makeOne('1.2')
        dist.parse('Requires-Dist: SpanishInquisition')
        self.assertEqual(list(dist.requires_dist), ['SpanishInquisition'])

    def test_parse_Requires_Dist_single_w_version(self):
        dist = self._makeOne('1.2')
        dist.parse('Requires-Dist: SpanishInquisition (>=1.3)')
        self.assertEqual(list(dist.requires_dist),
                         ['SpanishInquisition (>=1.3)'])

    def test_parse_Requires_Dist_single_w_env_marker(self):
        dist = self._makeOne('1.2')
        dist.parse("Requires-Dist: SpanishInquisition; "
                        "python_version == '1.4'")
        self.assertEqual(list(dist.requires_dist),
                         ["SpanishInquisition; python_version == '1.4'"])

    def test_parse_Requires_Dist_multiple(self):
        dist = self._makeOne('1.2')
        dist.parse("Requires-Dist: SpanishInquisition\n"
                   "Requires-Dist: SillyWalks; python_version == '1.4'\n"
                   "Requires-Dist: kniggits (>=2.3,<3.0)")
        self.assertEqual(list(dist.requires_dist),
                         ["SpanishInquisition",
                          "SillyWalks; python_version == '1.4'",
                          "kniggits (>=2.3,<3.0)",
                         ])

    def test_parse_Provides_Dist_single_wo_version(self):
        dist = self._makeOne('1.2')
        dist.parse('Provides-Dist: SillyWalks')
        self.assertEqual(list(dist.provides_dist), ['SillyWalks'])

    def test_parse_Provides_Dist_single_w_version(self):
        dist = self._makeOne('1.2')
        dist.parse('Provides-Dist: SillyWalks (1.4)')
        self.assertEqual(list(dist.provides_dist), ['SillyWalks (1.4)'])

    def test_parse_Provides_Dist_single_w_env_marker(self):
        dist = self._makeOne('1.2')
        dist.parse("Provides-Dist: SillyWalks; sys.platform == 'os2'")
        self.assertEqual(list(dist.provides_dist),
                         ["SillyWalks; sys.platform == 'os2'"])

    def test_parse_Provides_Dist_multiple(self):
        dist = self._makeOne('1.2')
        dist.parse("Provides-Dist: SillyWalks\n"
                   "Provides-Dist: SpanishInquisition; sys.platform == 'os2'\n"
                   "Provides-Dist: DeadlyJoke (3.1.4)")
        self.assertEqual(list(dist.provides_dist),
                         ["SillyWalks",
                          "SpanishInquisition; sys.platform == 'os2'",
                          "DeadlyJoke (3.1.4)",
                         ])

    def test_parse_Obsoletes_Dist_single_no_version(self):
        dist = self._makeOne('1.2')
        dist.parse('Obsoletes-Dist: SillyWalks')
        self.assertEqual(list(dist.obsoletes_dist), ['SillyWalks'])

    def test_parse_Obsoletes_Dist_single_w_version(self):
        dist = self._makeOne('1.2')
        dist.parse('Obsoletes-Dist: SillyWalks (<=1.3)')
        self.assertEqual(list(dist.obsoletes_dist), ['SillyWalks (<=1.3)'])

    def test_parse_Obsoletes_Dist_single_w_env_marker(self):
        dist = self._makeOne('1.2')
        dist.parse("Obsoletes-Dist: SillyWalks; sys.platform == 'os2'")
        self.assertEqual(list(dist.obsoletes_dist),
                         ["SillyWalks; sys.platform == 'os2'"])

    def test_parse_Obsoletes_Dist_multiple(self):
        dist = self._makeOne('1.2')
        dist.parse("Obsoletes-Dist: kniggits\n"
                   "Obsoletes-Dist: SillyWalks; sys.platform == 'os2'\n"
                   "Obsoletes-Dist: DeadlyJoke (<=2.0)\n"
                  )
        self.assertEqual(list(dist.obsoletes_dist),
                         ["kniggits",
                          "SillyWalks; sys.platform == 'os2'",
                          "DeadlyJoke (<=2.0)",
                         ])

    def test_parse_Project_URL_single_no_version(self):
        dist = self._makeOne('1.2')
        dist.parse('Project-URL: Bug tracker, http://bugs.example.com/grail')
        self.assertEqual(list(dist.project_urls),
                         ['Bug tracker, http://bugs.example.com/grail'])

    def test_parse_Project_URL_multiple(self):
        dist = self._makeOne('1.2')
        dist.parse('Project-URL: Bug tracker, http://bugs.example.com/grail\n'
                   'Project-URL: Repository, http://svn.example.com/grail')
        self.assertEqual(list(dist.project_urls),
                         ['Bug tracker, http://bugs.example.com/grail',
                          'Repository, http://svn.example.com/grail',
                         ])

    def test_parse_given_unicode(self):
        from pkginfo._compat import u
        dist = self._makeOne()
        dist.parse(u('Metadata-Version: 1.0\nName: lp722928_c3')) # no raise