annotate tests/test_util.py @ 772:f3af4fe98d37

test_util: make manifest filter use shared list of files to ignore
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Tue, 30 Nov 2010 02:54:11 +0100
parents bc5c176b63eb
children e698be84c22d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
492
50d77547c218 test_util: sort imports
Augie Fackler <durin42@gmail.com>
parents: 487
diff changeset
1 import StringIO
548
2148eb4b4da4 test_util: add assertStringEqual to output diff output for string checks
Augie Fackler <durin42@gmail.com>
parents: 546
diff changeset
2 import difflib
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
3 import errno
492
50d77547c218 test_util: sort imports
Augie Fackler <durin42@gmail.com>
parents: 487
diff changeset
4 import gettext
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 342
diff changeset
5 import imp
14
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
6 import os
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
7 import shutil
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
8 import stat
492
50d77547c218 test_util: sort imports
Augie Fackler <durin42@gmail.com>
parents: 487
diff changeset
9 import subprocess
50d77547c218 test_util: sort imports
Augie Fackler <durin42@gmail.com>
parents: 487
diff changeset
10 import sys
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
11 import tempfile
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
12 import unittest
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
13 import urllib
14
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
14
644
95abc4cfc78f tests: improve import logic
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 626
diff changeset
15 _rootdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
95abc4cfc78f tests: improve import logic
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 626
diff changeset
16 sys.path.insert(0, _rootdir)
347
537de0300510 Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 342
diff changeset
17
711
cfc7df19e4dc test_util: add requiresoption decorator function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 706
diff changeset
18 from mercurial import cmdutil
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 326
diff changeset
19 from mercurial import commands
492
50d77547c218 test_util: sort imports
Augie Fackler <durin42@gmail.com>
parents: 487
diff changeset
20 from mercurial import context
706
1f1a3a6730c1 test_util: use the Mercurial dispatch logic for cloning repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 696
diff changeset
21 from mercurial import dispatch
22
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
22 from mercurial import hg
492
50d77547c218 test_util: sort imports
Augie Fackler <durin42@gmail.com>
parents: 487
diff changeset
23 from mercurial import i18n
84
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
24 from mercurial import node
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
25 from mercurial import ui
772
f3af4fe98d37 test_util: make manifest filter use shared list of files to ignore
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 764
diff changeset
26 from mercurial import util
527
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
27 from mercurial import extensions
22
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
28
716
38ebf7714cdf requiresoption: raise SkipTest if available
Augie Fackler <durin42@gmail.com>
parents: 715
diff changeset
29 try:
734
e24fb3e27ec9 test_util: use SkipTest if provided by the unittest module.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 727
diff changeset
30 SkipTest = unittest.SkipTest
e24fb3e27ec9 test_util: use SkipTest if provided by the unittest module.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 727
diff changeset
31 except AttributeError:
716
38ebf7714cdf requiresoption: raise SkipTest if available
Augie Fackler <durin42@gmail.com>
parents: 715
diff changeset
32 try:
734
e24fb3e27ec9 test_util: use SkipTest if provided by the unittest module.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 727
diff changeset
33 from unittest2 import SkipTest
716
38ebf7714cdf requiresoption: raise SkipTest if available
Augie Fackler <durin42@gmail.com>
parents: 715
diff changeset
34 except ImportError:
734
e24fb3e27ec9 test_util: use SkipTest if provided by the unittest module.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 727
diff changeset
35 try:
e24fb3e27ec9 test_util: use SkipTest if provided by the unittest module.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 727
diff changeset
36 from nose import SkipTest
e24fb3e27ec9 test_util: use SkipTest if provided by the unittest module.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 727
diff changeset
37 except ImportError:
e24fb3e27ec9 test_util: use SkipTest if provided by the unittest module.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 727
diff changeset
38 SkipTest = None
716
38ebf7714cdf requiresoption: raise SkipTest if available
Augie Fackler <durin42@gmail.com>
parents: 715
diff changeset
39
337
46e69be8e2c8 Reorganize to have a more conventional module structure.
Augie Fackler <durin42@gmail.com>
parents: 334
diff changeset
40 from hgsubversion import util
333
a59ab58969d9 test_util: normalize path in svnls()
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 331
diff changeset
41
479
83fcb1cf6d8f Avoid 'ValueError: close_fds is not supported on Windows platforms' exception
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 355
diff changeset
42 # Documentation for Subprocess.Popen() says:
83fcb1cf6d8f Avoid 'ValueError: close_fds is not supported on Windows platforms' exception
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 355
diff changeset
43 # "Note that on Windows, you cannot set close_fds to true and
83fcb1cf6d8f Avoid 'ValueError: close_fds is not supported on Windows platforms' exception
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 355
diff changeset
44 # also redirect the standard handles by setting stdin, stdout or
83fcb1cf6d8f Avoid 'ValueError: close_fds is not supported on Windows platforms' exception
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 355
diff changeset
45 # stderr."
83fcb1cf6d8f Avoid 'ValueError: close_fds is not supported on Windows platforms' exception
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 355
diff changeset
46 canCloseFds='win32' not in sys.platform
83fcb1cf6d8f Avoid 'ValueError: close_fds is not supported on Windows platforms' exception
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 355
diff changeset
47
483
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
48 if not 'win32' in sys.platform:
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
49 def kill_process(popen_obj):
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
50 os.kill(popen_obj.pid, 9)
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
51 else:
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
52 import ctypes
487
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
53 from ctypes.wintypes import BOOL, DWORD, HANDLE, UINT
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
54
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
55 def win_status_check(result, func, args):
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
56 if result == 0:
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
57 raise ctypes.WinError()
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
58 return args
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
59
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
60 def WINAPI(returns, func, *params):
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
61 assert len(params) % 2 == 0
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
62
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
63 func.argtypes = tuple(params[0::2])
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
64 func.resvalue = returns
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
65 func.errcheck = win_status_check
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
66
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
67 return func
483
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
68
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
69 # dwDesiredAccess
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
70 PROCESS_TERMINATE = 0x0001
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
71
487
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
72 OpenProcess = WINAPI(HANDLE, ctypes.windll.kernel32.OpenProcess,
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
73 DWORD, 'dwDesiredAccess',
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
74 BOOL, 'bInheritHandle',
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
75 DWORD, 'dwProcessId',
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
76 )
483
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
77
487
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
78 CloseHandle = WINAPI(BOOL, ctypes.windll.kernel32.CloseHandle,
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
79 HANDLE, 'hObject'
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
80 )
483
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
81
487
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
82 TerminateProcess = WINAPI(BOOL, ctypes.windll.kernel32.TerminateProcess,
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
83 HANDLE, 'hProcess',
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
84 UINT, 'uExitCode'
6b481331c355 test_util: fix up line endings
Augie Fackler <durin42@gmail.com>
parents: 486
diff changeset
85 )
483
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
86
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
87 def kill_process(popen_obj):
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
88 phnd = OpenProcess(PROCESS_TERMINATE, False, popen_obj.pid)
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
89 TerminateProcess(phnd, 1)
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
90 CloseHandle(phnd)
37718f514acb No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
Risto Kankkunen <risto.kankkunen@iki.fi>
parents: 479
diff changeset
91
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
92 # 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
93 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
94 'fetch_missing_files_subdir.svndump': '/foo',
270
2848d17eae71 Fix rebuildmeta tests for empty_dir_in_trunk_not_repo_root
Augie Fackler <durin42@gmail.com>
parents: 257
diff changeset
95 'empty_dir_in_trunk_not_repo_root.svndump': '/project',
351
3d5c4352a6c8 test_util: Add another missing project root.
Augie Fackler <durin42@gmail.com>
parents: 347
diff changeset
96 'project_root_not_repo_root.svndump': '/dummyproj',
512
c421e6bf0d95 tests: test paths with spaces
Augie Fackler <durin42@gmail.com>
parents: 511
diff changeset
97 'project_name_with_space.svndump': '/project name',
717
ae5968ffe6fe svnwrap: fix handling of quotable URLs (fixes #197, refs #132)
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 716
diff changeset
98 'non_ascii_path_1.svndump': '/b\xC3\xB8b',
ae5968ffe6fe svnwrap: fix handling of quotable URLs (fixes #197, refs #132)
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 716
diff changeset
99 'non_ascii_path_2.svndump': '/b%C3%B8b',
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
100 }
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
101
14
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
102 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
103 'fixtures')
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
104
719
ae52a3b30cfb test_util: refactor requiresoption to ease creation of other skip decorators
Augie Fackler <durin42@gmail.com>
parents: 717
diff changeset
105
ae52a3b30cfb test_util: refactor requiresoption to ease creation of other skip decorators
Augie Fackler <durin42@gmail.com>
parents: 717
diff changeset
106 def _makeskip(name, message):
727
e830b592917b tests: fix test skipping in pure unittest
Augie Fackler <durin42@gmail.com>
parents: 720
diff changeset
107 if SkipTest:
e830b592917b tests: fix test skipping in pure unittest
Augie Fackler <durin42@gmail.com>
parents: 720
diff changeset
108 def skip(*args, **kwargs):
e830b592917b tests: fix test skipping in pure unittest
Augie Fackler <durin42@gmail.com>
parents: 720
diff changeset
109 raise SkipTest(message)
e830b592917b tests: fix test skipping in pure unittest
Augie Fackler <durin42@gmail.com>
parents: 720
diff changeset
110 skip.__name__ = name
e830b592917b tests: fix test skipping in pure unittest
Augie Fackler <durin42@gmail.com>
parents: 720
diff changeset
111 return skip
719
ae52a3b30cfb test_util: refactor requiresoption to ease creation of other skip decorators
Augie Fackler <durin42@gmail.com>
parents: 717
diff changeset
112
720
a19a208c085b test_util: new requiresmodule decorator for tests that require a feature
Augie Fackler <durin42@gmail.com>
parents: 719
diff changeset
113 def requiresmodule(mod):
a19a208c085b test_util: new requiresmodule decorator for tests that require a feature
Augie Fackler <durin42@gmail.com>
parents: 719
diff changeset
114 """Skip a test if the specified module is not None."""
a19a208c085b test_util: new requiresmodule decorator for tests that require a feature
Augie Fackler <durin42@gmail.com>
parents: 719
diff changeset
115 def decorator(fn):
727
e830b592917b tests: fix test skipping in pure unittest
Augie Fackler <durin42@gmail.com>
parents: 720
diff changeset
116 if fn is None:
e830b592917b tests: fix test skipping in pure unittest
Augie Fackler <durin42@gmail.com>
parents: 720
diff changeset
117 return
720
a19a208c085b test_util: new requiresmodule decorator for tests that require a feature
Augie Fackler <durin42@gmail.com>
parents: 719
diff changeset
118 if mod is not None:
a19a208c085b test_util: new requiresmodule decorator for tests that require a feature
Augie Fackler <durin42@gmail.com>
parents: 719
diff changeset
119 return fn
a19a208c085b test_util: new requiresmodule decorator for tests that require a feature
Augie Fackler <durin42@gmail.com>
parents: 719
diff changeset
120 return _makeskip(fn.__name__, 'missing required feature')
a19a208c085b test_util: new requiresmodule decorator for tests that require a feature
Augie Fackler <durin42@gmail.com>
parents: 719
diff changeset
121 return decorator
a19a208c085b test_util: new requiresmodule decorator for tests that require a feature
Augie Fackler <durin42@gmail.com>
parents: 719
diff changeset
122
a19a208c085b test_util: new requiresmodule decorator for tests that require a feature
Augie Fackler <durin42@gmail.com>
parents: 719
diff changeset
123
711
cfc7df19e4dc test_util: add requiresoption decorator function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 706
diff changeset
124 def requiresoption(option):
715
c33293a34752 requiresoption: clean up docstring
Augie Fackler <durin42@gmail.com>
parents: 711
diff changeset
125 '''Skip a test if commands.clone does not take the specified option.'''
711
cfc7df19e4dc test_util: add requiresoption decorator function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 706
diff changeset
126 def decorator(fn):
cfc7df19e4dc test_util: add requiresoption decorator function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 706
diff changeset
127 for entry in cmdutil.findcmd('clone', commands.table)[1][1]:
cfc7df19e4dc test_util: add requiresoption decorator function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 706
diff changeset
128 if entry[1] == option:
cfc7df19e4dc test_util: add requiresoption decorator function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 706
diff changeset
129 return fn
716
38ebf7714cdf requiresoption: raise SkipTest if available
Augie Fackler <durin42@gmail.com>
parents: 715
diff changeset
130 # no match found, so skip
38ebf7714cdf requiresoption: raise SkipTest if available
Augie Fackler <durin42@gmail.com>
parents: 715
diff changeset
131 if SkipTest:
719
ae52a3b30cfb test_util: refactor requiresoption to ease creation of other skip decorators
Augie Fackler <durin42@gmail.com>
parents: 717
diff changeset
132 return _makeskip(fn.__name__,
ae52a3b30cfb test_util: refactor requiresoption to ease creation of other skip decorators
Augie Fackler <durin42@gmail.com>
parents: 717
diff changeset
133 'test requires clone to accept %s' % option)
716
38ebf7714cdf requiresoption: raise SkipTest if available
Augie Fackler <durin42@gmail.com>
parents: 715
diff changeset
134 # no skipping support, so erase decorated method
38ebf7714cdf requiresoption: raise SkipTest if available
Augie Fackler <durin42@gmail.com>
parents: 715
diff changeset
135 return
711
cfc7df19e4dc test_util: add requiresoption decorator function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 706
diff changeset
136 if not isinstance(option, str):
cfc7df19e4dc test_util: add requiresoption decorator function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 706
diff changeset
137 raise TypeError('requiresoption takes a string argument')
cfc7df19e4dc test_util: add requiresoption decorator function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 706
diff changeset
138 return decorator
cfc7df19e4dc test_util: add requiresoption decorator function.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 706
diff changeset
139
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 492
diff changeset
140 def filtermanifest(manifest):
772
f3af4fe98d37 test_util: make manifest filter use shared list of files to ignore
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 764
diff changeset
141 return [f for f in manifest if f not in util.ignoredfiles]
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 492
diff changeset
142
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
143 def fileurl(path):
522
60bf433647e7 test_util: fix Windows test URLs
Patrick Mezard <pmezard@gmail.com>
parents: 516
diff changeset
144 path = os.path.abspath(path).replace(os.sep, '/')
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
145 drive, path = os.path.splitdrive(path)
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
146 if drive:
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
147 drive = '/' + drive
342
76c833526fbc Use fallbacks in the wrappers for Subversion support, instead of prefixes.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 337
diff changeset
148 url = 'file://%s%s' % (drive, path)
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
149 return url
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
150
652
c3900ad3bf69 test_util: support specifying a start revision
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 645
diff changeset
151 def testui(stupid=False, layout='auto', startrev=0):
576
d96aa92d9ad9 tests: silence test suite by using quiet UIs everywhere
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 548
diff changeset
152 u = ui.ui()
d96aa92d9ad9 tests: silence test suite by using quiet UIs everywhere
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 548
diff changeset
153 bools = {True: 'true', False: 'false'}
d96aa92d9ad9 tests: silence test suite by using quiet UIs everywhere
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 548
diff changeset
154 u.setconfig('ui', 'quiet', bools[True])
696
c11bf0dd38d3 tests: enable hgsubversion in the generated UI.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 689
diff changeset
155 u.setconfig('extensions', 'hgsubversion', '')
576
d96aa92d9ad9 tests: silence test suite by using quiet UIs everywhere
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 548
diff changeset
156 u.setconfig('hgsubversion', 'stupid', bools[stupid])
d96aa92d9ad9 tests: silence test suite by using quiet UIs everywhere
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 548
diff changeset
157 u.setconfig('hgsubversion', 'layout', layout)
652
c3900ad3bf69 test_util: support specifying a start revision
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 645
diff changeset
158 u.setconfig('hgsubversion', 'startrev', startrev)
576
d96aa92d9ad9 tests: silence test suite by using quiet UIs everywhere
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 548
diff changeset
159 return u
d96aa92d9ad9 tests: silence test suite by using quiet UIs everywhere
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 548
diff changeset
160
14
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
161 def load_svndump_fixture(path, fixture_name):
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
162 '''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
163 already exist.
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
164 '''
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 326
diff changeset
165 if os.path.exists(path): rmtree(path)
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 326
diff changeset
166 subprocess.call(['svnadmin', 'create', path,],
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 326
diff changeset
167 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
14
d78dbf88c13d Started a meaningful test suite.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
168 inp = open(os.path.join(FIXTURES, fixture_name))
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 326
diff changeset
169 proc = subprocess.Popen(['svnadmin', 'load', path,], stdin=inp,
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 326
diff changeset
170 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
171 proc.communicate()
22
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
172
652
c3900ad3bf69 test_util: support specifying a start revision
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 645
diff changeset
173 def load_fixture_and_fetch(fixture_name, repo_path, wc_path, stupid=False,
c3900ad3bf69 test_util: support specifying a start revision
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 645
diff changeset
174 subdir='', noupdate=True, layout='auto',
762
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 744
diff changeset
175 startrev=0, externals=None):
22
95d0109e495e Refactor tests so I can reuse code more.
Augie Fackler <durin42@gmail.com>
parents: 16
diff changeset
176 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
177 if subdir:
e58c2f1de059 Fix a regression in converting repositories with files copied in from outside
Augie Fackler <durin42@gmail.com>
parents: 96
diff changeset
178 repo_path += '/' + subdir
706
1f1a3a6730c1 test_util: use the Mercurial dispatch logic for cloning repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 696
diff changeset
179
1f1a3a6730c1 test_util: use the Mercurial dispatch logic for cloning repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 696
diff changeset
180 cmd = [
1f1a3a6730c1 test_util: use the Mercurial dispatch logic for cloning repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 696
diff changeset
181 'clone',
1f1a3a6730c1 test_util: use the Mercurial dispatch logic for cloning repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 696
diff changeset
182 '--layout=%s' % layout,
1f1a3a6730c1 test_util: use the Mercurial dispatch logic for cloning repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 696
diff changeset
183 '--startrev=%s' % startrev,
1f1a3a6730c1 test_util: use the Mercurial dispatch logic for cloning repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 696
diff changeset
184 fileurl(repo_path),
1f1a3a6730c1 test_util: use the Mercurial dispatch logic for cloning repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 696
diff changeset
185 wc_path,
1f1a3a6730c1 test_util: use the Mercurial dispatch logic for cloning repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 696
diff changeset
186 ]
1f1a3a6730c1 test_util: use the Mercurial dispatch logic for cloning repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 696
diff changeset
187 if stupid:
1f1a3a6730c1 test_util: use the Mercurial dispatch logic for cloning repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 696
diff changeset
188 cmd.append('--stupid')
1f1a3a6730c1 test_util: use the Mercurial dispatch logic for cloning repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 696
diff changeset
189 if noupdate:
1f1a3a6730c1 test_util: use the Mercurial dispatch logic for cloning repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 696
diff changeset
190 cmd.append('--noupdate')
762
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 744
diff changeset
191 if externals:
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 744
diff changeset
192 cmd[:0] = ['--config', 'hgsubversion.externals=%s' % externals]
706
1f1a3a6730c1 test_util: use the Mercurial dispatch logic for cloning repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 696
diff changeset
193
1f1a3a6730c1 test_util: use the Mercurial dispatch logic for cloning repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 696
diff changeset
194 dispatch.dispatch(cmd)
1f1a3a6730c1 test_util: use the Mercurial dispatch logic for cloning repositories.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 696
diff changeset
195
576
d96aa92d9ad9 tests: silence test suite by using quiet UIs everywhere
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 548
diff changeset
196 return hg.repository(testui(), wc_path)
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
197
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
198 def rmtree(path):
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
199 # 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
200 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
201 for f in files:
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
202 f = os.path.join(root, f)
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
203 try:
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
204 s = os.stat(f)
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
205 except OSError, e:
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
206 if e.errno == errno.ENOENT:
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
207 continue
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
208 raise
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 23
diff changeset
209 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
210 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
211 shutil.rmtree(path)
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
212
645
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
213 def _verify_our_modules():
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
214 '''
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
215 Verify that hgsubversion was imported from the correct location.
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
216
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
217 The correct location is any location within the parent directory of the
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
218 directory containing this file.
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
219 '''
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
220
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
221 for modname, module in sys.modules.iteritems():
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
222 if not module or not modname.startswith('hgsubversion.'):
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
223 continue
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
224
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
225 modloc = module.__file__
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
226 cp = os.path.commonprefix((os.path.abspath(__file__), modloc))
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
227 assert cp.rstrip(os.sep) == _rootdir, (
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
228 'Module location verification failed: hgsubversion was imported '
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
229 'from the wrong path!'
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
230 )
486
5607e81ba616 test_util: specify LANG=LC_ALL=C so l10n stops breaking tests
Augie Fackler <durin42@gmail.com>
parents: 483
diff changeset
231
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
232 class TestBase(unittest.TestCase):
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
233 def setUp(self):
645
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
234 _verify_our_modules()
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
235
486
5607e81ba616 test_util: specify LANG=LC_ALL=C so l10n stops breaking tests
Augie Fackler <durin42@gmail.com>
parents: 483
diff changeset
236 self.oldenv = dict([(k, os.environ.get(k, None), ) for k in
5607e81ba616 test_util: specify LANG=LC_ALL=C so l10n stops breaking tests
Augie Fackler <durin42@gmail.com>
parents: 483
diff changeset
237 ('LANG', 'LC_ALL', 'HGRCPATH', )])
5607e81ba616 test_util: specify LANG=LC_ALL=C so l10n stops breaking tests
Augie Fackler <durin42@gmail.com>
parents: 483
diff changeset
238 self.oldt = i18n.t
5607e81ba616 test_util: specify LANG=LC_ALL=C so l10n stops breaking tests
Augie Fackler <durin42@gmail.com>
parents: 483
diff changeset
239 os.environ['LANG'] = os.environ['LC_ALL'] = 'C'
5607e81ba616 test_util: specify LANG=LC_ALL=C so l10n stops breaking tests
Augie Fackler <durin42@gmail.com>
parents: 483
diff changeset
240 i18n.t = gettext.translation('hg', i18n.localedir, fallback=True)
5607e81ba616 test_util: specify LANG=LC_ALL=C so l10n stops breaking tests
Augie Fackler <durin42@gmail.com>
parents: 483
diff changeset
241
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
242 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
243 self.tmpdir = tempfile.mkdtemp(
0c5f6420a8b5 tests: Add an environment variable (HGSUBVERSION_TEST_TEMP) which allows
Augie Fackler <durin42@gmail.com>
parents: 139
diff changeset
244 '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
245 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
246 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
247 rc = open(self.hgrc, 'w')
334
3c3c3264c362 test_util: Make the patching of ui.ui.write_err() slightly more reusable.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 333
diff changeset
248 for l in '[extensions]', 'hgsubversion=':
3c3c3264c362 test_util: Make the patching of ui.ui.write_err() slightly more reusable.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 333
diff changeset
249 print >> rc, l
148
0c5f6420a8b5 tests: Add an environment variable (HGSUBVERSION_TEST_TEMP) which allows
Augie Fackler <durin42@gmail.com>
parents: 139
diff changeset
250
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
251 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
252 self.wc_path = '%s/testrepo_wc' % self.tmpdir
689
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
253 self.svn_wc = None
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 326
diff changeset
254
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 326
diff changeset
255 # Previously, we had a MockUI class that wrapped ui, and giving access
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 326
diff changeset
256 # to the stream. The ui.pushbuffer() and ui.popbuffer() can be used
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 326
diff changeset
257 # instead. Using the regular UI class, with all stderr redirected to
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 326
diff changeset
258 # stdout ensures that the test setup is much more similar to usage
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 326
diff changeset
259 # setups.
334
3c3c3264c362 test_util: Make the patching of ui.ui.write_err() slightly more reusable.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 333
diff changeset
260 self.patch = (ui.ui.write_err, ui.ui.write)
3c3c3264c362 test_util: Make the patching of ui.ui.write_err() slightly more reusable.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 333
diff changeset
261 setattr(ui.ui, self.patch[0].func_name, self.patch[1])
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
262
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
263 def tearDown(self):
486
5607e81ba616 test_util: specify LANG=LC_ALL=C so l10n stops breaking tests
Augie Fackler <durin42@gmail.com>
parents: 483
diff changeset
264 for var, val in self.oldenv.iteritems():
5607e81ba616 test_util: specify LANG=LC_ALL=C so l10n stops breaking tests
Augie Fackler <durin42@gmail.com>
parents: 483
diff changeset
265 if val is None:
5607e81ba616 test_util: specify LANG=LC_ALL=C so l10n stops breaking tests
Augie Fackler <durin42@gmail.com>
parents: 483
diff changeset
266 del os.environ[var]
5607e81ba616 test_util: specify LANG=LC_ALL=C so l10n stops breaking tests
Augie Fackler <durin42@gmail.com>
parents: 483
diff changeset
267 else:
5607e81ba616 test_util: specify LANG=LC_ALL=C so l10n stops breaking tests
Augie Fackler <durin42@gmail.com>
parents: 483
diff changeset
268 os.environ[var] = val
5607e81ba616 test_util: specify LANG=LC_ALL=C so l10n stops breaking tests
Augie Fackler <durin42@gmail.com>
parents: 483
diff changeset
269 i18n.t = self.oldt
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
270 rmtree(self.tmpdir)
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
271 os.chdir(self.oldwd)
334
3c3c3264c362 test_util: Make the patching of ui.ui.write_err() slightly more reusable.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 333
diff changeset
272 setattr(ui.ui, self.patch[0].func_name, self.patch[0])
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
273
645
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
274 _verify_our_modules()
3cb5042531fb tests: verify locations of any imported hgsubversion modules
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 644
diff changeset
275
576
d96aa92d9ad9 tests: silence test suite by using quiet UIs everywhere
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 548
diff changeset
276 def ui(self, stupid=False, layout='auto'):
d96aa92d9ad9 tests: silence test suite by using quiet UIs everywhere
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 548
diff changeset
277 return testui(stupid, layout)
d96aa92d9ad9 tests: silence test suite by using quiet UIs everywhere
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 548
diff changeset
278
652
c3900ad3bf69 test_util: support specifying a start revision
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 645
diff changeset
279 def _load_fixture_and_fetch(self, fixture_name, subdir=None, stupid=False,
762
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 744
diff changeset
280 layout='auto', startrev=0, externals=None):
499
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 492
diff changeset
281 if layout == 'single':
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 492
diff changeset
282 if subdir is None:
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 492
diff changeset
283 subdir = 'trunk'
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 492
diff changeset
284 elif subdir is None:
1fd3cfa47c5e Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents: 492
diff changeset
285 subdir = ''
138
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 112
diff changeset
286 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
287 self.wc_path, subdir=subdir,
652
c3900ad3bf69 test_util: support specifying a start revision
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 645
diff changeset
288 stupid=stupid, layout=layout,
762
c31a1f92e1c6 svnexternals: preliminary support for subrepos based externals
Patrick Mezard <pmezard@gmail.com>
parents: 744
diff changeset
289 startrev=startrev, externals=externals)
138
40474f6c1f84 diff_cmd: more robust, add tests.
Augie Fackler <durin42@gmail.com>
parents: 112
diff changeset
290
689
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
291 def _add_svn_rev(self, changes):
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
292 '''changes is a dict of filename -> contents'''
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
293 if self.svn_wc is None:
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
294 self.svn_wc = os.path.join(self.tmpdir, 'testsvn_wc')
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
295 subprocess.call([
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
296 'svn', 'co', '-q', fileurl(self.repo_path),
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
297 self.svn_wc
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
298 ],
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
299 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
300
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
301 for filename, contents in changes.iteritems():
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
302 # filenames are / separated
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
303 filename = filename.replace('/', os.path.sep)
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
304 filename = os.path.join(self.svn_wc, filename)
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
305 open(filename, 'w').write(contents)
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
306 # may be redundant
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
307 subprocess.call(['svn', 'add', '-q', filename],
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
308 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
309 subprocess.call([
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
310 'svn', 'commit', '-q', self.svn_wc, '-m', 'test changes'],
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
311 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
35a1e93b6f78 tests: move _add_svn_rev to test_util for reuse
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 652
diff changeset
312
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
313 # 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
314 @property
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
315 def repo(self):
576
d96aa92d9ad9 tests: silence test suite by using quiet UIs everywhere
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 548
diff changeset
316 return hg.repository(testui(), self.wc_path)
82
71de43e9f614 Extract PushTest common code into test_util.TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 78
diff changeset
317
355
256863a65141 test_util: make it easier to test odd push cases
Augie Fackler <durin42@gmail.com>
parents: 351
diff changeset
318 def pushrevisions(self, stupid=False, expected_extra_back=0):
170
d046bef502d7 test_util: check all committed revisions are pushed
Patrick Mezard <pmezard@gmail.com>
parents: 148
diff changeset
319 before = len(self.repo)
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 326
diff changeset
320 self.repo.ui.setconfig('hgsubversion', 'stupid', str(stupid))
626
8e621dbb82d4 push: return reasonable status codes to the end user
Augie Fackler <durin42@gmail.com>
parents: 621
diff changeset
321 res = commands.push(self.repo.ui, self.repo)
170
d046bef502d7 test_util: check all committed revisions are pushed
Patrick Mezard <pmezard@gmail.com>
parents: 148
diff changeset
322 after = len(self.repo)
355
256863a65141 test_util: make it easier to test odd push cases
Augie Fackler <durin42@gmail.com>
parents: 351
diff changeset
323 self.assertEqual(expected_extra_back, after - before)
626
8e621dbb82d4 push: return reasonable status codes to the end user
Augie Fackler <durin42@gmail.com>
parents: 621
diff changeset
324 return res
83
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
325
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
326 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
327 path = self.repo_path + '/' + path
333
a59ab58969d9 test_util: normalize path in svnls()
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 331
diff changeset
328 path = util.normalize_url(fileurl(path))
83
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
329 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
330 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
331 stdout=subprocess.PIPE,
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 326
diff changeset
332 stderr=subprocess.STDOUT)
83
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
333 stdout, stderr = p.communicate()
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
334 if p.returncode:
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
335 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
336 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
337 entries.sort()
6c9b7cf1c5aa push_cmd: delete empty svn directories, refactor directory creation
Patrick Mezard <pmezard@gmail.com>
parents: 82
diff changeset
338 return entries
84
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
339
764
bc5c176b63eb svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
340 def svnco(self, svnpath, rev, path):
bc5c176b63eb svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
341 path = os.path.join(self.wc_path, path)
bc5c176b63eb svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
342 subpath = os.path.dirname(path)
bc5c176b63eb svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
343 if not os.path.isdir(subpath):
bc5c176b63eb svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
344 os.makedirs(subpath)
bc5c176b63eb svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
345 svnpath = fileurl(self.repo_path + '/' + svnpath)
bc5c176b63eb svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
346 args = ['svn', 'co', '-r', rev, svnpath, path]
bc5c176b63eb svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
347 p = subprocess.Popen(args,
bc5c176b63eb svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
348 stdout=subprocess.PIPE,
bc5c176b63eb svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
349 stderr=subprocess.STDOUT)
bc5c176b63eb svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
350 stdout, stderr = p.communicate()
bc5c176b63eb svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
351 if p.returncode:
bc5c176b63eb svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
352 raise Exception('svn co failed on %s: %r' % (svnpath, stderr))
bc5c176b63eb svnexternals: support pushing subrepo based externals
Patrick Mezard <pmezard@gmail.com>
parents: 762
diff changeset
353
355
256863a65141 test_util: make it easier to test odd push cases
Augie Fackler <durin42@gmail.com>
parents: 351
diff changeset
354 def commitchanges(self, changes, parent='tip', message='automated test'):
84
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
355 """Commit changes to mercurial directory
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
356
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
357 '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
358 like:
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
359 - (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
360 - (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
361 copied from source.
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
362 - (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
363 from source.
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
364 - (source, None, None) to remove source.
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
365 """
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
366 repo = self.repo
277
3848a7f9b983 push: Add a test that demonstrates base-text detection works
Augie Fackler <durin42@gmail.com>
parents: 270
diff changeset
367 parentctx = repo[parent]
84
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
368
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
369 changed, removed = [], []
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
370 for source, dest, newdata in changes:
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
371 if dest is None:
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
372 removed.append(source)
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
373 else:
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
374 changed.append(dest)
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
375
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
376 def filectxfn(repo, memctx, path):
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
377 if path in removed:
531
cf4fe45bf8fd Change all instantiations of IOError to set both errno and strerror.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 527
diff changeset
378 raise IOError(errno.ENOENT,
cf4fe45bf8fd Change all instantiations of IOError to set both errno and strerror.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 527
diff changeset
379 "File \"%s\" no longer exists" % path)
84
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
380 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
381 source, dest, newdata = entry
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
382 if newdata is None:
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
383 newdata = parentctx[source].data()
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
384 copied = None
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
385 if source != dest:
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
386 copied = source
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
387 return context.memfilectx(path=dest,
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
388 data=newdata,
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
389 islink=False,
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
390 isexec=False,
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
391 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
392
84
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
393 ctx = context.memctx(repo,
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
394 (parentctx.node(), node.nullid),
355
256863a65141 test_util: make it easier to test odd push cases
Augie Fackler <durin42@gmail.com>
parents: 351
diff changeset
395 message,
84
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
396 changed + removed,
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
397 filectxfn,
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
398 'an_author',
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
399 '2008-10-07 20:59:48 -0500')
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
400 nodeid = repo.commitctx(ctx)
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
401 repo = self.repo
277
3848a7f9b983 push: Add a test that demonstrates base-text detection works
Augie Fackler <durin42@gmail.com>
parents: 270
diff changeset
402 hg.clean(repo, nodeid)
84
01e747937d35 test_util: add commitchanges() to TestBase
Patrick Mezard <pmezard@gmail.com>
parents: 83
diff changeset
403 return nodeid
96
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
404
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
405 def assertchanges(self, changes, ctx):
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
406 """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
407 went into ctx.
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
408 """
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
409 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
410 if dest is None:
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
411 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
412 continue
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
413 self.assertTrue(dest in ctx)
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
414 if data is None:
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
415 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
416 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
417 if dest != source:
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
418 copy = ctx[dest].renamed()
9b5e528f67f8 Add a test to check EOLs are correctly converted
Patrick Mezard <pmezard@gmail.com>
parents: 91
diff changeset
419 self.assertEqual(copy[0], source)
527
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
420
621
3e18cdcb6e00 test_util: add assertMultiLineEqual() method.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 576
diff changeset
421 def assertMultiLineEqual(self, first, second, msg=None):
3e18cdcb6e00 test_util: add assertMultiLineEqual() method.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 576
diff changeset
422 """Assert that two multi-line strings are equal. (Based on Py3k code.)
3e18cdcb6e00 test_util: add assertMultiLineEqual() method.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 576
diff changeset
423 """
744
6d6be5284056 tests: make assertMultiLineEqual call super, if possible.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 743
diff changeset
424 try:
6d6be5284056 tests: make assertMultiLineEqual call super, if possible.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 743
diff changeset
425 return super(TestBase, self).assertMultiLineEqual(first, second,
6d6be5284056 tests: make assertMultiLineEqual call super, if possible.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 743
diff changeset
426 msg)
6d6be5284056 tests: make assertMultiLineEqual call super, if possible.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 743
diff changeset
427 except AttributeError:
6d6be5284056 tests: make assertMultiLineEqual call super, if possible.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 743
diff changeset
428 pass
6d6be5284056 tests: make assertMultiLineEqual call super, if possible.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 743
diff changeset
429
621
3e18cdcb6e00 test_util: add assertMultiLineEqual() method.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 576
diff changeset
430 self.assert_(isinstance(first, str),
3e18cdcb6e00 test_util: add assertMultiLineEqual() method.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 576
diff changeset
431 ('First argument is not a string'))
3e18cdcb6e00 test_util: add assertMultiLineEqual() method.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 576
diff changeset
432 self.assert_(isinstance(second, str),
3e18cdcb6e00 test_util: add assertMultiLineEqual() method.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 576
diff changeset
433 ('Second argument is not a string'))
3e18cdcb6e00 test_util: add assertMultiLineEqual() method.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 576
diff changeset
434
3e18cdcb6e00 test_util: add assertMultiLineEqual() method.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 576
diff changeset
435 if first != second:
3e18cdcb6e00 test_util: add assertMultiLineEqual() method.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 576
diff changeset
436 diff = ''.join(difflib.unified_diff(first.splitlines(True),
3e18cdcb6e00 test_util: add assertMultiLineEqual() method.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 576
diff changeset
437 second.splitlines(True),
3e18cdcb6e00 test_util: add assertMultiLineEqual() method.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 576
diff changeset
438 fromfile='a',
3e18cdcb6e00 test_util: add assertMultiLineEqual() method.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 576
diff changeset
439 tofile='b'))
3e18cdcb6e00 test_util: add assertMultiLineEqual() method.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 576
diff changeset
440 msg = '%s\n%s' % (msg or '', diff)
3e18cdcb6e00 test_util: add assertMultiLineEqual() method.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 576
diff changeset
441 raise self.failureException, msg
3e18cdcb6e00 test_util: add assertMultiLineEqual() method.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 576
diff changeset
442
527
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
443 def draw(self, repo):
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
444 """Helper function displaying a repository graph, especially
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
445 useful when debugging comprehensive tests.
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
446 """
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
447 # Could be more elegant, but it works with stock hg
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
448 _ui = ui.ui()
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
449 _ui.setconfig('extensions', 'graphlog', '')
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
450 extensions.loadall(_ui)
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
451 graphlog = extensions.find('graphlog')
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
452 templ = """\
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
453 changeset: {rev}:{node|short}
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
454 branch: {branches}
546
d84116dda52d test_util: add tags to output of draw
Augie Fackler <durin42@gmail.com>
parents: 531
diff changeset
455 tags: {tags}
527
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
456 summary: {desc|firstline}
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
457 files: {files}
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
458
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
459 """
2be9f14bd23f test_util: add helper to draw repo with graphlog extension
Patrick Mezard <pmezard@gmail.com>
parents: 522
diff changeset
460 graphlog.graphlog(_ui, repo, rev=None, template=templ)