comparison test/test_listpackages.py @ 246:59e2d8e26635

Extend --revision parameter of bin/listpackages.py to accept rules revision too. Add test cases for listpackages.
author Bernhard Herzog <bh@intevation.de>
date Fri, 06 Mar 2009 19:21:56 +0000
parents
children 5dd710b167d2
comparison
equal deleted inserted replaced
245:21da92cea416 246:59e2d8e26635
1 # Copyright (C) 2009 by Intevation GmbH
2 # Authors:
3 # Bernhard Herzog <bh@intevation.de>
4 #
5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with the software for details.
7
8
9 import sys
10 import os
11 import difflib
12 import unittest
13
14 from filesupport import FileTestMixin
15
16 from treepkg.run import call, capture_output, SubprocessError
17
18
19 def package_track_files(track, version, binaries, revisions):
20 src_templates = ["%s_%s.%%s%s" % (track, version, suffix)
21 for suffix in [".orig.tar.gz", "-1.diff.gz", "-1.dsc"]]
22 bin_templates = ["%s_%s.%%s-1_i386.deb" % (basename, version)
23 for basename in binaries]
24 return (track,
25 [("pkg", [("%s-%s" % (rev, rules_rev),
26 [("status", "TreePackagerStatus 0.0\n"),
27 ("src", [(template % (rev,), "")
28 for template in src_templates]),
29 ("binary", [(template % (rev,), "")
30 for template in bin_templates])])
31 for rev, rules_rev in revisions])])
32
33 class ListPackagesTest(unittest.TestCase, FileTestMixin):
34
35 treepkg_cfg_template = """\
36 [DEFAULT]
37 tracks_dir: %(tracksdir)s
38 root_cmd: true
39 pbuilderrc:
40 deb_email: packager@example.com
41 deb_fullname: Sample Packager
42 debrevision_prefix: treepkg
43 handle_dependencies: False
44
45 [treepkg]
46 check_interval: 3600
47 instructions_file:
48
49 [pkg_kdepim]
50 svn_url: svn://anonsvn.kde.org/home/kde/branches/kdepim/enterprise/kdepim
51 base_dir: %%(tracks_dir)s/kdepim
52 packager_class: recipes.kde_enterprise_3_5.kdepim
53
54 [pkg_kdepimlibs]
55 svn_url: svn://anonsvn.kde.org/home/kde/branches/kdepim/enterprise/kdepimlibs
56 base_dir: %%(tracks_dir)s/kdepimlibs
57 packager_class: recipes.kde_enterprise_3_5.kdepim
58 """
59
60 track_files = []
61
62 def setUp(self):
63 self.bindir = os.path.join(os.path.dirname(__file__),
64 os.pardir, "bin")
65 self.listpackages = os.path.join(self.bindir, "listpackages.py")
66 self.tracksdir = self.create_files("tracks", self.track_files)
67 config = self.treepkg_cfg_template % dict(tracksdir=self.tracksdir)
68 self.config_file = self.create_temp_file("treepkg.cfg", config)
69 self.base_command = [sys.executable, self.listpackages,
70 "--config-file=" + self.config_file]
71
72 def run_command(self, extra_args, expected_exit_code=0):
73 cmd = self.base_command + list(extra_args)
74 try:
75 output = capture_output(cmd)
76 except SubprocessError, exc:
77 if expected_exit_code != exc.returncode:
78 raise
79 output = exc.output
80 return output
81
82 def check_cmd(self, args, expected):
83 expected_lines = [os.path.join(self.tracksdir, filename) + "\n"
84 for filename in expected.splitlines()]
85 try:
86 output_lines = [line + "\n"
87 for line in self.run_command(args).splitlines()]
88 except SubprocessError, exc:
89 print >>sys.stderr, "Unexpected output:", exc.output
90 raise
91
92 # the order of the listed packages doesn't matter, so sort the
93 # lists before comparing them
94 expected_lines.sort()
95 output_lines.sort()
96
97 if expected_lines != output_lines:
98 diff = difflib.unified_diff(expected_lines, output_lines,
99 "expected", "found")
100 raise self.failureException("\n" + "".join(diff))
101
102
103 class TestListPackagesTrackNoRevision(ListPackagesTest):
104
105 track_files = [package_track_files("kdepim", "1.0.1",
106 ["kdepim", "kleopatra"],
107 [(704195, 31), (702432, 47)])]
108
109 def test_listpackages_source(self):
110 self.check_cmd(["--track=kdepim", "--source"],
111 """\
112 kdepim/pkg/704195-31/src/kdepim_1.0.1.704195-1.diff.gz
113 kdepim/pkg/704195-31/src/kdepim_1.0.1.704195-1.dsc
114 kdepim/pkg/704195-31/src/kdepim_1.0.1.704195.orig.tar.gz
115 """)
116
117 def test_listpackages_binary(self):
118 self.check_cmd(["--track=kdepim", "--binary"],
119 """\
120 kdepim/pkg/704195-31/binary/kdepim_1.0.1.704195-1_i386.deb
121 kdepim/pkg/704195-31/binary/kleopatra_1.0.1.704195-1_i386.deb
122 """)
123
124
125 class TestListPackagesNoTrackNoRevision(ListPackagesTest):
126
127 track_files = [package_track_files("kdepim", "1.0.1",
128 ["kdepim", "kleopatra"],
129 [(704195, 31), (702432, 47)]),
130 package_track_files("kdepimlibs", "1.0.1",
131 ["kdepimlibs"],
132 [(803691, 4321), (803692, 4322)]),
133 ]
134
135 def test_listpackages_source(self):
136 self.check_cmd(["--source"],
137 """\
138 kdepim/pkg/704195-31/src/kdepim_1.0.1.704195-1.diff.gz
139 kdepim/pkg/704195-31/src/kdepim_1.0.1.704195-1.dsc
140 kdepim/pkg/704195-31/src/kdepim_1.0.1.704195.orig.tar.gz
141 kdepimlibs/pkg/803692-4322/src/kdepimlibs_1.0.1.803692-1.diff.gz
142 kdepimlibs/pkg/803692-4322/src/kdepimlibs_1.0.1.803692-1.dsc
143 kdepimlibs/pkg/803692-4322/src/kdepimlibs_1.0.1.803692.orig.tar.gz""")
144
145 def test_listpackages_binary(self):
146 self.check_cmd(["--binary"],
147 """\
148 kdepim/pkg/704195-31/binary/kdepim_1.0.1.704195-1_i386.deb
149 kdepim/pkg/704195-31/binary/kleopatra_1.0.1.704195-1_i386.deb
150 kdepimlibs/pkg/803692-4322/binary/kdepimlibs_1.0.1.803692-1_i386.deb""")
151
152
153 class TestListPackagesTrackRevision(ListPackagesTest):
154
155 track_files = [package_track_files("kdepim", "1.0.1",
156 ["kdepim", "kleopatra"],
157 [(704195, 31), (702432, 47)]),
158 package_track_files("kdepimlibs", "1.0.1",
159 ["kdepimlibs"],
160 [(803691, 4321), (803692, 4322)]),
161 ]
162
163 def test_listpackages_source(self):
164 self.check_cmd(["--source", "--track=kdepim", "--revision=702432"],
165 """\
166 kdepim/pkg/702432-47/src/kdepim_1.0.1.702432-1.diff.gz
167 kdepim/pkg/702432-47/src/kdepim_1.0.1.702432-1.dsc
168 kdepim/pkg/702432-47/src/kdepim_1.0.1.702432.orig.tar.gz""")
169
170 def test_listpackages_binary(self):
171 self.check_cmd(["--binary", "--track=kdepim", "--revision=702432"],
172 """\
173 kdepim/pkg/702432-47/binary/kdepim_1.0.1.702432-1_i386.deb
174 kdepim/pkg/702432-47/binary/kleopatra_1.0.1.702432-1_i386.deb""")
175
176
177
178 class TestListPackagesMultipleRulesRevisions(ListPackagesTest):
179
180 track_files = [package_track_files("kdepim", "1.0.1",
181 ["kdepim", "kleopatra"],
182 [(704195, 31), (704195, 33),
183 (702432, 47)]),
184 package_track_files("kdepimlibs", "1.0.1",
185 ["kdepimlibs"],
186 [(803691, 4321), (803692, 4322)]),
187 ]
188
189 def test_listpackages_source_no_rev(self):
190 self.check_cmd(["--source", "--track=kdepim"],
191 """\
192 kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.diff.gz
193 kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.dsc
194 kdepim/pkg/704195-33/src/kdepim_1.0.1.704195.orig.tar.gz""")
195
196 def test_listpackages_binary_no_rev(self):
197 self.check_cmd(["--binary", "--track=kdepim"],
198 """\
199 kdepim/pkg/704195-33/binary/kdepim_1.0.1.704195-1_i386.deb
200 kdepim/pkg/704195-33/binary/kleopatra_1.0.1.704195-1_i386.deb""")
201
202 def test_listpackages_source_and_binary_no_rev(self):
203 self.check_cmd(["--source", "--track=kdepim", "--binary"],
204 """\
205 kdepim/pkg/704195-33/binary/kdepim_1.0.1.704195-1_i386.deb
206 kdepim/pkg/704195-33/binary/kleopatra_1.0.1.704195-1_i386.deb
207 kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.diff.gz
208 kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.dsc
209 kdepim/pkg/704195-33/src/kdepim_1.0.1.704195.orig.tar.gz
210 """)
211
212 def test_listpackages_source_no_rulesrev(self):
213 self.check_cmd(["--source", "--track=kdepim", "--revision=704195"],
214 """\
215 kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.diff.gz
216 kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.dsc
217 kdepim/pkg/704195-33/src/kdepim_1.0.1.704195.orig.tar.gz""")
218
219 def test_listpackages_binary_no_rulesrev(self):
220 self.check_cmd(["--binary", "--track=kdepim", "--revision=704195"],
221 """\
222 kdepim/pkg/704195-33/binary/kdepim_1.0.1.704195-1_i386.deb
223 kdepim/pkg/704195-33/binary/kleopatra_1.0.1.704195-1_i386.deb""")
224
225 def test_listpackages_source_rulesrev(self):
226 self.check_cmd(["--source", "--track=kdepim", "--revision=704195-31"],
227 """\
228 kdepim/pkg/704195-31/src/kdepim_1.0.1.704195-1.diff.gz
229 kdepim/pkg/704195-31/src/kdepim_1.0.1.704195-1.dsc
230 kdepim/pkg/704195-31/src/kdepim_1.0.1.704195.orig.tar.gz""")
231
232 def test_listpackages_binary_rulesrev(self):
233 self.check_cmd(["--binary", "--track=kdepim", "--revision=704195-31"],
234 """\
235 kdepim/pkg/704195-31/binary/kdepim_1.0.1.704195-1_i386.deb
236 kdepim/pkg/704195-31/binary/kleopatra_1.0.1.704195-1_i386.deb""")
237
238
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)