aboutsummaryrefslogtreecommitdiff
path: root/python/metadata_key_TEST.py
blob: a13ed6b5412a52188535178fbc6ff701f614eebc (plain)
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#!/usr/bin/env python
# vim: set fileencoding=utf-8 sw=4 sts=4 et :

#
# Copyright (c) 2007 Piotr JaroszyƄski
#
# This file is part of the Paludis package manager. Paludis is free software;
# you can redistribute it and/or modify it under the terms of the GNU General
# Public License version 2, as published by the Free Software Foundation.
#
# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA  02111-1307  USA
#

import os

repo_path = os.path.join(os.getcwd(), "metadata_key_TEST_dir/testrepo")
irepo_path = os.path.join(os.getcwd(), "metadata_key_TEST_dir/installed")

from paludis import *
from additional_tests import *

import unittest

Log.instance.log_level = LogLevel.WARNING

class TestCase_01_MetadataKeys(unittest.TestCase):
    def setUp(self):
        self.e = NoConfigEnvironment(repo_path, "/var/empty")
        self.ie = NoConfigEnvironment(irepo_path)
        self.pid = iter(self.e.package_database.fetch_repository("testrepo").package_ids("foo/bar")).next()
        self.ipid = iter(self.ie.package_database.fetch_repository("installed").package_ids("cat-one/pkg-one")).next()

    def test_01_contents(self):
        self.assertEquals(self.pid.find_metadata("CONTENTS"), None)
        self.assert_(isinstance(self.ipid.find_metadata("CONTENTS"), MetadataContentsKey))

    def test_02_installed_time(self):
        self.assertEquals(self.pid.find_metadata("INSTALLED_TIME"), None)
        self.assert_(isinstance(self.ipid.find_metadata("INSTALLED_TIME"), MetadataTimeKey))

    def test_03_repository(self):
        self.assertEquals(self.pid.find_metadata("REPOSITORIES"), None)
        self.assert_(isinstance(self.ipid.find_metadata("REPOSITORIES"), MetadataStringIterableKey))

    def test_04_keywords(self):
        self.assert_(isinstance(self.pid.find_metadata("KEYWORDS"), MetadataKeywordNameIterableKey))
        self.assertEquals(self.ipid.find_metadata("KEYWORDS"), None)

    def test_07_inherited(self):
        self.assert_(isinstance(self.pid.find_metadata("INHERITED"), MetadataStringIterableKey))
        self.assert_(isinstance(self.ipid.find_metadata("INHERITED"), MetadataStringIterableKey))

    def test_08_depend(self):
        self.assert_(isinstance(self.pid.find_metadata("DEPEND"), MetadataDependencySpecTreeKey))
        self.assertEquals(self.ipid.find_metadata("DEPEND"), None)

    def test_011_choices(self):
        self.assert_(isinstance(self.pid.find_metadata("PALUDIS_CHOICES"), MetadataChoicesKey))
        self.assert_(isinstance(self.ipid.find_metadata("PALUDIS_CHOICES"), MetadataChoicesKey))

class TestCase_02_MetadataKeys_suclassing(unittest.TestCase):
    def test_01_package_id(self):
        class TestKey(MetadataPackageIDKey):
            def __init__(self):
                MetadataPackageIDKey.__init__(self)

            def value(self):
                e = NoConfigEnvironment(repo_path, "/var/empty")
                pid = iter(e.package_database.fetch_repository("testrepo").package_ids("foo/bar")).next()
                return pid

            def raw_name(self):
                return "raw"

            def human_name(self):
                return "human"

            def type(self):
                return MetadataKeyType.NORMAL

        test_metadata_package_id_key(TestKey())

    def test_02_string(self):
        class TestKey(MetadataStringKey):
            def __init__(self):
                MetadataStringKey.__init__(self)

            def value(self):
                return "str"

            def raw_name(self):
                return "raw"

            def human_name(self):
                return "human"

            def type(self):
                return MetadataKeyType.NORMAL

        test_metadata_string_key(TestKey())

    def test_03_time(self):
        class TestKey(MetadataTimeKey):
            def __init__(self):
                MetadataTimeKey.__init__(self)

            def value(self):
                return 123

            def raw_name(self):
                return "raw"

            def human_name(self):
                return "human"

            def type(self):
                return MetadataKeyType.NORMAL

        test_metadata_time_key(TestKey())


    def test_04_contents(self):
        class TestKey(MetadataContentsKey):
            def __init__(self):
                MetadataContentsKey.__init__(self)

            def value(self):
                return Contents()

            def raw_name(self):
                return "raw"

            def human_name(self):
                return "human"

            def type(self):
                return MetadataKeyType.NORMAL

        test_metadata_contents_key(TestKey())

    def test_06_keyword_name_iterable(self):
        class TestKey(MetadataKeywordNameIterableKey):
            def __init__(self):
                MetadataKeywordNameIterableKey.__init__(self)

            def value(self):
                return ["keyword"]

            def pretty_print_flat(self, f):
                return f.format_keyword_name_plain(KeywordName("foo"))

            def raw_name(self):
                return "raw"

            def human_name(self):
                return "human"

            def type(self):
                return MetadataKeyType.NORMAL

        test_metadata_keyword_name_set_key(TestKey())


    def test_09_string_iterable(self):
        class TestKey(MetadataStringIterableKey):
            def __init__(self):
                MetadataStringIterableKey.__init__(self)

            def value(self):
                return ["string"]

            def pretty_print_flat(self, f):
                return f.format_string_plain("foo")

            def raw_name(self):
                return "raw"

            def human_name(self):
                return "human"

            def type(self):
                return MetadataKeyType.NORMAL

        test_metadata_string_set_key(TestKey())

    def test_10_license_spec_tree(self):
        class TestKey(MetadataLicenseSpecTreeKey):
            def __init__(self):
                MetadataLicenseSpecTreeKey.__init__(self)

            def value(self):
                return AllDepSpec()

            def pretty_print(self, f):
                #TODO
                #return f.format_use_dep_spec_plain(...)
                return "str"

            def pretty_print_flat(self, f):
                #TODO
                #return f.format_use_dep_spec_plain(...)
                return "str"

            def raw_name(self):
                return "raw"

            def human_name(self):
                return "human"

            def type(self):
                return MetadataKeyType.NORMAL

        test_metadata_license_spec_tree_key(TestKey())

    def test_11_provide_spec_tree(self):
        class TestKey(MetadataProvideSpecTreeKey):
            def __init__(self):
                MetadataProvideSpecTreeKey.__init__(self)
                self.e = NoConfigEnvironment(repo_path, "/var/empty")

            def value(self):
                return AllDepSpec()

            def pretty_print(self, f):
                pds = parse_user_package_dep_spec("cat/pkg", self.e, [])
                return f.format_package_dep_spec_plain(pds)

            def pretty_print_flat(self, f):
                pds = parse_user_package_dep_spec("cat/pkg", self.e, [])
                return f.format_package_dep_spec_plain(pds)

            def raw_name(self):
                return "raw"

            def human_name(self):
                return "human"

            def type(self):
                return MetadataKeyType.NORMAL

        test_metadata_provide_spec_tree_key(TestKey())

    def test_12_dependency_spec_tree(self):
        class TestKey(MetadataDependencySpecTreeKey):
            def __init__(self):
                self.e = NoConfigEnvironment(repo_path, "/var/empty")
                MetadataDependencySpecTreeKey.__init__(self)

            def value(self):
                return AllDepSpec()

            def pretty_print(self, f):
                pds = parse_user_package_dep_spec("cat/pkg", self.e, [])
                return f.format_package_dep_spec_plain(pds)

            def pretty_print_flat(self, f):
                pds = parse_user_package_dep_spec("cat/pkg", self.e, [])
                return f.format_package_dep_spec_plain(pds)

            def raw_name(self):
                return "raw"

            def human_name(self):
                return "human"

            def type(self):
                return MetadataKeyType.NORMAL

        test_metadata_dependency_spec_tree_key(TestKey())


    def test_13_plain_text_spec_tree(self):
        class TestKey(MetadataPlainTextSpecTreeKey):
            def __init__(self):
                MetadataPlainTextSpecTreeKey.__init__(self)

            def value(self):
                return AllDepSpec()

            def pretty_print(self, f):
                #TODO
                #return f.format_plain_text_dep_spec_plain(PlainTextDepSpec("foo"))
                return "str"

            def pretty_print_flat(self, f):
                #TODO
                #return f.format_plain_text_dep_spec_plain(PlainTextDepSpec("foo"))
                return "str"

            def raw_name(self):
                return "raw"

            def human_name(self):
                return "human"

            def type(self):
                return MetadataKeyType.NORMAL

        test_metadata_plain_text_spec_tree_key(TestKey())

    def test_14_fetchable_uri_spec_tree(self):
        class TestKey(MetadataFetchableURISpecTreeKey):
            def __init__(self):
                MetadataFetchableURISpecTreeKey.__init__(self)

            def value(self):
                return AllDepSpec()

            def pretty_print(self, f):
                #TODO
                #return f.format_use_dep_spec_plain(...)
                return "str"

            def pretty_print_flat(self, f):
                #TODO
                #return f.format_use_dep_spec_plain(...)
                return "str"

            def initial_label(self):
                return URIMirrorsOnlyLabel("foo")

            def raw_name(self):
                return "raw"

            def human_name(self):
                return "human"

            def type(self):
                return MetadataKeyType.NORMAL

        test_metadata_fetchable_uri_spec_tree_key(TestKey())

    def test_15_simple_uri_spec_tree(self):
        class TestKey(MetadataSimpleURISpecTreeKey):
            def __init__(self):
                MetadataSimpleURISpecTreeKey.__init__(self)

            def value(self):
                return AllDepSpec()

            def pretty_print(self, f):
                #TODO
                #return f.format_use_dep_spec_plain(...)
                return "str"

            def pretty_print_flat(self, f):
                #TODO
                #return f.format_use_dep_spec_plain(...)
                return "str"

            def raw_name(self):
                return "raw"

            def human_name(self):
                return "human"

            def type(self):
                return MetadataKeyType.NORMAL

        test_metadata_simple_uri_spec_tree_key(TestKey())

    def test_16_section(self):
        class TestKey(MetadataSectionKey):
            def __init__(self):
                MetadataSectionKey.__init__(self)

            def need_keys_added(self):
                return

            def title_key(self):
                return None

            def raw_name(self):
                return "raw"

            def human_name(self):
                return "human"

            def type(self):
                return MetadataKeyType.NORMAL

        test_metadata_section_key(TestKey())

    def test_17_choices(self):
        class TestKey(MetadataChoicesKey):
            def __init__(self):
                MetadataChoicesKey.__init__(self)

            def value(self):
                return Choices()

            def raw_name(self):
                return "raw"

            def human_name(self):
                return "human"

            def type(self):
                return MetadataKeyType.NORMAL

        test_metadata_choices_key(TestKey())


if __name__ == "__main__":
    unittest.main()