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
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
test_elpa_db.py
~~~~~~~~~~~~~~~
ELPA package database test suite
:copyright: (c) 2013 by Jauhien Piatlicki
:license: GPL-2, see LICENSE for more details.
"""
import os
import unittest
from g_elpa import elpa_db
from g_sorcery import exceptions, package_db
from tests.server import Server
from tests.base import BaseTest
def generate_archive_contents(packages):
archive_contents = "(1"
for pkg in packages:
archive_contents += "\n(" + pkg[0] + ' . [('
for v in pkg[1]:
archive_contents += ' ' + str(v)
archive_contents += ')\n'
if pkg[4]:
archive_contents += '('
for p in pkg[4]:
archive_contents += '(' + p[0] + ' ('
for v in p[1]:
archive_contents += ' ' + str(v)
archive_contents += '))\n'
archive_contents += ')'
else:
archive_contents += 'nil'
archive_contents += '\n "' + pkg[2] + '" ' + pkg[3] + '])'
archive_contents += ')'
return archive_contents
packages = [['ack', [1, 2],
"Interface to ack-like source code search tools",
"tar",
[]
],
['dict-tree', [0, 12, 8],
"Dictionary data structure",
"tar",
[['trie', [0, 2, 5]],
['tNFA', [0, 1, 1]],
['heap', [0, 3]]]
],
['tNFA', [0, 1, 1],
"Tagged non-deterministic finite-state automata",
"single",
[['queue', [0, 1]]]
],
['trie', [0, 2, 6],
"Trie data structure",
"single",
[['tNFA', [0, 1, 1]],
['queue', [0, 1]]]
],
['heap', [0, 3],
"Heap (a.k.a. priority queue) data structure",
"single",
[]
],
['queue', [0, 1],
"Queue data structure",
"single",
[]
]
]
def fill_database(database, packages, tempdir):
prev = os.getcwd()
os.chdir(tempdir)
archive_contents = generate_archive_contents(packages)
with open(os.path.join(tempdir, 'archive-contents'), 'w') as f:
f.write(archive_contents)
server = Server()
server.start()
database.generate()
server.shutdown()
server.join()
os.chdir(prev)
class TestElpaDB(BaseTest):
def test_generate(self):
edb = elpa_db.ElpaDB(os.path.join(self.tempdir.name, 'db'),
repo_uri = 'http://127.0.0.1:8080')
self.assertRaises(exceptions.DownloadingError, edb.generate)
fill_database(edb, packages, self.tempdir.name)
for pkg in packages:
package = package_db.Package('app-emacs',
pkg[0],
'.'.join(map(str, pkg[1])))
description = edb.get_package_description(package)
self.assertEqual(description['source_type'], pkg[3])
self.assertEqual(description['description'], pkg[2])
deps = []
depend=[]
for d in pkg[4]:
deps.append(package_db.Package('app-emacs',
d[0],
'.'.join(map(str, d[1]))))
depend.append('app-emacs' + '/' + d[0])
dependencies = description['dependencies']
for d in dependencies:
self.assertTrue(d in deps)
for d in deps:
self.assertTrue(d in dependencies)
for ds in (description['depend'], description['rdepend']):
for d in ds:
self.assertTrue(d in depend)
for d in depend:
self.assertTrue(d in ds)
def suite():
suite = unittest.TestSuite()
suite.addTest(TestElpaDB('test_generate'))
return suite
|