bh@84: # Copyright (C) 2007 by Intevation GmbH bh@84: # Authors: bh@84: # Bernhard Herzog bh@84: # bh@84: # This program is free software under the GPL (>=v2) bh@84: # Read the file COPYING coming with the software for details. bh@84: bh@84: """Tests for treepkg.packager""" bh@84: bh@84: import sys bh@84: import os bh@84: import unittest bh@84: bh@84: from treepkg.run import call bh@84: from treepkg.cmdexpand import cmdexpand bh@84: from treepkg.util import writefile bh@84: from treepkg.packager import PackagerGroup bh@84: import treepkg.subversion as subversion bh@84: import treepkg bh@84: bh@84: from filesupport import FileTestMixin bh@84: bh@84: bh@84: def create_svn_repository(directory): bh@84: baseurl = "file://" + directory bh@84: call(cmdexpand("svnadmin create --fs-type fsfs $directory", bh@84: **locals())) bh@84: call(cmdexpand("svn mkdir -q -m 'create directory structure'" bh@84: " $baseurl/trunk", bh@84: **locals())) bh@84: return baseurl bh@84: bh@84: def add_svn_files(workingcopy, filedesc, commitmsg): bh@84: for name, contents in filedesc: bh@84: writefile(os.path.join(workingcopy, name), contents) bh@84: call(cmdexpand("svn add -q $name", **locals()), bh@84: cwd=workingcopy) bh@84: call(cmdexpand("svn commit -q -m $commitmsg", **locals()), bh@84: cwd=workingcopy) bh@84: bh@84: bh@84: class SourcePackager(treepkg.packager.SourcePackager): bh@84: bh@84: pkg_basename = "testpkg" bh@84: bh@84: def do_package(self): bh@84: pkgbaseversion, pkgbasedir = self.export_sources() bh@84: bh@84: pkgbasename = self.pkg_basename + "_" + pkgbaseversion bh@84: origtargz = os.path.join(self.work_dir, bh@84: pkgbasename + ".orig.tar.gz") bh@84: self.create_tarball(origtargz, self.work_dir, bh@84: os.path.basename(pkgbasedir)) bh@84: bh@84: changemsg = ("Update to SVN rev. %d" % (self.revision,)) bh@84: self.copy_debian_directory(pkgbasedir, pkgbaseversion, bh@84: changemsg) bh@84: bh@84: self.create_source_package(pkgbasedir, origtargz) bh@84: self.move_source_package(pkgbasename) bh@84: bh@84: bh@84: class RevisionPackager(treepkg.packager.RevisionPackager): bh@84: bh@84: source_packager_cls = SourcePackager bh@84: bh@84: bh@84: class PackageTrack(treepkg.packager.PackageTrack): bh@84: bh@84: revision_packager_cls = RevisionPackager bh@84: bh@84: bh@84: class TestPackager(unittest.TestCase, FileTestMixin): bh@84: bh@84: initial_files = [ bh@84: ("README", "and miles to go before I sleep"), bh@84: ] bh@84: bh@84: debian_files = [ bh@84: ("debian", bh@84: [("control", """\ bh@84: Source: testpkg bh@84: Priority: optional bh@84: Maintainer: TreePKG bh@84: Standards-Version: 3.7.2 bh@84: bh@84: Package: testpkg bh@84: Architecture: all bh@84: Description: Test package for treepkg testsGerman (de) internationalized (i18n) files for KDE bh@84: This package contains the German internationalized (i18n) files for bh@84: all KDE core applications. bh@84: """), bh@84: ("changelog", """\ bh@84: testpkg (0-0) unstable; urgency=low bh@84: bh@84: * Initial version bh@84: bh@84: -- TreePKG Thu, 8 Mar 2007 18:34:39 +0100 bh@84: """), bh@84: ("rules", "binary: echo binary")])] bh@84: bh@84: def setUp(self): bh@84: self.svndir = self.create_temp_dir(self.id() + "-svn") bh@84: self.svnworkdir = self.create_temp_dir(self.id() + "-svnwork") bh@84: self.trackdir = self.create_temp_dir(self.id() + "-track") bh@84: self.create_files(self.trackdir, self.debian_files) bh@84: bh@84: def test(self): bh@84: baseurl = create_svn_repository(self.svndir) bh@84: svn_url = baseurl + "/trunk" bh@84: subversion.checkout(svn_url, self.svnworkdir) bh@84: add_svn_files(self.svnworkdir, self.initial_files, bh@84: "Initial version") bh@84: rootcmd = os.path.join(os.path.dirname(__file__), os.pardir, "test", bh@84: "mocksudopbuilder.py") bh@84: track = PackageTrack(name="testpkg", base_dir=self.trackdir, bh@84: svn_url=svn_url, pbuilderrc="", bh@84: root_cmd=[sys.executable, rootcmd], bh@84: deb_email="treepkg@example.com", bh@84: deb_fullname="treepkg tester") bh@84: group = PackagerGroup([track], 1) bh@84: group.check_package_tracks() bh@84: bh@84: # Now check the source and binary package files bh@84: pkgdir = os.path.join(self.trackdir, "pkg", "2-1") bh@84: self.assertEquals(sorted(os.listdir(os.path.join(pkgdir, "src"))), bh@84: ["testpkg_2-kk1.diff.gz", bh@84: "testpkg_2-kk1.dsc", bh@84: "testpkg_2.orig.tar.gz"]) bh@84: self.assertEquals(sorted(os.listdir(os.path.join(pkgdir, "binary"))), bh@84: ["testpkg_2-kk1_all.deb", bh@84: "testpkg_2-kk1_i386.changes"]) bh@85: bh@85: bh@85: class TestPackageTrack(unittest.TestCase, FileTestMixin): bh@85: bh@85: track_files = [("pkg", bh@85: [("704195-1", bh@85: [("status", ""), bh@85: ("src", []), bh@85: ("binary", [])]), bh@85: # Note: The revisions are not ordered so that we bh@85: # can check whether get_revision_numbers returns a bh@85: # sorted list of revisions bh@85: ("702432-1", bh@85: [("status", ""), bh@85: ("src", []), bh@85: ("binary", [])])])] bh@85: bh@85: def setUp(self): bh@85: self.trackdir = self.create_temp_dir(self.id() + "-track") bh@85: self.create_files(self.trackdir, self.track_files) bh@85: bh@85: def test_get_revision_numbers(self): bh@85: track = PackageTrack("testtrack", self.trackdir, "", "", "", "", "") bh@85: self.assertEquals(track.get_revision_numbers(), [702432, 704195])