view test/test_listpackages.py @ 267:fdee17d71778

Refactor the enterprise4 BasePackageTrack to make it possible to override the tag export in derived classes
author Bernhard Herzog <bh@intevation.de>
date Thu, 30 Apr 2009 10:30:04 +0000
parents 7d932fac1055
children faeeac2c4c71
line wrap: on
line source
# Copyright (C) 2009 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.


import sys
import os
import difflib
import unittest
from datetime import datetime, timedelta

from filesupport import FileTestMixin

from treepkg.run import call, capture_output, SubprocessError
from treepkg.status import RevisionStatus


def package_track_files(track, version, binaries, revisions):
    src_templates = ["%s_%s.%%s%s" % (track, version, suffix)
                     for suffix in [".orig.tar.gz", "-1.diff.gz", "-1.dsc"]]
    bin_templates = ["%s_%s.%%s-1_i386.deb" % (basename, version)
                     for basename in binaries]

    start_time = datetime.now()
    build_duration = timedelta(minutes=30)
    check_interval = timedelta(minutes=60)

    package_dirs = []
    for revision in revisions:
        status = RevisionStatus(None)
        if len(revision) == 2:
            rev, rules_rev = revision
            status.binary_package_created()
        else:
            rev, rules_rev, status_name = revision
            getattr(status, status_name)()

        status.start = start_time
        status.stop = start_time + build_duration
        start_time += check_interval

        if status.status.finished and not status.status.error:
            src_files = [(template % (rev,), "") for template in src_templates]
            bin_files = [(template % (rev,), "") for template in bin_templates]
        else:
            src_files = []
            bin_files = []

        package_dirs.append(("%s-%s" % (rev, rules_rev),
                             [("status", "".join(status.serialize())),
                              ("src", src_files),
                              ("binary", bin_files)]))
    return (track,
            [("pkg",
              package_dirs)])


class ListPackagesTest(unittest.TestCase, FileTestMixin):

    treepkg_cfg_template = """\
[DEFAULT]
tracks_dir: %(tracksdir)s
root_cmd: true
pbuilderrc:
deb_email: packager@example.com
deb_fullname: Sample Packager
debrevision_prefix: treepkg
handle_dependencies: False

[treepkg]
check_interval: 3600
instructions_file:

[pkg_kdepim]
svn_url: svn://anonsvn.kde.org/home/kde/branches/kdepim/enterprise/kdepim
base_dir: %%(tracks_dir)s/kdepim
packager_class: recipes.kde_enterprise_3_5.kdepim

[pkg_kdepimlibs]
svn_url: svn://anonsvn.kde.org/home/kde/branches/kdepim/enterprise/kdepimlibs
base_dir: %%(tracks_dir)s/kdepimlibs
packager_class: recipes.kde_enterprise_3_5.kdepim
"""

    track_files = []

    def setUp(self):
        self.bindir = os.path.join(os.path.dirname(__file__),
                                   os.pardir, "bin")
        self.listpackages = os.path.join(self.bindir, "listpackages.py")
        self.tracksdir = self.create_files("tracks", self.track_files)
        config = self.treepkg_cfg_template % dict(tracksdir=self.tracksdir)
        self.config_file = self.create_temp_file("treepkg.cfg", config)
        self.base_command = [sys.executable, self.listpackages,
                             "--config-file=" + self.config_file]

    def run_command(self, extra_args, expected_exit_code=0):
        cmd = self.base_command + list(extra_args)
        try:
            output = capture_output(cmd)
        except SubprocessError, exc:
            if expected_exit_code != exc.returncode:
                raise
            output = exc.output
        return output

    def check_cmd(self, args, expected):
        expected_lines = [os.path.join(self.tracksdir, filename) + "\n"
                          for filename in expected.splitlines()]
        try:
            output_lines = [line + "\n"
                            for line in self.run_command(args).splitlines()]
        except SubprocessError, exc:
            print >>sys.stderr, "Unexpected output:", exc.output
            raise

        # the order of the listed packages doesn't matter, so sort the
        # lists before comparing them
        expected_lines.sort()
        output_lines.sort()

        if expected_lines != output_lines:
            diff = difflib.unified_diff(expected_lines, output_lines,
                                        "expected", "found")
            raise self.failureException("\n" + "".join(diff))


class TestListPackagesNoPackages(ListPackagesTest):

    track_files = []

    def test_listpackages_noargs(self):
        # if nothing has been packaged yet, the output is simply empty
        self.check_cmd(["--source"], "")

    def test_listpackages_revision(self):
        # if nothing has been packaged yet, the output is simply empty
        self.assertEquals(self.run_command(["--source", "--revision=12345",
                                            "--track=kdepim"],
                                           expected_exit_code=1),
                          "No revision 12345\n")

    def test_listpackages_revision_rulesrev(self):
        # if nothing has been packaged yet, the output is simply empty
        self.assertEquals(self.run_command(["--source", "--revision=12345-321",
                                            "--track=kdepim"],
                                           expected_exit_code=1),
                          "No revision 12345-321\n")

class TestListPackagesTrackNoRevision(ListPackagesTest):

    track_files = [package_track_files("kdepim", "1.0.1",
                                       ["kdepim", "kleopatra"],
                                       [(704195, 31), (702432, 47)])]

    def test_listpackages_source(self):
        self.check_cmd(["--track=kdepim", "--source"],
                       """\
kdepim/pkg/702432-47/src/kdepim_1.0.1.702432-1.diff.gz
kdepim/pkg/702432-47/src/kdepim_1.0.1.702432-1.dsc
kdepim/pkg/702432-47/src/kdepim_1.0.1.702432.orig.tar.gz
""")

    def test_listpackages_binary(self):
        self.check_cmd(["--track=kdepim", "--binary"],
                       """\
kdepim/pkg/702432-47/binary/kdepim_1.0.1.702432-1_i386.deb
kdepim/pkg/702432-47/binary/kleopatra_1.0.1.702432-1_i386.deb
""")


class TestListPackagesTrackNoRevisionWithIncompleteBuilds(ListPackagesTest):

    track_files = [package_track_files("kdepim", "1.0.1",
                                       ["kdepim", "kleopatra"],
                                       [(702432, 47),
                                        (704195, 31, "error")])]

    def test_listpackages_source(self):
        self.check_cmd(["--track=kdepim", "--source"],
                       """\
kdepim/pkg/702432-47/src/kdepim_1.0.1.702432-1.diff.gz
kdepim/pkg/702432-47/src/kdepim_1.0.1.702432-1.dsc
kdepim/pkg/702432-47/src/kdepim_1.0.1.702432.orig.tar.gz
""")

    def test_listpackages_binary(self):
        self.check_cmd(["--track=kdepim", "--binary"],
                       """\
kdepim/pkg/702432-47/binary/kdepim_1.0.1.702432-1_i386.deb
kdepim/pkg/702432-47/binary/kleopatra_1.0.1.702432-1_i386.deb
""")


class TestListPackagesNoTrackNoRevision(ListPackagesTest):

    track_files = [package_track_files("kdepim", "1.0.1",
                                       ["kdepim", "kleopatra"],
                                       [(702432, 47),
                                        (704195, 31)]),
                   package_track_files("kdepimlibs", "1.0.1",
                                       ["kdepimlibs"],
                                       [(803691, 4321),
                                        (803692, 4322)]),
                   ]

    def test_listpackages_source(self):
        self.check_cmd(["--source"],
                       """\
kdepim/pkg/704195-31/src/kdepim_1.0.1.704195-1.diff.gz
kdepim/pkg/704195-31/src/kdepim_1.0.1.704195-1.dsc
kdepim/pkg/704195-31/src/kdepim_1.0.1.704195.orig.tar.gz
kdepimlibs/pkg/803692-4322/src/kdepimlibs_1.0.1.803692-1.diff.gz
kdepimlibs/pkg/803692-4322/src/kdepimlibs_1.0.1.803692-1.dsc
kdepimlibs/pkg/803692-4322/src/kdepimlibs_1.0.1.803692.orig.tar.gz""")

    def test_listpackages_binary(self):
        self.check_cmd(["--binary"],
                       """\
kdepim/pkg/704195-31/binary/kdepim_1.0.1.704195-1_i386.deb
kdepim/pkg/704195-31/binary/kleopatra_1.0.1.704195-1_i386.deb
kdepimlibs/pkg/803692-4322/binary/kdepimlibs_1.0.1.803692-1_i386.deb""")


class TestListPackagesNNewest(ListPackagesTest):

    track_files = [package_track_files("kdepim", "1.0.1",
                                       ["kdepim", "kleopatra"],
                                       [(701865, 28),
                                        (700345, 28),
                                        (702432, 28),
                                        (704195, 31, "error")]),
                   package_track_files("kdepimlibs", "1.0.1",
                                       ["kdepimlibs"],
                                       [(700298, 34),
                                        (700345, 34),
                                        (701866, 34, "error"),
                                        (701866, 35),
                                        (702436, 35)]),
                   ]

    def test_listpackages_source(self):
        self.check_cmd(["--source", "--newest=2"],
                       """\
kdepim/pkg/700345-28/src/kdepim_1.0.1.700345-1.diff.gz
kdepim/pkg/700345-28/src/kdepim_1.0.1.700345-1.dsc
kdepim/pkg/700345-28/src/kdepim_1.0.1.700345.orig.tar.gz
kdepim/pkg/702432-28/src/kdepim_1.0.1.702432-1.diff.gz
kdepim/pkg/702432-28/src/kdepim_1.0.1.702432-1.dsc
kdepim/pkg/702432-28/src/kdepim_1.0.1.702432.orig.tar.gz
kdepimlibs/pkg/701866-35/src/kdepimlibs_1.0.1.701866-1.diff.gz
kdepimlibs/pkg/701866-35/src/kdepimlibs_1.0.1.701866-1.dsc
kdepimlibs/pkg/701866-35/src/kdepimlibs_1.0.1.701866.orig.tar.gz
kdepimlibs/pkg/702436-35/src/kdepimlibs_1.0.1.702436-1.diff.gz
kdepimlibs/pkg/702436-35/src/kdepimlibs_1.0.1.702436-1.dsc
kdepimlibs/pkg/702436-35/src/kdepimlibs_1.0.1.702436.orig.tar.gz""")

    def test_listpackages_binary(self):
        self.check_cmd(["--binary", "--newest=3"],
                       """\
kdepim/pkg/700345-28/binary/kdepim_1.0.1.700345-1_i386.deb
kdepim/pkg/700345-28/binary/kleopatra_1.0.1.700345-1_i386.deb
kdepim/pkg/701865-28/binary/kdepim_1.0.1.701865-1_i386.deb
kdepim/pkg/701865-28/binary/kleopatra_1.0.1.701865-1_i386.deb
kdepim/pkg/702432-28/binary/kdepim_1.0.1.702432-1_i386.deb
kdepim/pkg/702432-28/binary/kleopatra_1.0.1.702432-1_i386.deb
kdepimlibs/pkg/700345-34/binary/kdepimlibs_1.0.1.700345-1_i386.deb
kdepimlibs/pkg/701866-35/binary/kdepimlibs_1.0.1.701866-1_i386.deb
kdepimlibs/pkg/702436-35/binary/kdepimlibs_1.0.1.702436-1_i386.deb""")


class TestListPackagesTrackRevision(ListPackagesTest):

    track_files = [package_track_files("kdepim", "1.0.1",
                                       ["kdepim", "kleopatra"],
                                       [(704195, 31), (702432, 47)]),
                   package_track_files("kdepimlibs", "1.0.1",
                                       ["kdepimlibs"],
                                       [(803691, 4321), (803692, 4322)]),
                   ]

    def test_listpackages_source(self):
        self.check_cmd(["--source", "--track=kdepim", "--revision=702432"],
                       """\
kdepim/pkg/702432-47/src/kdepim_1.0.1.702432-1.diff.gz
kdepim/pkg/702432-47/src/kdepim_1.0.1.702432-1.dsc
kdepim/pkg/702432-47/src/kdepim_1.0.1.702432.orig.tar.gz""")

    def test_listpackages_binary(self):
        self.check_cmd(["--binary", "--track=kdepim", "--revision=702432"],
                       """\
kdepim/pkg/702432-47/binary/kdepim_1.0.1.702432-1_i386.deb
kdepim/pkg/702432-47/binary/kleopatra_1.0.1.702432-1_i386.deb""")



class TestListPackagesMultipleRulesRevisions(ListPackagesTest):

    track_files = [package_track_files("kdepim", "1.0.1",
                                       ["kdepim", "kleopatra"],
                                       [(702432, 47),
                                        (704195, 31),
                                        (704195, 33)]),
                   package_track_files("kdepimlibs", "1.0.1",
                                       ["kdepimlibs"],
                                       [(803691, 4321),
                                        (803692, 4322)]),
                   ]

    def test_listpackages_source_no_rev(self):
        self.check_cmd(["--source", "--track=kdepim"],
                       """\
kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.diff.gz
kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.dsc
kdepim/pkg/704195-33/src/kdepim_1.0.1.704195.orig.tar.gz""")

    def test_listpackages_binary_no_rev(self):
        self.check_cmd(["--binary", "--track=kdepim"],
                       """\
kdepim/pkg/704195-33/binary/kdepim_1.0.1.704195-1_i386.deb
kdepim/pkg/704195-33/binary/kleopatra_1.0.1.704195-1_i386.deb""")

    def test_listpackages_source_and_binary_no_rev(self):
        self.check_cmd(["--source", "--track=kdepim", "--binary"],
                       """\
kdepim/pkg/704195-33/binary/kdepim_1.0.1.704195-1_i386.deb
kdepim/pkg/704195-33/binary/kleopatra_1.0.1.704195-1_i386.deb
kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.diff.gz
kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.dsc
kdepim/pkg/704195-33/src/kdepim_1.0.1.704195.orig.tar.gz
""")

    def test_listpackages_source_no_rulesrev(self):
        self.check_cmd(["--source", "--track=kdepim", "--revision=704195"],
                       """\
kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.diff.gz
kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.dsc
kdepim/pkg/704195-33/src/kdepim_1.0.1.704195.orig.tar.gz""")

    def test_listpackages_binary_no_rulesrev(self):
        self.check_cmd(["--binary", "--track=kdepim", "--revision=704195"],
                       """\
kdepim/pkg/704195-33/binary/kdepim_1.0.1.704195-1_i386.deb
kdepim/pkg/704195-33/binary/kleopatra_1.0.1.704195-1_i386.deb""")

    def test_listpackages_source_rulesrev(self):
        self.check_cmd(["--source", "--track=kdepim", "--revision=704195-31"],
                       """\
kdepim/pkg/704195-31/src/kdepim_1.0.1.704195-1.diff.gz
kdepim/pkg/704195-31/src/kdepim_1.0.1.704195-1.dsc
kdepim/pkg/704195-31/src/kdepim_1.0.1.704195.orig.tar.gz""")

    def test_listpackages_binary_rulesrev(self):
        self.check_cmd(["--binary", "--track=kdepim", "--revision=704195-31"],
                       """\
kdepim/pkg/704195-31/binary/kdepim_1.0.1.704195-1_i386.deb
kdepim/pkg/704195-31/binary/kleopatra_1.0.1.704195-1_i386.deb""")

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)