Mercurial > python-hglib
annotate tests/test_commit.py @ 221:a2afbf236ca8
hglib tests: remove deprecated constructions
This mostly removes usage of 'assertEquals' (replaced with 'assertEqual'),
as well as opening files without closing them
(fixed using a 'with' statement).
author | Mathias De Mare <mathias.de_mare@nokia.com> |
---|---|
date | Thu, 09 Mar 2023 14:00:02 +0100 |
parents | 8341f2494b3f |
children |
rev | line source |
---|---|
148
c1b966866ed7
hglib: make all imports absolute (issue4520)
Brett Cannon <brett@python.org>
parents:
144
diff
changeset
|
1 from tests import common |
c1b966866ed7
hglib: make all imports absolute (issue4520)
Brett Cannon <brett@python.org>
parents:
144
diff
changeset
|
2 import hglib, datetime |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
3 from hglib.util import b |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
4 |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
5 class test_commit(common.basetest): |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
6 def test_user(self): |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
7 self.append('a', 'a') |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
8 rev, node = self.client.commit(b('first'), addremove=True, |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
9 user=b('foo')) |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
10 rev = self.client.log(node)[0] |
221
a2afbf236ca8
hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
219
diff
changeset
|
11 self.assertEqual(rev.author, b('foo')) |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
12 |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
13 def test_no_user(self): |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
14 self.append('a', 'a') |
134 | 15 self.assertRaises(hglib.error.CommandError, |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
16 self.client.commit, b('first'), user=b('')) |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
17 |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
18 def test_close_branch(self): |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
19 self.append('a', 'a') |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
20 rev0, node0 = self.client.commit(b('first'), addremove=True) |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
21 self.client.branch(b('foo')) |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
22 self.append('a', 'a') |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
23 rev1, node1 = self.client.commit(b('second')) |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
24 revclose = self.client.commit(b('closing foo'), closebranch=True) |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
25 rev0, rev1, revclose = self.client.log([node0, node1, revclose[1]]) |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
26 |
221
a2afbf236ca8
hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
219
diff
changeset
|
27 self.assertEqual(self.client.branches(), |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
28 [(rev0.branch, int(rev0.rev), rev0.node[:12])]) |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
29 |
221
a2afbf236ca8
hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
219
diff
changeset
|
30 self.assertEqual(self.client.branches(closed=True), |
134 | 31 [(revclose.branch, int(revclose.rev), |
32 revclose.node[:12]), | |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
33 (rev0.branch, int(rev0.rev), rev0.node[:12])]) |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
34 |
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
35 def test_message_logfile(self): |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
36 self.assertRaises(ValueError, self.client.commit, b('foo'), |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
37 logfile=b('bar')) |
16
943aff89b068
client: add missing options to commit()
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
38 self.assertRaises(ValueError, self.client.commit) |
99
2b36619ec0a0
client: add date field to revision
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
39 |
2b36619ec0a0
client: add date field to revision
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
40 def test_date(self): |
2b36619ec0a0
client: add date field to revision
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
41 self.append('a', 'a') |
2b36619ec0a0
client: add date field to revision
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
42 now = datetime.datetime.now().replace(microsecond=0) |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
43 rev0, node0 = self.client.commit( |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
44 b('first'), addremove=True, |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
45 date=now.isoformat(' ').encode('latin-1')) |
99
2b36619ec0a0
client: add date field to revision
Idan Kamara <idankk86@gmail.com>
parents:
16
diff
changeset
|
46 |
221
a2afbf236ca8
hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
219
diff
changeset
|
47 self.assertEqual(now, self.client.tip().date) |
136
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
48 |
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
49 def test_amend(self): |
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
50 self.append('a', 'a') |
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
51 now = datetime.datetime.now().replace(microsecond=0) |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
52 rev0, node0 = self.client.commit( |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
53 b('first'), addremove=True, |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
136
diff
changeset
|
54 date=now.isoformat(' ').encode('latin-1')) |
136
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
55 |
221
a2afbf236ca8
hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
219
diff
changeset
|
56 self.assertEqual(now, self.client.tip().date) |
136
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
57 |
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
58 self.append('a', 'a') |
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
59 rev1, node1 = self.client.commit(amend=True) |
221
a2afbf236ca8
hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
219
diff
changeset
|
60 self.assertEqual(now, self.client.tip().date) |
a2afbf236ca8
hglib tests: remove deprecated constructions
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
219
diff
changeset
|
61 self.assertNotEqual(node0, node1) |
136
dc63978871ed
client: add support for 'hg commit --amend'
David Douard <david.douard@logilab.fr>
parents:
134
diff
changeset
|
62 self.assertEqual(1, len(self.client.log())) |
201
67398bbf788d
client: do not accept NULL character as command arguments
Yuya Nishihara <yuya@tcha.org>
parents:
148
diff
changeset
|
63 |
67398bbf788d
client: do not accept NULL character as command arguments
Yuya Nishihara <yuya@tcha.org>
parents:
148
diff
changeset
|
64 def test_nul_injection(self): |
67398bbf788d
client: do not accept NULL character as command arguments
Yuya Nishihara <yuya@tcha.org>
parents:
148
diff
changeset
|
65 self.append('a', 'a') |
67398bbf788d
client: do not accept NULL character as command arguments
Yuya Nishihara <yuya@tcha.org>
parents:
148
diff
changeset
|
66 self.assertRaises(ValueError, lambda: self.client.commit(b('fail\0-A'))) |
67398bbf788d
client: do not accept NULL character as command arguments
Yuya Nishihara <yuya@tcha.org>
parents:
148
diff
changeset
|
67 self.assertEqual(0, len(self.client.log())) |