| 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 | |
|---|
| 8 | from unittest import TestCase |
|---|
| 9 | from vcpx.config import Config, ConfigurationError |
|---|
| 10 | from vcpx.project import Project |
|---|
| 11 | |
|---|
| 12 | class Configuration(TestCase): |
|---|
| 13 | "Test the configuration system" |
|---|
| 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 | def getTestConfiguration(self, testname): |
|---|
| 31 | from os.path import join, split |
|---|
| 32 | |
|---|
| 33 | logname = join(split(__file__)[0], 'data', testname)+'.py' |
|---|
| 34 | return file(logname) |
|---|
| 35 | |
|---|
| 36 | def testBasicConfig(self): |
|---|
| 37 | """Verify the basic configuration mechanism""" |
|---|
| 38 | |
|---|
| 39 | from os import getcwd |
|---|
| 40 | from os.path import expanduser |
|---|
| 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 | self.assertEqual(project1.source.name, 'svn:project1repo') |
|---|
| 51 | self.assertEqual(project1.target.name, 'darcs:project1') |
|---|
| 52 | self.assertEqual(project1.target.repository, expanduser('~/darcs/project1')) |
|---|
| 53 | |
|---|
| 54 | project4 = Project('project4', config) |
|---|
| 55 | self.assertEqual(project4.rootdir, getcwd()) |
|---|
| 56 | |
|---|
| 57 | self.assert_(config.namespace.has_key('maybe_skip')) |
|---|
| 58 | self.assert_(config.namespace['refill'] in project1.before_commit) |
|---|
| 59 | self.assertEqual(len(project1.after_commit), 1) |
|---|
| 60 | |
|---|
| 61 | def testSharedDirs(self): |
|---|
| 62 | """Verify the shared-dir switch""" |
|---|
| 63 | |
|---|
| 64 | config = Config(self.getTestConfiguration("config-basic_test"), |
|---|
| 65 | {'tailor_repo': self.tailor_repo}) |
|---|
| 66 | |
|---|
| 67 | project1 = Project('project1', config) |
|---|
| 68 | wd = project1.workingDir() |
|---|
| 69 | self.assert_(wd.shared_basedirs) |
|---|
| 70 | |
|---|
| 71 | project3 = Project('project3', config) |
|---|
| 72 | wd = project3.workingDir() |
|---|
| 73 | self.assert_(wd.shared_basedirs) |
|---|
| 74 | |
|---|
| 75 | project4 = Project('project4', config) |
|---|
| 76 | wd = project4.workingDir() |
|---|
| 77 | self.assert_(not wd.shared_basedirs) |
|---|
| 78 | |
|---|
| 79 | def testWithLogging(self): |
|---|
| 80 | """Verify a configuration containing also a [[logging]] section""" |
|---|
| 81 | |
|---|
| 82 | from logging import getLogger |
|---|
| 83 | |
|---|
| 84 | config = Config(self.getTestConfiguration("config-with_logging"), {}) |
|---|
| 85 | |
|---|
| 86 | logger = getLogger() |
|---|
| 87 | self.assertEqual(logger.handlers[0].formatter._fmt, 'DUMMY') |
|---|
| 88 | |
|---|
| 89 | def testLookForAdds(self): |
|---|
| 90 | """Verify the darcs Repository knows about --look-for-adds""" |
|---|
| 91 | |
|---|
| 92 | config = Config(self.getTestConfiguration("config-basic_test"), |
|---|
| 93 | {'tailor_repo': self.tailor_repo}) |
|---|
| 94 | |
|---|
| 95 | project3 = Project('project3', config) |
|---|
| 96 | self.assertEqual(project3.target.command('record', '-a'), |
|---|
| 97 | ['darcs', 'record', '-a']) |
|---|
| 98 | project4 = Project('project4', config) |
|---|
| 99 | self.assertEqual(project4.target.command('record', '-a'), |
|---|
| 100 | ['darcs', 'record', '-a', '--look-for-adds']) |
|---|
| 101 | |
|---|
| 102 | def testTagEntries(self): |
|---|
| 103 | """Verify the darcs Repository knows when force CVS tag on entries""" |
|---|
| 104 | |
|---|
| 105 | config = Config(self.getTestConfiguration("config-basic_test"), |
|---|
| 106 | {'tailor_repo': self.tailor_repo}) |
|---|
| 107 | |
|---|
| 108 | project5 = Project('project5', config) |
|---|
| 109 | self.assertEqual(project5.source.tag_entries, True) |
|---|
| 110 | self.assertEqual(project5.target.tag_entries, False) |
|---|
| 111 | |
|---|
| 112 | def testStateFileName(self): |
|---|
| 113 | """Verify that the state file is computed the way it should""" |
|---|
| 114 | |
|---|
| 115 | from os.path import expanduser |
|---|
| 116 | |
|---|
| 117 | config = Config(self.getTestConfiguration("config-basic_test"), |
|---|
| 118 | {'tailor_repo': self.tailor_repo}) |
|---|
| 119 | |
|---|
| 120 | project1 = Project('project1', config) |
|---|
| 121 | self.assertEqual(project1.state_file.filename, '/tmp/tailor-tests/project1.state') |
|---|
| 122 | project3 = Project('project3', config) |
|---|
| 123 | self.assertEqual(project3.state_file.filename, '/tmp/tailor-tests/_darcs/tailor.state') |
|---|
| 124 | project4 = Project('project4', config) |
|---|
| 125 | self.assertEqual(project4.state_file.filename, expanduser('~/tailorize/project4.state')) |
|---|
| 126 | project6 = Project('project6', config) |
|---|
| 127 | self.assertEqual(project6.state_file.filename, expanduser('~/tailorizedp/project6/.hg/tailor.state')) |
|---|
| 128 | |
|---|
| 129 | config = Config(self.getTestConfiguration("config-sf_test"), {}) |
|---|
| 130 | sbcl = Project('sbcl', config) |
|---|
| 131 | self.assertEqual(sbcl.state_file.filename, expanduser('~/tmp/test-tailor/sbcl/.hg/tailor.state')) |
|---|
| 132 | |
|---|
| 133 | def testBadChars(self): |
|---|
| 134 | """Test how the config parser loads the badchar mapping""" |
|---|
| 135 | |
|---|
| 136 | config = Config(self.getTestConfiguration("config-basic_test"), |
|---|
| 137 | {'tailor_repo': self.tailor_repo}) |
|---|
| 138 | project4 = Project('project4', config) |
|---|
| 139 | self.assert_(project4.target.replace_badchars.has_key('\xc1')) |
|---|
| 140 | project6 = Project('project6', config) |
|---|
| 141 | self.assertEqual(project6.source.replace_badchars['a'], 'b') |
|---|