annotate tests/common.py @ 224:2ab42323f149

client: handle commit messages with \0 characters for all commands Each of the impacted commands will now use the 'json' template, which they all support as of Mercurial 3.7.3 (the first version tested in the regression tests). Note: I tried to add a test with null bytes, but both hglib and using hg directly through subprocess rejected adding a commit message with a null byte.
author Mathias De Mare <mathias.de_mare@nokia.com>
date Mon, 13 Mar 2023 15:32:20 +0100
parents 8341f2494b3f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
1 import os, sys, tempfile, shutil
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
2 import unittest
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
3
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
4 import hglib
101
d1a42c1d0b61 tests: hook into hgclient.open for closing open cmdservers
Idan Kamara <idankk86@gmail.com>
parents: 68
diff changeset
5 from hglib import client
7
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
6
67
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
7 def resultappender(list):
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
8 def decorator(f):
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
9 def decorated(*args, **kwargs):
101
d1a42c1d0b61 tests: hook into hgclient.open for closing open cmdservers
Idan Kamara <idankk86@gmail.com>
parents: 68
diff changeset
10 list.append(args[0])
d1a42c1d0b61 tests: hook into hgclient.open for closing open cmdservers
Idan Kamara <idankk86@gmail.com>
parents: 68
diff changeset
11 return f(*args, **kwargs)
67
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
12 return decorated
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
13 return decorator
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
14
7
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
15 class basetest(unittest.TestCase):
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
16 def setUp(self):
219
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
17 os.environ['LANG'] = os.environ['LC_ALL'] = os.environ['LANGUAGE'] = 'C'
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
18 os.environ["EMAIL"] = "Foo Bar <foo.bar@example.com>"
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
19 os.environ['CDPATH'] = ''
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
20 os.environ['COLUMNS'] = '80'
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
21 os.environ['GREP_OPTIONS'] = ''
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
22 os.environ['http_proxy'] = ''
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
23
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
24 os.environ["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"'
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
25 os.environ["HGMERGE"] = "internal:merge"
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
26 os.environ["HGUSER"] = "test"
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
27 os.environ["HGENCODING"] = "ascii"
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
28 os.environ["HGENCODINGMODE"] = "strict"
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
29 tmpdir = tempfile.mkdtemp('', 'python-hglib.')
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
30 os.environ["HGTMP"] = os.path.realpath(tmpdir)
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
31 os.environ["HGRCPATH"] = os.pathsep
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
32
7
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
33 self._testtmp = os.environ["TESTTMP"] = os.environ["HOME"] = \
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
34 os.path.join(os.environ["HGTMP"], self.__class__.__name__)
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
35
67
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
36 self.clients = []
101
d1a42c1d0b61 tests: hook into hgclient.open for closing open cmdservers
Idan Kamara <idankk86@gmail.com>
parents: 68
diff changeset
37 self._oldopen = hglib.client.hgclient.open
d1a42c1d0b61 tests: hook into hgclient.open for closing open cmdservers
Idan Kamara <idankk86@gmail.com>
parents: 68
diff changeset
38 # hglib.open = resultappender(self.clients)(hglib.open)
134
1b47146a4a2c style: fix long lines
Matt Mackall <mpm@selenic.com>
parents: 101
diff changeset
39 c = hglib.client.hgclient
1b47146a4a2c style: fix long lines
Matt Mackall <mpm@selenic.com>
parents: 101
diff changeset
40 c.open = resultappender(self.clients)(c.open)
67
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
41
7
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
42 os.mkdir(self._testtmp)
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
43 os.chdir(self._testtmp)
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
44 # until we can run norepo commands in the cmdserver
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
45 os.system('hg init')
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
46 self.client = hglib.open()
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
47
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
48 def tearDown(self):
134
1b47146a4a2c style: fix long lines
Matt Mackall <mpm@selenic.com>
parents: 101
diff changeset
49 # on Windows we cannot rmtree before closing all instances
1b47146a4a2c style: fix long lines
Matt Mackall <mpm@selenic.com>
parents: 101
diff changeset
50 # because of used files
101
d1a42c1d0b61 tests: hook into hgclient.open for closing open cmdservers
Idan Kamara <idankk86@gmail.com>
parents: 68
diff changeset
51 hglib.client.hgclient.open = self._oldopen
67
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
52 for client in self.clients:
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
53 if client.server is not None:
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
54 client.close()
730c42743ba3 tests: cleanup on test finish so Windows doesn't complain about used files
Idan Kamara <idankk86@gmail.com>
parents: 58
diff changeset
55 os.chdir('..')
219
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
56
58
3d413c54e048 tests: be prepared for basetest.setUp not being called
Idan Kamara <idankk86@gmail.com>
parents: 7
diff changeset
57 try:
219
8341f2494b3f hglib tests: migrate away from (unmaintained) nose
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 157
diff changeset
58 shutil.rmtree(self._testtmp, ignore_errors=True)
58
3d413c54e048 tests: be prepared for basetest.setUp not being called
Idan Kamara <idankk86@gmail.com>
parents: 7
diff changeset
59 except AttributeError:
3d413c54e048 tests: be prepared for basetest.setUp not being called
Idan Kamara <idankk86@gmail.com>
parents: 7
diff changeset
60 pass # if our setUp was overriden
7
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
61
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
62 def append(self, path, *args):
68
a0328b08e028 tests: open files in binary mode so new lines aren't converted
Idan Kamara <idankk86@gmail.com>
parents: 67
diff changeset
63 f = open(path, 'ab')
7
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
64 for a in args:
157
6564544576b9 tests: write out bytes instead of strings to test files (issue4520)
Brett Cannon <brett@python.org>
parents: 134
diff changeset
65 f.write(a.encode('latin-1'))
7
eac8be119d81 tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
66 f.close()