comparison test/test_packager.py @ 84:98a7d70746a9

Make BinaryPackager remove all files that do not belong to the binary package from the pkg/<rev>/binary directory after pbuilder finished. Also, add tests for this and some corresponding test support code.
author Bernhard Herzog <bh@intevation.de>
date Mon, 10 Sep 2007 17:13:33 +0000
parents
children 31b0567df051
comparison
equal deleted inserted replaced
83:83e48a76f759 84:98a7d70746a9
1 # Copyright (C) 2007 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 """Tests for treepkg.packager"""
9
10 import sys
11 import os
12 import unittest
13
14 from treepkg.run import call
15 from treepkg.cmdexpand import cmdexpand
16 from treepkg.util import writefile
17 from treepkg.packager import PackagerGroup
18 import treepkg.subversion as subversion
19 import treepkg
20
21 from filesupport import FileTestMixin
22
23
24 def create_svn_repository(directory):
25 baseurl = "file://" + directory
26 call(cmdexpand("svnadmin create --fs-type fsfs $directory",
27 **locals()))
28 call(cmdexpand("svn mkdir -q -m 'create directory structure'"
29 " $baseurl/trunk",
30 **locals()))
31 return baseurl
32
33 def add_svn_files(workingcopy, filedesc, commitmsg):
34 for name, contents in filedesc:
35 writefile(os.path.join(workingcopy, name), contents)
36 call(cmdexpand("svn add -q $name", **locals()),
37 cwd=workingcopy)
38 call(cmdexpand("svn commit -q -m $commitmsg", **locals()),
39 cwd=workingcopy)
40
41
42 class SourcePackager(treepkg.packager.SourcePackager):
43
44 pkg_basename = "testpkg"
45
46 def do_package(self):
47 pkgbaseversion, pkgbasedir = self.export_sources()
48
49 pkgbasename = self.pkg_basename + "_" + pkgbaseversion
50 origtargz = os.path.join(self.work_dir,
51 pkgbasename + ".orig.tar.gz")
52 self.create_tarball(origtargz, self.work_dir,
53 os.path.basename(pkgbasedir))
54
55 changemsg = ("Update to SVN rev. %d" % (self.revision,))
56 self.copy_debian_directory(pkgbasedir, pkgbaseversion,
57 changemsg)
58
59 self.create_source_package(pkgbasedir, origtargz)
60 self.move_source_package(pkgbasename)
61
62
63 class RevisionPackager(treepkg.packager.RevisionPackager):
64
65 source_packager_cls = SourcePackager
66
67
68 class PackageTrack(treepkg.packager.PackageTrack):
69
70 revision_packager_cls = RevisionPackager
71
72
73 class TestPackager(unittest.TestCase, FileTestMixin):
74
75 initial_files = [
76 ("README", "and miles to go before I sleep"),
77 ]
78
79 debian_files = [
80 ("debian",
81 [("control", """\
82 Source: testpkg
83 Priority: optional
84 Maintainer: TreePKG <treepkg@example.com>
85 Standards-Version: 3.7.2
86
87 Package: testpkg
88 Architecture: all
89 Description: Test package for treepkg testsGerman (de) internationalized (i18n) files for KDE
90 This package contains the German internationalized (i18n) files for
91 all KDE core applications.
92 """),
93 ("changelog", """\
94 testpkg (0-0) unstable; urgency=low
95
96 * Initial version
97
98 -- TreePKG <treepkg@example.com> Thu, 8 Mar 2007 18:34:39 +0100
99 """),
100 ("rules", "binary: echo binary")])]
101
102 def setUp(self):
103 self.svndir = self.create_temp_dir(self.id() + "-svn")
104 self.svnworkdir = self.create_temp_dir(self.id() + "-svnwork")
105 self.trackdir = self.create_temp_dir(self.id() + "-track")
106 self.create_files(self.trackdir, self.debian_files)
107
108 def test(self):
109 baseurl = create_svn_repository(self.svndir)
110 svn_url = baseurl + "/trunk"
111 subversion.checkout(svn_url, self.svnworkdir)
112 add_svn_files(self.svnworkdir, self.initial_files,
113 "Initial version")
114 rootcmd = os.path.join(os.path.dirname(__file__), os.pardir, "test",
115 "mocksudopbuilder.py")
116 track = PackageTrack(name="testpkg", base_dir=self.trackdir,
117 svn_url=svn_url, pbuilderrc="",
118 root_cmd=[sys.executable, rootcmd],
119 deb_email="treepkg@example.com",
120 deb_fullname="treepkg tester")
121 group = PackagerGroup([track], 1)
122 group.check_package_tracks()
123
124 # Now check the source and binary package files
125 pkgdir = os.path.join(self.trackdir, "pkg", "2-1")
126 self.assertEquals(sorted(os.listdir(os.path.join(pkgdir, "src"))),
127 ["testpkg_2-kk1.diff.gz",
128 "testpkg_2-kk1.dsc",
129 "testpkg_2.orig.tar.gz"])
130 self.assertEquals(sorted(os.listdir(os.path.join(pkgdir, "binary"))),
131 ["testpkg_2-kk1_all.deb",
132 "testpkg_2-kk1_i386.changes"])
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)