view 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
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 filesupport import FileTestMixin

from treepkg.run import call, capture_output, SubprocessError


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]
    return (track,
            [("pkg", [("%s-%s" % (rev, rules_rev),
                       [("status", "TreePackagerStatus 0.0\n"),
                        ("src", [(template % (rev,), "")
                                 for template in src_templates]),
                        ("binary", [(template % (rev,), "")
                                    for template in bin_templates])])
                      for rev, rules_rev in revisions])])

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 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/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(self):
        self.check_cmd(["--track=kdepim", "--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
""")


class TestListPackagesNoTrackNoRevision(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"],
                       """\
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 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"],
                                       [(704195, 31), (704195, 33),
                                        (702432, 47)]),
                   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)