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 bricks@344: builderconfig: %(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 bricks@387: name: testtreepkg bh@114: bh@114: [pkg_simple] bh@299: pkg_basename: simple1 bricks@511: 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 bricks@403: os: foo os aheinecke@465: status_hook: echo simple hook bh@114: bh@114: [pkg_extraargs] bricks@511: 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 bricks@511: rules_url: file:///tmp/my-debian-repository bh@297: deb_build_options: parallel=2 bricks@403: os: bar os aheinecke@465: status_hook: echo extra hook 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", bricks@389: check_interval=3600, bricks@389: name="testtreepkg", bricks@389: treepkg_dir="/home/builder/mill", bricks@389: tracks_dir="/home/builder/mill/tracks")) 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", bricks@344: builderconfig="/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)], bricks@511: url="svn://example.com/extraargs/trunk", bricks@511: rules_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"), bricks@511: branch="", bricks@403: builder_cls="PBuilder", aheinecke@465: os="bar os", aheinecke@465: status_hook="echo extra hook"), 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="", bricks@511: rules_url="", aheinecke@341: pkg_revision_template="treepkg%(pkg_revision)s", bh@129: handle_dependencies=True, bh@114: packager_class="readconfig_test.simple", bricks@344: builderconfig="/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=[], bricks@511: url="svn://example.com/simple/trunk", aheinecke@326: version_template="1.0.svn%(revision)s", bricks@511: branch="", bricks@403: builder_cls="PBuilder", aheinecke@465: os="foo os", aheinecke@465: status_hook="echo simple hook")]) bricks@387: bricks@387: def main(): bricks@387: unittest.main() bricks@387: bricks@387: if __name__ == "__main__": bricks@387: main()