Mercurial > treepkg
view test/test_listpackages.py @ 250:b3f9cc956acc
Make the Status class usable without a filename and provide methods to
(de-)serialize to and from memory to make writing tests easier.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 09 Apr 2009 18:20:04 +0000 |
parents | 5dd710b167d2 |
children | 243f206574cb |
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 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/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""")