comparison test/test_readconfig.py @ 114:02c261e4443f

Extend treepkg.readconfig.read_config: - use import_packager_module - allow %(name)s substitutions in packager_class values in the pkg_* sections
author Bernhard Herzog <bh@intevation.de>
date Tue, 01 Apr 2008 13:27:21 +0000
parents
children ce9f046058b5
comparison
equal deleted inserted replaced
113:312949e7628d 114:02c261e4443f
1 # Copyright (C) 2008 by Intevation GmbH
2 # Authors:
3 # Bernhard Herzog <bh@intevation.de>
4 #
5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with the software for details.
7
8 """Tests for the treepkg.readconfig module"""
9
10 import sys
11 import os
12 import operator
13 import unittest
14
15 from filesupport import FileTestMixin
16
17 from treepkg.readconfig import read_config
18
19
20 class TestReadConfig(unittest.TestCase, FileTestMixin):
21
22 config_contents = """\
23 [DEFAULT]
24 treepkg_dir: /home/builder/mill
25 tracks_dir: %(treepkg_dir)s/tracks
26 root_cmd: sudo
27 pbuilder_dir: %(treepkg_dir)s/pbuilder
28 pbuilderrc: %(pbuilder_dir)s/pbuilderrc
29 deb_email: treepkg@example.com
30 deb_fullname: TreePKG
31 debrevision_prefix: treepkg
32
33 [treepkg]
34 instructions_file: %(treepkg_dir)s/instructions
35 check_interval: 3600
36
37 [pkg_simple]
38 svn_url: svn://example.com/%(name)s/trunk
39 base_dir: %(tracks_dir)s/%(name)s
40 packager_class: readconfig_test.%(name)s
41
42 [pkg_extraargs]
43 svn_url: svn://example.com/%(name)s/trunk
44 base_dir: %(tracks_dir)s/%(name)s
45 packager_class: readconfig_test.extraargs
46 orig_tarball: %(base_dir)s/mytarball.tgz
47 """
48
49 files = [("treepkg.cfg", config_contents),
50 ("readconfig_test",
51 [("__init__.py", ""),
52 ("simple.py",
53 "\n".join(["class SourcePackager:",
54 " pass",
55 ""])),
56 ("extraargs.py",
57 "\n".join(["class PackageTrack:",
58 " extra_config_desc=['orig_tarball']",
59 ""]))])]
60
61 def setUp(self):
62 self.directory = self.create_temp_dir(self.id())
63 self.create_files(self.directory, self.files)
64 self.old_path = sys.path
65 sys.path = [self.directory] + sys.path
66
67 def tearDown(self):
68 sys.path = self.old_path
69
70 def test_readconfig(self):
71 config_file = os.path.join(self.directory, "treepkg.cfg")
72 treepkg_opts, packager_opts = read_config(config_file)
73 self.assertEquals(treepkg_opts,
74 dict(instructions_file="/home/builder/mill/instructions",
75 check_interval=3600))
76 self.assertEquals(sorted(packager_opts,
77 key=operator.itemgetter("name")),
78 [
79 dict(name="extraargs",
80 base_dir="/home/builder/mill/tracks/extraargs",
81 deb_email="treepkg@example.com",
82 deb_fullname="TreePKG",
83 debrevision_prefix="treepkg",
84 packager_class="readconfig_test.extraargs",
85 pbuilderrc="/home/builder/mill/pbuilder/pbuilderrc",
86 root_cmd=['sudo'],
87 svn_url="svn://example.com/extraargs/trunk",
88 orig_tarball=("/home/builder/mill/"
89 "tracks/extraargs/mytarball.tgz")),
90 dict(name="simple",
91 base_dir="/home/builder/mill/tracks/simple",
92 deb_email="treepkg@example.com",
93 deb_fullname="TreePKG",
94 debrevision_prefix="treepkg",
95 packager_class="readconfig_test.simple",
96 pbuilderrc="/home/builder/mill/pbuilder/pbuilderrc",
97 root_cmd=['sudo'],
98 svn_url="svn://example.com/simple/trunk")])
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)