view test/test_packager.py @ 85:31b0567df051

Make PackageTrack.get_revision_numbers return the revisions as a sorted list. Add a test case for this.
author Bernhard Herzog <bh@intevation.de>
date Tue, 11 Sep 2007 09:53:34 +0000
parents 98a7d70746a9
children 9bd92a3290e0
line wrap: on
line source
# Copyright (C) 2007 by Intevation GmbH
# Authors:
# Bernhard Herzog <bh@intevation.de>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with the software for details.

"""Tests for treepkg.packager"""

import sys
import os
import unittest

from treepkg.run import call
from treepkg.cmdexpand import cmdexpand
from treepkg.util import writefile
from treepkg.packager import PackagerGroup
import treepkg.subversion as subversion
import treepkg

from filesupport import FileTestMixin


def create_svn_repository(directory):
    baseurl = "file://" + directory
    call(cmdexpand("svnadmin create --fs-type fsfs $directory",
                   **locals()))
    call(cmdexpand("svn mkdir -q -m 'create directory structure'"
                   " $baseurl/trunk",
                   **locals()))
    return baseurl

def add_svn_files(workingcopy, filedesc, commitmsg):
    for name, contents in filedesc:
        writefile(os.path.join(workingcopy, name), contents)
        call(cmdexpand("svn add -q $name", **locals()),
             cwd=workingcopy)
    call(cmdexpand("svn commit -q -m $commitmsg", **locals()),
         cwd=workingcopy)


class SourcePackager(treepkg.packager.SourcePackager):

    pkg_basename = "testpkg"

    def do_package(self):
        pkgbaseversion, pkgbasedir = self.export_sources()

        pkgbasename = self.pkg_basename + "_" + pkgbaseversion
        origtargz = os.path.join(self.work_dir,
                                 pkgbasename + ".orig.tar.gz")
        self.create_tarball(origtargz, self.work_dir,
                            os.path.basename(pkgbasedir))

        changemsg = ("Update to SVN rev. %d" % (self.revision,))
        self.copy_debian_directory(pkgbasedir, pkgbaseversion,
                                   changemsg)

        self.create_source_package(pkgbasedir, origtargz)
        self.move_source_package(pkgbasename)


class RevisionPackager(treepkg.packager.RevisionPackager):

    source_packager_cls = SourcePackager


class PackageTrack(treepkg.packager.PackageTrack):

    revision_packager_cls = RevisionPackager


class TestPackager(unittest.TestCase, FileTestMixin):

    initial_files = [
        ("README", "and miles to go before I sleep"),
        ]

    debian_files = [
        ("debian",
         [("control", """\
Source: testpkg
Priority: optional
Maintainer: TreePKG <treepkg@example.com>
Standards-Version: 3.7.2

Package: testpkg
Architecture: all
Description: Test package for treepkg testsGerman (de) internationalized (i18n) files for KDE
 This package contains the German internationalized (i18n) files for
 all KDE core applications.
"""),
          ("changelog", """\
testpkg (0-0) unstable; urgency=low

  * Initial version

 -- TreePKG <treepkg@example.com>  Thu,  8 Mar 2007 18:34:39 +0100
"""),
          ("rules", "binary: echo binary")])]

    def setUp(self):
        self.svndir = self.create_temp_dir(self.id() + "-svn")
        self.svnworkdir = self.create_temp_dir(self.id() + "-svnwork")
        self.trackdir = self.create_temp_dir(self.id() + "-track")
        self.create_files(self.trackdir, self.debian_files)

    def test(self):
        baseurl = create_svn_repository(self.svndir)
        svn_url = baseurl + "/trunk"
        subversion.checkout(svn_url, self.svnworkdir)
        add_svn_files(self.svnworkdir, self.initial_files,
                      "Initial version")
        rootcmd = os.path.join(os.path.dirname(__file__), os.pardir, "test",
                               "mocksudopbuilder.py")
        track = PackageTrack(name="testpkg", base_dir=self.trackdir,
                             svn_url=svn_url, pbuilderrc="",
                             root_cmd=[sys.executable, rootcmd],
                             deb_email="treepkg@example.com",
                             deb_fullname="treepkg tester")
        group = PackagerGroup([track], 1)
        group.check_package_tracks()

        # Now check the source and binary package files
        pkgdir = os.path.join(self.trackdir, "pkg", "2-1")
        self.assertEquals(sorted(os.listdir(os.path.join(pkgdir, "src"))),
                          ["testpkg_2-kk1.diff.gz",
                           "testpkg_2-kk1.dsc",
                           "testpkg_2.orig.tar.gz"])
        self.assertEquals(sorted(os.listdir(os.path.join(pkgdir, "binary"))),
                          ["testpkg_2-kk1_all.deb",
                           "testpkg_2-kk1_i386.changes"])


class TestPackageTrack(unittest.TestCase, FileTestMixin):

    track_files = [("pkg",
                    [("704195-1",
                      [("status", ""),
                       ("src", []),
                       ("binary", [])]),
                     # Note: The revisions are not ordered so that we
                     # can check whether get_revision_numbers returns a
                     # sorted list of revisions
                     ("702432-1",
                      [("status", ""),
                       ("src", []),
                       ("binary", [])])])]

    def setUp(self):
        self.trackdir = self.create_temp_dir(self.id() + "-track")
        self.create_files(self.trackdir, self.track_files)

    def test_get_revision_numbers(self):
        track = PackageTrack("testtrack", self.trackdir, "", "", "", "", "")
        self.assertEquals(track.get_revision_numbers(), [702432, 704195])
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)