Mercurial > bitten > bitten-test
comparison bitten/build/tests/config.py @ 233:8f816147620f
* Moved SlaveConfiguration logic into new module ([source:/trunk/bitten/build/config.py bitten.build.config]).
* The configuration properties can now be used by recipe commands. For example, the Python tools use the Python interpreter specified by the `python.path` property, if specified.
* A build recipe can reference configuration in command attributes, using the notation `${property.name:default value}`.
author | cmlenz |
---|---|
date | Fri, 30 Sep 2005 15:42:50 +0000 |
parents | |
children | 24e91cbae6e0 |
comparison
equal
deleted
inserted
replaced
232:b6e4896dc026 | 233:8f816147620f |
---|---|
1 # -*- coding: iso8859-1 -*- | |
2 # | |
3 # Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de> | |
4 # All rights reserved. | |
5 # | |
6 # This software is licensed as described in the file COPYING, which | |
7 # you should have received as part of this distribution. The terms | |
8 # are also available at http://bitten.cmlenz.net/wiki/License. | |
9 | |
10 import platform | |
11 import os | |
12 import shutil | |
13 import tempfile | |
14 import unittest | |
15 | |
16 from bitten.build.config import Configuration | |
17 | |
18 | |
19 class ConfigurationTestCase(unittest.TestCase): | |
20 | |
21 def test_sysinfo_defaults(self): | |
22 config = Configuration() | |
23 | |
24 self.assertEqual(platform.machine(), config['machine']) | |
25 self.assertEqual(platform.processor(), config['processor']) | |
26 system, release, version = platform.system_alias(platform.system(), | |
27 platform.release(), | |
28 platform.version()) | |
29 self.assertEqual(system, config['os']) | |
30 self.assertEqual(os.name, config['family']) | |
31 self.assertEqual(release, config['version']) | |
32 | |
33 def test_sysinfo_properties_override(self): | |
34 config = Configuration(properties={ | |
35 'machine': 'MACHINE', | |
36 'processor': 'PROCESSOR', | |
37 'os': 'OS', | |
38 'family': 'FAMILY', | |
39 'version': 'VERSION' | |
40 }) | |
41 self.assertEqual('MACHINE', config['machine']) | |
42 self.assertEqual('PROCESSOR', config['processor']) | |
43 self.assertEqual('OS', config['os']) | |
44 self.assertEqual('FAMILY', config['family']) | |
45 self.assertEqual('VERSION', config['version']) | |
46 | |
47 def test_sysinfo_configfile_override(self): | |
48 inifile, ininame = tempfile.mkstemp(prefix='bitten_test') | |
49 try: | |
50 os.write(inifile, """ | |
51 [machine] | |
52 name = MACHINE | |
53 processor = PROCESSOR | |
54 | |
55 [os] | |
56 name = OS | |
57 family = FAMILY | |
58 version = VERSION | |
59 """) | |
60 os.close(inifile) | |
61 config = Configuration(ininame) | |
62 | |
63 self.assertEqual('MACHINE', config['machine']) | |
64 self.assertEqual('PROCESSOR', config['processor']) | |
65 self.assertEqual('OS', config['os']) | |
66 self.assertEqual('FAMILY', config['family']) | |
67 self.assertEqual('VERSION', config['version']) | |
68 finally: | |
69 os.remove(ininame) | |
70 | |
71 def test_package_properties(self): | |
72 config = Configuration(properties={ | |
73 'python.version': '2.3.5', | |
74 'python.path': '/usr/local/bin/python2.3' | |
75 }) | |
76 self.assertEqual(True, 'python' in config.packages) | |
77 self.assertEqual('/usr/local/bin/python2.3', config['python.path']) | |
78 self.assertEqual('2.3.5', config['python.version']) | |
79 | |
80 def test_package_configfile(self): | |
81 inifile, ininame = tempfile.mkstemp(prefix='bitten_test') | |
82 try: | |
83 os.write(inifile, """ | |
84 [python] | |
85 path = /usr/local/bin/python2.3 | |
86 version = 2.3.5 | |
87 """) | |
88 os.close(inifile) | |
89 config = Configuration(ininame) | |
90 | |
91 self.assertEqual(True, 'python' in config.packages) | |
92 self.assertEqual('/usr/local/bin/python2.3', config['python.path']) | |
93 self.assertEqual('2.3.5', config['python.version']) | |
94 finally: | |
95 os.remove(ininame) | |
96 | |
97 def test_interpolate(self): | |
98 config = Configuration(properties={ | |
99 'python.version': '2.3.5', | |
100 'python.path': '/usr/local/bin/python2.3' | |
101 }) | |
102 self.assertEqual('/usr/local/bin/python2.3', | |
103 config.interpolate('${python.path}')) | |
104 self.assertEqual('foo /usr/local/bin/python2.3 bar', | |
105 config.interpolate('foo ${python.path} bar')) | |
106 | |
107 def test_interpolate_default(self): | |
108 config = Configuration() | |
109 self.assertEqual('python2.3', | |
110 config.interpolate('${python.path:python2.3}')) | |
111 self.assertEqual('foo python2.3 bar', | |
112 config.interpolate('foo ${python.path:python2.3} bar')) | |
113 | |
114 def test_interpolate_missing(self): | |
115 config = Configuration() | |
116 self.assertEqual('${python.path}', | |
117 config.interpolate('${python.path}')) | |
118 self.assertEqual('foo ${python.path} bar', | |
119 config.interpolate('foo ${python.path} bar')) | |
120 | |
121 | |
122 def suite(): | |
123 suite = unittest.TestSuite() | |
124 suite.addTest(unittest.makeSuite(ConfigurationTestCase, 'test')) | |
125 return suite | |
126 | |
127 if __name__ == '__main__': | |
128 unittest.main(defaultTest='suite') |