| 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, TestSuite |
|---|
| 9 | from cStringIO import StringIO |
|---|
| 10 | from vcpx.config import Config, ConfigurationError |
|---|
| 11 | from vcpx.project import Project |
|---|
| 12 | |
|---|
| 13 | class 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] |
|---|
| 34 | verbose = False |
|---|
| 35 | target-module = None |
|---|
| 36 | projects = project2 |
|---|
| 37 | |
|---|
| 38 | [project1] |
|---|
| 39 | root-directory = /tmp/tailor-tests |
|---|
| 40 | source = svn:project1repo |
|---|
| 41 | target = darcs:project1repo |
|---|
| 42 | refill-changelogs = Yes |
|---|
| 43 | state-file = project1.state |
|---|
| 44 | before-commit = (maybe_skip, refill, p1_remap_authors) |
|---|
| 45 | after-commit = checkpoint |
|---|
| 46 | |
|---|
| 47 | [svn:project1repo] |
|---|
| 48 | repository = svn://some.server/svn |
|---|
| 49 | module = project1 |
|---|
| 50 | use-propset = Yes |
|---|
| 51 | |
|---|
| 52 | [darcs:project1repo] |
|---|
| 53 | repository = ~/darcs/project1 |
|---|
| 54 | |
|---|
| 55 | [monotone:project1repo] |
|---|
| 56 | repository = /tmp/db |
|---|
| 57 | passphrase = simba |
|---|
| 58 | |
|---|
| 59 | [project2] |
|---|
| 60 | root-directory = /tmp/tailor-tests |
|---|
| 61 | source = darcs:project1repo |
|---|
| 62 | target = svn:project2repo |
|---|
| 63 | refill-changelogs = Yes |
|---|
| 64 | state-file = project2.state |
|---|
| 65 | before-commit = refill |
|---|
| 66 | |
|---|
| 67 | [svn:project2repo] |
|---|
| 68 | |
|---|
| 69 | [project3] |
|---|
| 70 | root-directory = /tmp/tailor-tests |
|---|
| 71 | source = svndump:project3repo |
|---|
| 72 | target = darcs:project3repo |
|---|
| 73 | |
|---|
| 74 | [svndump:project3repo] |
|---|
| 75 | repository = %(tailor_repo)s/vcpx/tests/data/simple.svndump |
|---|
| 76 | subdir = plain |
|---|
| 77 | |
|---|
| 78 | [darcs:project3repo] |
|---|
| 79 | subdir = . |
|---|
| 80 | |
|---|
| 81 | [project4] |
|---|
| 82 | source = svndump:project3repo |
|---|
| 83 | target = darcs:project4repo |
|---|
| 84 | |
|---|
| 85 | [darcs:project4repo] |
|---|
| 86 | subdir = darcs |
|---|
| 87 | ''' |
|---|
| 88 | |
|---|
| 89 | def 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 | |
|---|
| 96 | def refill(context, changeset): |
|---|
| 97 | changeset.refillChangelog() |
|---|
| 98 | return True |
|---|
| 99 | |
|---|
| 100 | p1_authors_map = { |
|---|
| 101 | 'lele': 'Lele Gaifax <lele@example.com>', |
|---|
| 102 | 'x123': 'A man ... with a name to come', |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | def 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 | |
|---|
| 110 | def 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()) |
|---|