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

Revision 831, 4.2 KB checked in by lele@…, 8 years ago (diff)

Expand ~user on project's root-directory and make it absolute anyway

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, TestSuite
9from cStringIO import StringIO
10from vcpx.config import Config, ConfigurationError
11from vcpx.project import Project
12
13class ConfigTest(TestCase):
14
15    def setUp(self):
16        from os import mkdir, getcwd
17        from os.path import exists, split, join
18        from atexit import register
19        from shutil import rmtree
20
21        tailor_repo = getcwd()
22        while tailor_repo and not exists(join(tailor_repo, '_darcs')):
23            tailor_repo = split(tailor_repo)[0]
24        assert exists(join(tailor_repo, '_darcs')), "Tailor Darcs repository not found!"
25        self.tailor_repo = tailor_repo
26        if not exists('/tmp/tailor-tests'):
27            mkdir('/tmp/tailor-tests')
28            register(rmtree, '/tmp/tailor-tests')
29
30    BASIC_TEST = """\
31#!tailor
32'''
33[DEFAULT]
34verbose = False
35target-module = None
36projects = project2
37
38[project1]
39root-directory = /tmp/tailor-tests
40source = svn:project1repo
41target = darcs:project1repo
42refill-changelogs = Yes
43state-file = project1.state
44before-commit = (maybe_skip, refill, p1_remap_authors)
45after-commit = checkpoint
46
47[svn:project1repo]
48repository = svn://some.server/svn
49module = project1
50use-propset = Yes
51
52[darcs:project1repo]
53repository = ~/darcs/project1
54
55[monotone:project1repo]
56repository = /tmp/db
57passphrase = simba
58
59[project2]
60root-directory = /tmp/tailor-tests
61source = darcs:project1repo
62target = svn:project2repo
63refill-changelogs = Yes
64state-file = project2.state
65before-commit = refill
66
67[svn:project2repo]
68
69[project3]
70root-directory = /tmp/tailor-tests
71source = svndump:project3repo
72target = darcs:project3repo
73
74[svndump:project3repo]
75repository = %(tailor_repo)s/vcpx/tests/data/simple.svndump
76subdir = plain
77
78[darcs:project3repo]
79subdir = .
80
81[project4]
82source = svndump:project3repo
83target = darcs:project4repo
84
85[darcs:project4repo]
86subdir = darcs
87'''
88
89def maybe_skip(context, changeset):
90    for e in changeset.entries:
91        if not context.darcs.isBoringFile(e):
92            return True
93    # What a bunch of boring entries! Skip the patch
94    return False
95
96def refill(context, changeset):
97    changeset.refillChangelog()
98    return True
99
100p1_authors_map = {
101    'lele': 'Lele Gaifax <lele@example.com>',
102    'x123': 'A man ... with a name to come',
103}
104
105def p1_remap_authors(context, changeset):
106    if p1_authors_map.has_key(changeset.author):
107        changeset.author = p1_authors_map[changeset.author]
108    return True
109
110def checkpoint(context, changeset):
111    if changeset.log.startswith('Release '):
112        context.target.tagWithCheckpoint(changeset.log)
113    return True
114"""
115
116    def testBasicConfig(self):
117        """Verify the configuration mechanism"""
118
119        config = Config(StringIO(self.BASIC_TEST),
120                        {'tailor_repo': self.tailor_repo})
121        self.assertEqual(config.projects(), ['project2'])
122
123    def testValidation(self):
124        """Verify Repository validation mechanism"""
125
126        config = Config(StringIO(self.BASIC_TEST),
127                         {'tailor_repo': self.tailor_repo})
128        self.assertRaises(ConfigurationError, Project, 'project2', config)
129
130    def testSharedDirs(self):
131        """Verify the shared-dir switch"""
132
133        config = Config(StringIO(self.BASIC_TEST),
134                        {'tailor_repo': self.tailor_repo})
135
136        project1 = Project('project1', config)
137        wd = project1.workingDir()
138        self.assert_(wd.shared_basedirs)
139
140        project3 = Project('project3', config)
141        wd = project3.workingDir()
142        self.assert_(wd.shared_basedirs)
143
144        project4 = Project('project4', config)
145        wd = project4.workingDir()
146        self.assert_(not wd.shared_basedirs)
147
148    def testRootDirectory(self):
149        """Verify the root-directory expansion"""
150
151        from os import getcwd
152
153        config = Config(StringIO(self.BASIC_TEST),
154                        {'tailor_repo': self.tailor_repo})
155
156        project1 = Project('project1', config)
157        self.assertEqual(project1.rootdir, '/tmp/tailor-tests')
158
159        project4 = Project('project4', config)
160        self.assertEqual(project4.rootdir, getcwd())
Note: See TracBrowser for help on using the repository browser.