view test/test_readconfig.py @ 379:610b7e57f966

Changed the test for readconfig to allow the additional builder_cls option
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 21 Jun 2010 13:06:12 +0000
parents f06f707d9fda
children c1f3be727f9d
line wrap: on
line source
# Copyright (C) 2008, 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.

"""Tests for the treepkg.readconfig module"""

import sys
import os
import operator
import unittest

from filesupport import FileTestMixin

from treepkg.readconfig import read_config


class TestReadConfig(unittest.TestCase, FileTestMixin):

    config_contents = """\
[DEFAULT]
treepkg_dir: /home/builder/mill
tracks_dir: %(treepkg_dir)s/tracks
root_cmd: sudo
pbuilder_dir: %(treepkg_dir)s/pbuilder
builderconfig: %(pbuilder_dir)s/pbuilderrc
deb_email: treepkg@example.com
deb_fullname: TreePKG
pkg_revision_template: treepkg%%(pkg_revision)s
handle_dependencies: False

[treepkg]
instructions_file: %(treepkg_dir)s/instructions
check_interval: 3600

[pkg_simple]
pkg_basename: simple1
svn_url: svn://example.com/%(name)s/trunk
base_dir: %(tracks_dir)s/%(name)s
packager_class: readconfig_test.%(name)s
handle_dependencies: True
signing_key_id: abcd1234
changelog_msg_template: Update to feature branch r%%(revision)s
version_template: 1.0.svn%%(revision)s

[pkg_extraargs]
svn_url: svn://example.com/%(name)s/trunk
svn_subset: -N .
            subdir
svn_externals: scripts admin
base_dir: %(tracks_dir)s/%(name)s
packager_class: readconfig_test.extraargs
orig_tarball: %(base_dir)s/mytarball.tgz
rules_svn_url: file:///tmp/my-debian-repository
deb_build_options: parallel=2
"""

    files = [("treepkg.cfg", config_contents),
             ("readconfig_test",
              [("__init__.py", ""),
               ("simple.py",
                "\n".join(["class SourcePackager:",
                           "    pass",
                           ""])),
               ("extraargs.py",
                "\n".join(["class PackageTrack:",
                           "    extra_config_desc=['orig_tarball']",
                           ""]))])]

    def setUp(self):
        self.directory = self.create_files("treepkg", self.files)
        self.old_path = sys.path
        sys.path = [self.directory] + sys.path

    def tearDown(self):
        sys.path = self.old_path

    def test_readconfig(self):
        config_file = os.path.join(self.directory, "treepkg.cfg")
        treepkg_opts, packager_opts = read_config(config_file)
        self.assertEquals(treepkg_opts,
                    dict(instructions_file="/home/builder/mill/instructions",
                         check_interval=3600))
        self.assertEquals(sorted(packager_opts,
                                 key=operator.itemgetter("name")),
                          [
            dict(name="extraargs",
                 base_dir="/home/builder/mill/tracks/extraargs",
                 changelog_msg_template="Update to revision %(revision)s",
                 deb_email="treepkg@example.com",
                 deb_fullname="TreePKG",
                 deb_build_options="parallel=2",
                 pkg_revision_template="treepkg%(pkg_revision)s",
                 handle_dependencies=False,
                 packager_class="readconfig_test.extraargs",
                 builderconfig="/home/builder/mill/pbuilder/pbuilderrc",
                 # pkg_basename is passed as an empty string by default.
                 # The PackageTrack an empty pkg_basename it with the
                 # value of name
                 pkg_basename="",
                 root_cmd=['sudo'],
                 signing_key_id="",
                 svn_externals=["scripts", "admin"],
                 svn_subset=[(".", False), ("subdir", True)],
                 svn_url="svn://example.com/extraargs/trunk",
                 rules_svn_url="file:///tmp/my-debian-repository",
                 version_template="%(revision)s",
                 orig_tarball=("/home/builder/mill/"
                               "tracks/extraargs/mytarball.tgz"),
                 git_url="",
                 git_branch="",
                 builder_cls="PBuilder"),
            dict(name="simple",
                 base_dir="/home/builder/mill/tracks/simple",
                 changelog_msg_template=("Update to feature branch"
                                         " r%(revision)s"),
                 deb_email="treepkg@example.com",
                 deb_fullname="TreePKG",
                 deb_build_options="",
                 rules_svn_url="",
                 pkg_revision_template="treepkg%(pkg_revision)s",
                 handle_dependencies=True,
                 packager_class="readconfig_test.simple",
                 builderconfig="/home/builder/mill/pbuilder/pbuilderrc",
                 pkg_basename="simple1",
                 root_cmd=['sudo'],
                 signing_key_id="abcd1234",
                 svn_externals=[],
                 svn_subset=[],
                 svn_url="svn://example.com/simple/trunk",
                 version_template="1.0.svn%(revision)s",
                 git_url="",
                 git_branch="",
                 builder_cls="PBuilder")])
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)