source: tailor/vcpx/tests/config.py @ 1057

Revision 1057, 3.4 KB checked in by lele@…, 7 years ago (diff)

Test also the default case for look-for-adds

Line 
1# -*- mode: python; coding: utf-8 -*-
2# :Progetto: vcpx -- Tests for the configuration stuff
3# :Creato:   mer 03 ago 2005 02:17:18 CEST
4# :Autore:   Lele Gaifax <lele@nautilus.homeip.net>
5# :Licenza:  GNU General Public License
6#
7
8from unittest import TestCase
9from cStringIO import StringIO
10from vcpx.config import Config, ConfigurationError
11from vcpx.project import Project
12
13class Configuration(TestCase):
14    "Test the configuration system"
15
16    def setUp(self):
17        from os import mkdir, getcwd
18        from os.path import exists, split, join
19        from atexit import register
20        from shutil import rmtree
21
22        tailor_repo = getcwd()
23        while tailor_repo and not exists(join(tailor_repo, '_darcs')):
24            tailor_repo = split(tailor_repo)[0]
25        assert exists(join(tailor_repo, '_darcs')), "Tailor Darcs repository not found!"
26        self.tailor_repo = tailor_repo
27        if not exists('/tmp/tailor-tests'):
28            mkdir('/tmp/tailor-tests')
29            register(rmtree, '/tmp/tailor-tests')
30
31    def getTestConfiguration(self, testname):
32        from os.path import join, split
33
34        logname = join(split(__file__)[0], 'data', testname)+'.py'
35        return file(logname)
36
37    def testBasicConfig(self):
38        """Verify the basic configuration mechanism"""
39
40        from os import getcwd
41
42        config = Config(self.getTestConfiguration("config-basic_test"),
43                        {'tailor_repo': self.tailor_repo})
44
45        self.assertEqual(config.projects(), ['project2'])
46        self.assertRaises(ConfigurationError, Project, 'project2', config)
47
48        project1 = Project('project1', config)
49        self.assertEqual(project1.rootdir, '/tmp/tailor-tests')
50
51        project4 = Project('project4', config)
52        self.assertEqual(project4.rootdir, getcwd())
53
54        self.assert_(config.namespace.has_key('maybe_skip'))
55        self.assert_(config.namespace['refill'] in project1.before_commit)
56        self.assertEqual(len(project1.after_commit), 1)
57
58    def testSharedDirs(self):
59        """Verify the shared-dir switch"""
60
61        config = Config(self.getTestConfiguration("config-basic_test"),
62                        {'tailor_repo': self.tailor_repo})
63
64        project1 = Project('project1', config)
65        wd = project1.workingDir()
66        self.assert_(wd.shared_basedirs)
67
68        project3 = Project('project3', config)
69        wd = project3.workingDir()
70        self.assert_(wd.shared_basedirs)
71
72        project4 = Project('project4', config)
73        wd = project4.workingDir()
74        self.assert_(not wd.shared_basedirs)
75
76    def testWithLogging(self):
77        """Verify a configuration containing also a [[logging]] section"""
78
79        from logging import getLogger
80
81        config = Config(self.getTestConfiguration("config-with_logging"), {})
82
83        logger = getLogger()
84        self.assertEqual(logger.handlers[0].formatter._fmt, 'DUMMY')
85
86    def testLookForAdds(self):
87        """Verify the darcs Repository knows about --look-for-adds"""
88
89        config = Config(self.getTestConfiguration("config-basic_test"),
90                        {'tailor_repo': self.tailor_repo})
91
92        project3 = Project('project3', config)
93        self.assertEqual(project3.target.command('record', '-a'),
94                         ['darcs', 'record', '-a'])
95        project4 = Project('project4', config)
96        self.assertEqual(project4.target.command('record', '-a'),
97                         ['darcs', 'record', '-a', '--look-for-adds'])
98       
Note: See TracBrowser for help on using the repository browser.