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 bh@114: debrevision_prefix: treepkg 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@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 bh@114: bh@114: [pkg_extraargs] 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.extraargs bh@114: orig_tarball: %(base_dir)s/mytarball.tgz bh@234: rules_svn_url: file:///tmp/my-debian-repository 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", bh@114: deb_email="treepkg@example.com", bh@114: deb_fullname="TreePKG", bh@114: debrevision_prefix="treepkg", bh@129: handle_dependencies=False, bh@114: packager_class="readconfig_test.extraargs", bh@114: pbuilderrc="/home/builder/mill/pbuilder/pbuilderrc", bh@114: root_cmd=['sudo'], bh@167: signing_key_id="", bh@114: svn_url="svn://example.com/extraargs/trunk", bh@234: rules_svn_url="file:///tmp/my-debian-repository", bh@114: orig_tarball=("/home/builder/mill/" bh@114: "tracks/extraargs/mytarball.tgz")), bh@114: dict(name="simple", bh@114: base_dir="/home/builder/mill/tracks/simple", bh@114: deb_email="treepkg@example.com", bh@114: deb_fullname="TreePKG", bh@234: rules_svn_url="", bh@114: debrevision_prefix="treepkg", bh@129: handle_dependencies=True, bh@114: packager_class="readconfig_test.simple", bh@114: pbuilderrc="/home/builder/mill/pbuilder/pbuilderrc", bh@114: root_cmd=['sudo'], bh@167: signing_key_id="abcd1234", bh@114: svn_url="svn://example.com/simple/trunk")])