view test/test_readconfig.py @ 152:4adcb15cbdfb

Let the user supply the filename of the template to use for the status page. bin/createstaticweb.py and bin/starttreepkgweb.py now have an additional option --status-template for the filename of the template, and the code in treepkg/web.py accepts the filename as parameter in various places.
author Bernhard Herzog <bh@intevation.de>
date Mon, 09 Jun 2008 16:33:20 +0000
parents ce9f046058b5
children 36004ee0b3a1
line wrap: on
line source
# Copyright (C) 2008 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
pbuilderrc: %(pbuilder_dir)s/pbuilderrc
deb_email: treepkg@example.com
deb_fullname: TreePKG
debrevision_prefix: treepkg
handle_dependencies: False

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

[pkg_simple]
svn_url: svn://example.com/%(name)s/trunk
base_dir: %(tracks_dir)s/%(name)s
packager_class: readconfig_test.%(name)s
handle_dependencies: True

[pkg_extraargs]
svn_url: svn://example.com/%(name)s/trunk
base_dir: %(tracks_dir)s/%(name)s
packager_class: readconfig_test.extraargs
orig_tarball: %(base_dir)s/mytarball.tgz
"""

    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_temp_dir(self.id())
        self.create_files(self.directory, 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",
                 deb_email="treepkg@example.com",
                 deb_fullname="TreePKG",
                 debrevision_prefix="treepkg",
                 handle_dependencies=False,
                 packager_class="readconfig_test.extraargs",
                 pbuilderrc="/home/builder/mill/pbuilder/pbuilderrc",
                 root_cmd=['sudo'],
                 svn_url="svn://example.com/extraargs/trunk",
                 orig_tarball=("/home/builder/mill/"
                               "tracks/extraargs/mytarball.tgz")),
            dict(name="simple",
                 base_dir="/home/builder/mill/tracks/simple",
                 deb_email="treepkg@example.com",
                 deb_fullname="TreePKG",
                 debrevision_prefix="treepkg",
                 handle_dependencies=True,
                 packager_class="readconfig_test.simple",
                 pbuilderrc="/home/builder/mill/pbuilder/pbuilderrc",
                 root_cmd=['sudo'],
                 svn_url="svn://example.com/simple/trunk")])
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)