annotate tests/test_util.py @ 242:06130689a2c8

Move push into svncommands.
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Wed, 08 Apr 2009 17:53:48 +0200
parents 4950b18cf949
children ffccf0080e54
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
1 import errno
14
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2 import os
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
3 import subprocess
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
4 import shutil
91
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
5 import StringIO
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
6 import stat
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
7 import tempfile
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
8 import unittest
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
9 import urllib
14
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
10
84
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
11 from mercurial import context
22
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
12 from mercurial import hg
84
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
13 from mercurial import node
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
14 from mercurial import ui
22
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
15
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 231
diff changeset
16 import svncommands
22
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
17
194
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents: 170
diff changeset
18 # Fixtures that need to be pulled at a subdirectory of the repo path
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents: 170
diff changeset
19 subdir = {'truncatedhistory.svndump': '/project2',
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents: 170
diff changeset
20 'fetch_missing_files_subdir.svndump': '/foo',
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents: 170
diff changeset
21 }
13ae1bded5e7 Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents: 170
diff changeset
22
14
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
23 FIXTURES = os.path.join(os.path.abspath(os.path.dirname(__file__)),
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
24 'fixtures')
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
25
91
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
26 def fileurl(path):
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
27 path = os.path.abspath(path)
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
28 drive, path = os.path.splitdrive(path)
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
29 path = urllib.pathname2url(path)
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
30 if drive:
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
31 drive = '/' + drive
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
32 url = 'file://%s%s' % (drive, path)
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
33 return url
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
34
14
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
35 def load_svndump_fixture(path, fixture_name):
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
36 '''Loads an svnadmin dump into a fresh repo at path, which should not
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
37 already exist.
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
38 '''
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
39 subprocess.call(['svnadmin', 'create', path,])
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
40 proc = subprocess.Popen(['svnadmin', 'load', path,], stdin=subprocess.PIPE,
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
41 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
14
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
42 inp = open(os.path.join(FIXTURES, fixture_name))
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
43 proc.stdin.write(inp.read())
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
44 proc.stdin.flush()
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
45 proc.communicate()
22
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
46
112
e58c2f1de059 Fix a regression in converting repositories with files copied in from outside
Augie Fackler <durin42@gmail.com>
parents: 96
diff changeset
47 def load_fixture_and_fetch(fixture_name, repo_path, wc_path, stupid=False, subdir=''):
22
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
48 load_svndump_fixture(repo_path, fixture_name)
112
e58c2f1de059 Fix a regression in converting repositories with files copied in from outside
Augie Fackler <durin42@gmail.com>
parents: 96
diff changeset
49 if subdir:
e58c2f1de059 Fix a regression in converting repositories with files copied in from outside
Augie Fackler <durin42@gmail.com>
parents: 96
diff changeset
50 repo_path += '/' + subdir
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 231
diff changeset
51 svncommands.pull(ui.ui(), svn_url=fileurl(repo_path),
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 231
diff changeset
52 hg_repo_path=wc_path, stupid=stupid)
22
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
53 repo = hg.repository(ui.ui(), wc_path)
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
54 return repo
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
55
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
56 def rmtree(path):
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
57 # Read-only files cannot be removed under Windows
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
58 for root, dirs, files in os.walk(path):
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
59 for f in files:
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
60 f = os.path.join(root, f)
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
61 try:
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
62 s = os.stat(f)
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
63 except OSError, e:
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
64 if e.errno == errno.ENOENT:
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
65 continue
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
66 raise
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
67 if (s.st_mode & stat.S_IWRITE) == 0:
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
68 os.chmod(f, s.st_mode | stat.S_IWRITE)
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
69 shutil.rmtree(path)
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
70
91
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
71
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
72 class MockUI(object):
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
73 real_ui = ui.ui
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
74 _isatty = False
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
75 def __init__(self, parentui=None):
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
76 self.stream = StringIO.StringIO()
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
77 self.inner_ui = self.real_ui(parentui=parentui)
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
78
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
79 def status(self, *args):
139
89a737852d33 utility_commands: Add tests for url and info. Fix a bad mock in the process.
Augie Fackler <durin42@gmail.com>
parents: 138
diff changeset
80 self.stream.write(''.join(args))
91
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
81
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
82 def warn(self, *args):
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
83 self.stream.write(*args)
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
84
138
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 112
diff changeset
85 def write(self, *args):
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 112
diff changeset
86 self.stream.write(*args)
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 112
diff changeset
87
91
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
88 def __getattr__(self, attr):
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
89 return getattr(self.inner_ui, attr)
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
90
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
91
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
92 class TestBase(unittest.TestCase):
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
93 def setUp(self):
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
94 self.oldwd = os.getcwd()
148
0c5f6420a8b5 tests: Add an environment variable (HGSUBVERSION_TEST_TEMP) which allows
Augie Fackler <durin42@gmail.com>
parents: 139
diff changeset
95 self.tmpdir = tempfile.mkdtemp(
0c5f6420a8b5 tests: Add an environment variable (HGSUBVERSION_TEST_TEMP) which allows
Augie Fackler <durin42@gmail.com>
parents: 139
diff changeset
96 'svnwrap_test', dir=os.environ.get('HGSUBVERSION_TEST_TEMP', None))
231
b1543f243910 tests: Start providing our own custom hgrc for testing purposes.
Augie Fackler <durin42@gmail.com>
parents: 194
diff changeset
97 self.hgrc = os.path.join(self.tmpdir, '.hgrc')
b1543f243910 tests: Start providing our own custom hgrc for testing purposes.
Augie Fackler <durin42@gmail.com>
parents: 194
diff changeset
98 os.environ['HGRCPATH'] = self.hgrc
b1543f243910 tests: Start providing our own custom hgrc for testing purposes.
Augie Fackler <durin42@gmail.com>
parents: 194
diff changeset
99 rc = open(self.hgrc, 'w')
b1543f243910 tests: Start providing our own custom hgrc for testing purposes.
Augie Fackler <durin42@gmail.com>
parents: 194
diff changeset
100 rc.write('[extensions]\nhgsubversion=')
148
0c5f6420a8b5 tests: Add an environment variable (HGSUBVERSION_TEST_TEMP) which allows
Augie Fackler <durin42@gmail.com>
parents: 139
diff changeset
101
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
102 self.repo_path = '%s/testrepo' % self.tmpdir
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
103 self.wc_path = '%s/testrepo_wc' % self.tmpdir
91
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
104 self._real_ui = ui.ui
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
105 ui.ui = MockUI
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
106
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
107 def tearDown(self):
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
108 rmtree(self.tmpdir)
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
109 os.chdir(self.oldwd)
91
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
110 ui.ui = self._real_ui
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
111
138
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 112
diff changeset
112 def _load_fixture_and_fetch(self, fixture_name, subdir='', stupid=False):
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 112
diff changeset
113 return load_fixture_and_fetch(fixture_name, self.repo_path,
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 112
diff changeset
114 self.wc_path, subdir=subdir,
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 112
diff changeset
115 stupid=stupid)
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 112
diff changeset
116
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
117 # define this as a property so that it reloads anytime we need it
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
118 @property
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
119 def repo(self):
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
120 return hg.repository(ui.ui(), self.wc_path)
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
121
96
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
122 def pushrevisions(self, stupid=False):
170
d046bef502d7 test_util: check all committed revisions are pushed
Patrick Mezard <pmezard@gmail.com>
parents: 148
diff changeset
123 before = len(self.repo)
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
124 svncommands.push(ui.ui(), repo=self.repo, hg_repo_path=self.wc_path,
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
125 svn_url=fileurl(self.repo_path), stupid=stupid)
170
d046bef502d7 test_util: check all committed revisions are pushed
Patrick Mezard <pmezard@gmail.com>
parents: 148
diff changeset
126 after = len(self.repo)
d046bef502d7 test_util: check all committed revisions are pushed
Patrick Mezard <pmezard@gmail.com>
parents: 148
diff changeset
127 self.assertEqual(0, after - before)
83
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
128
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
129 def svnls(self, path, rev='HEAD'):
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
130 path = self.repo_path + '/' + path
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
131 path = fileurl(path)
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
132 args = ['svn', 'ls', '-r', rev, '-R', path]
91
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
133 p = subprocess.Popen(args,
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
134 stdout=subprocess.PIPE,
83
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
135 stderr=subprocess.PIPE)
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
136 stdout, stderr = p.communicate()
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
137 if p.returncode:
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
138 raise Exception('svn ls failed on %s: %r' % (path, stderr))
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
139 entries = [e.strip('/') for e in stdout.splitlines()]
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
140 entries.sort()
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
141 return entries
84
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
142
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
143 def commitchanges(self, changes):
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
144 """Commit changes to mercurial directory
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
145
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
146 'changes' is a sequence of tuples (source, dest, data). It can look
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
147 like:
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
148 - (source, source, data) to set source content to data
91
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
149 - (source, dest, None) to set dest content to source one, and mark it as
84
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
150 copied from source.
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
151 - (source, dest, data) to set dest content to data, and mark it as copied
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
152 from source.
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
153 - (source, None, None) to remove source.
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
154 """
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
155 repo = self.repo
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
156 parentctx = repo['tip']
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
157
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
158 changed, removed = [], []
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
159 for source, dest, newdata in changes:
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
160 if dest is None:
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
161 removed.append(source)
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
162 else:
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
163 changed.append(dest)
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
164
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
165 def filectxfn(repo, memctx, path):
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
166 if path in removed:
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
167 raise IOError()
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
168 entry = [e for e in changes if path == e[1]][0]
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
169 source, dest, newdata = entry
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
170 if newdata is None:
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
171 newdata = parentctx[source].data()
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
172 copied = None
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
173 if source != dest:
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
174 copied = source
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
175 return context.memfilectx(path=dest,
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
176 data=newdata,
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
177 islink=False,
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
178 isexec=False,
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
179 copied=copied)
91
7d10165cf3d9 tests: Mock the mercurial.ui.ui class like we really should to capture output.
Augie Fackler <durin42@gmail.com>
parents: 84
diff changeset
180
84
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
181 ctx = context.memctx(repo,
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
182 (parentctx.node(), node.nullid),
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
183 'automated test',
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
184 changed + removed,
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
185 filectxfn,
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
186 'an_author',
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
187 '2008-10-07 20:59:48 -0500')
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
188 nodeid = repo.commitctx(ctx)
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
189 repo = self.repo
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
190 hg.update(repo, nodeid)
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
191 return nodeid
96
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
192
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
193 def assertchanges(self, changes, ctx):
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
194 """Assert that all 'changes' (as in defined in commitchanged())
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
195 went into ctx.
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
196 """
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
197 for source, dest, data in changes:
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
198 if dest is None:
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
199 self.assertTrue(source not in ctx)
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
200 continue
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
201 self.assertTrue(dest in ctx)
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
202 if data is None:
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
203 data = ctx.parents()[0][source].data()
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
204 self.assertEqual(ctx[dest].data(), data)
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
205 if dest != source:
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
206 copy = ctx[dest].renamed()
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
207 self.assertEqual(copy[0], source)