bh@234: # Copyright (C) 2008, 2009 by Intevation GmbH bh@114: # Authors: bh@114: # Bernhard Herzog bh@114: # bh@114: # This program is free software under the GPL (>=v2) bh@114: # Read the file COPYING coming with the software for details. bh@114: bh@114: """Tests for the treepkg.readconfig module""" bh@114: bh@114: import sys bh@114: import os bh@114: import operator bh@114: import unittest bh@114: bh@114: from filesupport import FileTestMixin bh@114: bh@114: from treepkg.readconfig import read_config bh@114: bh@114: bh@114: class TestReadConfig(unittest.TestCase, FileTestMixin): bh@114: bh@114: config_contents = """\ bh@114: [DEFAULT] bh@114: treepkg_dir: /home/builder/mill bh@114: tracks_dir: %(treepkg_dir)s/tracks bh@114: root_cmd: sudo bh@114: pbuilder_dir: %(treepkg_dir)s/pbuilder bh@114: pbuilderrc: %(pbuilder_dir)s/pbuilderrc bh@114: deb_email: treepkg@example.com bh@114: deb_fullname: TreePKG aheinecke@341: pkg_revision_template: treepkg%%(pkg_revision)s bh@129: handle_dependencies: False bh@114: bh@114: [treepkg] bh@114: instructions_file: %(treepkg_dir)s/instructions bh@114: check_interval: 3600 bh@114: bh@114: [pkg_simple] bh@299: pkg_basename: simple1 bh@114: svn_url: svn://example.com/%(name)s/trunk bh@114: base_dir: %(tracks_dir)s/%(name)s bh@114: packager_class: readconfig_test.%(name)s bh@129: handle_dependencies: True bh@167: signing_key_id: abcd1234 aheinecke@341: changelog_msg_template: Update to feature branch r%%(revision)s bh@305: version_template: 1.0.svn%%(revision)s bh@114: bh@114: [pkg_extraargs] bh@114: svn_url: svn://example.com/%(name)s/trunk bh@304: svn_subset: -N . bh@304: subdir bh@306: svn_externals: scripts admin bh@114: base_dir: %(tracks_dir)s/%(name)s bh@114: packager_class: readconfig_test.extraargs bh@114: orig_tarball: %(base_dir)s/mytarball.tgz bh@234: rules_svn_url: file:///tmp/my-debian-repository bh@297: deb_build_options: parallel=2 bh@114: """ bh@114: bh@114: files = [("treepkg.cfg", config_contents), bh@114: ("readconfig_test", bh@114: [("__init__.py", ""), bh@114: ("simple.py", bh@114: "\n".join(["class SourcePackager:", bh@114: " pass", bh@114: ""])), bh@114: ("extraargs.py", bh@114: "\n".join(["class PackageTrack:", bh@114: " extra_config_desc=['orig_tarball']", bh@114: ""]))])] bh@114: bh@114: def setUp(self): bh@185: self.directory = self.create_files("treepkg", self.files) bh@114: self.old_path = sys.path bh@114: sys.path = [self.directory] + sys.path bh@114: bh@114: def tearDown(self): bh@114: sys.path = self.old_path bh@114: bh@114: def test_readconfig(self): bh@114: config_file = os.path.join(self.directory, "treepkg.cfg") bh@114: treepkg_opts, packager_opts = read_config(config_file) bh@114: self.assertEquals(treepkg_opts, bh@114: dict(instructions_file="/home/builder/mill/instructions", bh@114: check_interval=3600)) bh@114: self.assertEquals(sorted(packager_opts, bh@114: key=operator.itemgetter("name")), bh@114: [ bh@114: dict(name="extraargs", bh@114: base_dir="/home/builder/mill/tracks/extraargs", aheinecke@341: changelog_msg_template="Update to revision %(revision)s", bh@114: deb_email="treepkg@example.com", bh@114: deb_fullname="TreePKG", bh@297: deb_build_options="parallel=2", aheinecke@341: pkg_revision_template="treepkg%(pkg_revision)s", bh@129: handle_dependencies=False, bh@114: packager_class="readconfig_test.extraargs", bh@114: pbuilderrc="/home/builder/mill/pbuilder/pbuilderrc", bh@299: # pkg_basename is passed as an empty string by default. bh@299: # The PackageTrack an empty pkg_basename it with the bh@299: # value of name bh@299: pkg_basename="", bh@114: root_cmd=['sudo'], bh@167: signing_key_id="", bh@306: svn_externals=["scripts", "admin"], bh@304: svn_subset=[(".", False), ("subdir", True)], bh@114: svn_url="svn://example.com/extraargs/trunk", bh@234: rules_svn_url="file:///tmp/my-debian-repository", bh@305: version_template="%(revision)s", bh@114: orig_tarball=("/home/builder/mill/" aheinecke@326: "tracks/extraargs/mytarball.tgz"), aheinecke@326: git_url="", aheinecke@326: git_branch=""), bh@114: dict(name="simple", bh@114: base_dir="/home/builder/mill/tracks/simple", bh@300: changelog_msg_template=("Update to feature branch" aheinecke@341: " r%(revision)s"), bh@114: deb_email="treepkg@example.com", bh@114: deb_fullname="TreePKG", bh@297: deb_build_options="", bh@234: rules_svn_url="", aheinecke@341: pkg_revision_template="treepkg%(pkg_revision)s", bh@129: handle_dependencies=True, bh@114: packager_class="readconfig_test.simple", bh@114: pbuilderrc="/home/builder/mill/pbuilder/pbuilderrc", bh@299: pkg_basename="simple1", bh@114: root_cmd=['sudo'], bh@167: signing_key_id="abcd1234", bh@306: svn_externals=[], bh@304: svn_subset=[], bh@305: svn_url="svn://example.com/simple/trunk", aheinecke@326: version_template="1.0.svn%(revision)s", aheinecke@326: git_url="", aheinecke@326: git_branch="")])