Mercurial > python-hglib
changeset 219:8341f2494b3f
hglib tests: migrate away from (unmaintained) nose
author | Mathias De Mare <mathias.de_mare@nokia.com> |
---|---|
date | Wed, 08 Mar 2023 17:04:58 +0100 |
parents | 934608d4fcba |
children | ae6427d1c8f7 |
files | Makefile heptapod-ci.yml test.py tests/__init__.py tests/common.py tests/test-annotate.py tests/test-bookmarks.py tests/test-branch.py tests/test-branches.py tests/test-bundle.py tests/test-clone.py tests/test-commit.py tests/test-config.py tests/test-context.py tests/test-copy.py tests/test-diff.py tests/test-encoding.py tests/test-forget.py tests/test-grep.py tests/test-heads.py tests/test-hglib.py tests/test-hidden.py tests/test-import.py tests/test-init.py tests/test-log.py tests/test-manifest.py tests/test-merge.py tests/test-move.py tests/test-outgoing-incoming.py tests/test-parents.py tests/test-paths.py tests/test-phase.py tests/test-pull.py tests/test-push.py tests/test-remove.py tests/test-resolve.py tests/test-status.py tests/test-summary.py tests/test-tags.py tests/test-update.py tests/test_annotate.py tests/test_bookmarks.py tests/test_branch.py tests/test_branches.py tests/test_bundle.py tests/test_clone.py tests/test_commit.py tests/test_config.py tests/test_context.py tests/test_copy.py tests/test_diff.py tests/test_encoding.py tests/test_forget.py tests/test_grep.py tests/test_heads.py tests/test_hglib.py tests/test_hidden.py tests/test_import.py tests/test_init.py tests/test_log.py tests/test_manifest.py tests/test_merge.py tests/test_move.py tests/test_outgoing_incoming.py tests/test_parents.py tests/test_paths.py tests/test_phase.py tests/test_pull.py tests/test_push.py tests/test_remove.py tests/test_resolve.py tests/test_status.py tests/test_summary.py tests/test_tags.py tests/test_update.py tests/with_hg.py |
diffstat | 76 files changed, 1413 insertions(+), 1459 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Wed Mar 09 15:08:11 2022 +0100 +++ b/Makefile Wed Mar 08 17:04:58 2023 +0100 @@ -1,4 +1,4 @@ -PYTHON=python +PYTHON=python3 help: @echo 'Commonly used make targets:' @echo ' tests - run all tests in the automatic test suite' @@ -14,4 +14,4 @@ TAR_OPTIONS="--owner=root --group=root --mode=u+w,go-w,a+rX-s" $(PYTHON) setup.py -q sdist tests: - $(PYTHON) test.py --with-doctest + $(PYTHON) -m unittest discover
--- a/heptapod-ci.yml Wed Mar 09 15:08:11 2022 +0100 +++ b/heptapod-ci.yml Wed Mar 08 17:04:58 2023 +0100 @@ -4,6 +4,5 @@ unit-test-job: stage: test script: - - apt update && apt install -y make python3 python3-nose python3-pip && pip3 install mercurial - # to be replaced with 'make tests' after merge request 1 is in: - - python3 test.py --with-doctest + - apt update && apt install -y make python3 python3-pip && pip3 install mercurial + - make tests
--- a/test.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -#!/usr/bin/env python - -import nose -from tests import with_hg - -if __name__ == '__main__': - nose.main(addplugins=[with_hg.WithHgPlugin()])
--- a/tests/__init__.py Wed Mar 09 15:08:11 2022 +0100 +++ b/tests/__init__.py Wed Mar 08 17:04:58 2023 +0100 @@ -1,22 +0,0 @@ -import os, tempfile, sys, shutil - -def setUp(): - os.environ['LANG'] = os.environ['LC_ALL'] = os.environ['LANGUAGE'] = 'C' - os.environ["EMAIL"] = "Foo Bar <foo.bar@example.com>" - os.environ['CDPATH'] = '' - os.environ['COLUMNS'] = '80' - os.environ['GREP_OPTIONS'] = '' - os.environ['http_proxy'] = '' - - os.environ["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"' - os.environ["HGMERGE"] = "internal:merge" - os.environ["HGUSER"] = "test" - os.environ["HGENCODING"] = "ascii" - os.environ["HGENCODINGMODE"] = "strict" - tmpdir = tempfile.mkdtemp('', 'python-hglib.') - os.environ["HGTMP"] = os.path.realpath(tmpdir) - os.environ["HGRCPATH"] = os.pathsep - -def tearDown(self): - os.chdir('..') - shutil.rmtree(os.environ["HGTMP"])
--- a/tests/common.py Wed Mar 09 15:08:11 2022 +0100 +++ b/tests/common.py Wed Mar 08 17:04:58 2023 +0100 @@ -14,6 +14,22 @@ class basetest(unittest.TestCase): def setUp(self): + os.environ['LANG'] = os.environ['LC_ALL'] = os.environ['LANGUAGE'] = 'C' + os.environ["EMAIL"] = "Foo Bar <foo.bar@example.com>" + os.environ['CDPATH'] = '' + os.environ['COLUMNS'] = '80' + os.environ['GREP_OPTIONS'] = '' + os.environ['http_proxy'] = '' + + os.environ["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"' + os.environ["HGMERGE"] = "internal:merge" + os.environ["HGUSER"] = "test" + os.environ["HGENCODING"] = "ascii" + os.environ["HGENCODINGMODE"] = "strict" + tmpdir = tempfile.mkdtemp('', 'python-hglib.') + os.environ["HGTMP"] = os.path.realpath(tmpdir) + os.environ["HGRCPATH"] = os.pathsep + self._testtmp = os.environ["TESTTMP"] = os.environ["HOME"] = \ os.path.join(os.environ["HGTMP"], self.__class__.__name__) @@ -37,8 +53,9 @@ if client.server is not None: client.close() os.chdir('..') + try: - shutil.rmtree(self._testtmp) + shutil.rmtree(self._testtmp, ignore_errors=True) except AttributeError: pass # if our setUp was overriden
--- a/tests/test-annotate.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -from tests import common -from hglib.util import b - -class test_annotate(common.basetest): - def test_basic(self): - self.append('a', 'a\n') - rev, node0 = self.client.commit(b('first'), addremove=True) - self.append('a', 'a\n') - rev, node1 = self.client.commit(b('second')) - - self.assertEquals(list(self.client.annotate(b('a'))), - [(b('0'), b('a')), (b('1'), b('a'))]) - self.assertEquals(list( - self.client.annotate( - b('a'), user=True, file=True, - number=True, changeset=True, line=True, verbose=True)), - [(b('test 0 ') + node0[:12] + b(' a:1'), b('a')), - (b('test 1 ') + node1[:12] + b(' a:2'), b('a'))]) - - def test_files(self): - self.append('a', 'a\n') - rev, node0 = self.client.commit(b('first'), addremove=True) - self.append('b', 'b\n') - rev, node1 = self.client.commit(b('second'), addremove=True) - self.assertEquals(list(self.client.annotate([b('a'), b('b')])), - [(b('0'), b('a')), (b('1'), b('b'))]) - - def test_two_colons(self): - self.append('a', 'a: b\n') - self.client.commit(b('first'), addremove=True) - self.assertEquals(list(self.client.annotate(b('a'))), - [(b('0'), b('a: b'))])
--- a/tests/test-bookmarks.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -from tests import common -from hglib.util import b - -class test_bookmarks(common.basetest): - def test_empty(self): - self.assertEquals(self.client.bookmarks(), ([], -1)) - - def test_basic(self): - self.append('a', 'a') - rev0, node0 = self.client.commit(b('first'), addremove=True) - self.append('a', 'a') - rev1, node1 = self.client.commit(b('second')) - - self.client.bookmark(b('zero'), rev0) - self.assertEquals(self.client.bookmarks(), - ([(b('zero'), rev0, node0[:12])], -1)) - - self.client.bookmark(b('one'), rev1) - self.assertEquals(self.client.bookmarks()[0], - [(b('one'), rev1, node1[:12]), - (b('zero'), rev0, node0[:12])]) - - #def test_spaces(self): - # self.client.bookmark('s pace', self.rev0) - # self.assertEquals(self.client.bookmarks(), - # ([('s pace', 0, self.rev0.node[:12])], -1))
--- a/tests/test-branch.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -from tests import common -import hglib -from hglib.util import b - -class test_branch(common.basetest): - def test_empty(self): - self.assertEquals(self.client.branch(), b('default')) - - def test_basic(self): - self.assertEquals(self.client.branch(b('foo')), b('foo')) - self.append('a', 'a') - rev, node = self.client.commit(b('first'), addremove=True) - - rev = self.client.log(node)[0] - - self.assertEquals(rev.branch, b('foo')) - self.assertEquals(self.client.branches(), - [(rev.branch, int(rev.rev), rev.node[:12])]) - - def test_reset_with_name(self): - self.assertRaises(ValueError, self.client.branch, b('foo'), clean=True) - - def test_reset(self): - self.client.branch(b('foo')) - self.assertEquals(self.client.branch(clean=True), b('default')) - - def test_exists(self): - self.append('a', 'a') - self.client.commit(b('first'), addremove=True) - self.client.branch(b('foo')) - self.append('a', 'a') - self.client.commit(b('second')) - self.assertRaises(hglib.error.CommandError, - self.client.branch, b('default')) - - def test_force(self): - self.append('a', 'a') - self.client.commit(b('first'), addremove=True) - self.client.branch(b('foo')) - self.append('a', 'a') - self.client.commit(b('second')) - - self.assertRaises(hglib.error.CommandError, - self.client.branch, b('default')) - self.assertEquals(self.client.branch(b('default'), force=True), - b('default'))
--- a/tests/test-branches.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -from tests import common -import hglib -from hglib.util import b - -class test_branches(common.basetest): - def test_empty(self): - self.assertEquals(self.client.branches(), []) - - def test_basic(self): - self.append('a', 'a') - rev0 = self.client.commit(b('first'), addremove=True) - self.client.branch(b('foo')) - self.append('a', 'a') - rev1 = self.client.commit(b('second')) - branches = self.client.branches() - - expected = [] - for r, n in (rev1, rev0): - r = self.client.log(r)[0] - expected.append((r.branch, int(r.rev), r.node[:12])) - - self.assertEquals(branches, expected) - - def test_active_closed(self): - pass
--- a/tests/test-bundle.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -from tests import common -from hglib.util import b - -class test_bundle(common.basetest): - def test_no_changes(self): - self.append('a', 'a') - rev, node0 = self.client.commit(b('first'), addremove=True) - self.assertFalse(self.client.bundle(b('bundle'), destrepo=b('.'))) - - def test_basic(self): - self.append('a', 'a') - rev, node0 = self.client.commit(b('first'), addremove=True) - self.client.clone(dest=b('other')) - - self.append('a', 'a') - rev, node1 = self.client.commit(b('second')) - - self.assertTrue(self.client.bundle(b('bundle'), destrepo=b('other')))
--- a/tests/test-clone.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -import os -from tests import common -import hglib -from hglib.util import b - -class test_clone(common.basetest): - def test_basic(self): - self.append('a', 'a') - self.client.commit(b('first'), addremove=True) - cloned = hglib.clone(b('.'), b('cloned')) - self.assertRaises(ValueError, cloned.log) - cloned.open() - self.assertEquals(self.client.log(), cloned.log()) - - def test_clone_uncompressed(self): - hglib.clone(b('.'), b('cloned'), uncompressed=True)
--- a/tests/test-commit.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -from tests import common -import hglib, datetime -from hglib.util import b - -class test_commit(common.basetest): - def test_user(self): - self.append('a', 'a') - rev, node = self.client.commit(b('first'), addremove=True, - user=b('foo')) - rev = self.client.log(node)[0] - self.assertEquals(rev.author, b('foo')) - - def test_no_user(self): - self.append('a', 'a') - self.assertRaises(hglib.error.CommandError, - self.client.commit, b('first'), user=b('')) - - def test_close_branch(self): - self.append('a', 'a') - rev0, node0 = self.client.commit(b('first'), addremove=True) - self.client.branch(b('foo')) - self.append('a', 'a') - rev1, node1 = self.client.commit(b('second')) - revclose = self.client.commit(b('closing foo'), closebranch=True) - rev0, rev1, revclose = self.client.log([node0, node1, revclose[1]]) - - self.assertEquals(self.client.branches(), - [(rev0.branch, int(rev0.rev), rev0.node[:12])]) - - self.assertEquals(self.client.branches(closed=True), - [(revclose.branch, int(revclose.rev), - revclose.node[:12]), - (rev0.branch, int(rev0.rev), rev0.node[:12])]) - - def test_message_logfile(self): - self.assertRaises(ValueError, self.client.commit, b('foo'), - logfile=b('bar')) - self.assertRaises(ValueError, self.client.commit) - - def test_date(self): - self.append('a', 'a') - now = datetime.datetime.now().replace(microsecond=0) - rev0, node0 = self.client.commit( - b('first'), addremove=True, - date=now.isoformat(' ').encode('latin-1')) - - self.assertEquals(now, self.client.tip().date) - - def test_amend(self): - self.append('a', 'a') - now = datetime.datetime.now().replace(microsecond=0) - rev0, node0 = self.client.commit( - b('first'), addremove=True, - date=now.isoformat(' ').encode('latin-1')) - - self.assertEquals(now, self.client.tip().date) - - self.append('a', 'a') - rev1, node1 = self.client.commit(amend=True) - self.assertEquals(now, self.client.tip().date) - self.assertNotEquals(node0, node1) - self.assertEqual(1, len(self.client.log())) - - def test_nul_injection(self): - self.append('a', 'a') - self.assertRaises(ValueError, lambda: self.client.commit(b('fail\0-A'))) - self.assertEqual(0, len(self.client.log()))
--- a/tests/test-config.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -from tests import common -import os, hglib -from hglib.util import b - -class test_config(common.basetest): - def setUp(self): - common.basetest.setUp(self) - f = open('.hg/hgrc', 'a') - f.write('[section]\nkey=value\n') - f.close() - self.client = hglib.open() - - def test_basic(self): - config = self.client.config() - - self.assertTrue( - (b('section'), b('key'), b('value')) in self.client.config()) - - self.assertTrue([(b('section'), b('key'), b('value'))], - self.client.config(b('section'))) - self.assertTrue([(b('section'), b('key'), b('value'))], - self.client.config([b('section'), b('foo')])) - self.assertRaises(hglib.error.CommandError, - self.client.config, [b('a.b'), b('foo')]) - - def test_show_source(self): - config = self.client.config(showsource=True) - - self.assertTrue((os.path.abspath(b('.hg/hgrc')) + b(':2'), - b('section'), b('key'), b('value')) in config) - -class test_config_arguments(common.basetest): - def test_basic(self): - client = hglib.open(configs=[b('diff.unified=5'), b('a.b=foo')]) - self.assertEqual(client.config(b('a')), [(b('a'), b('b'), b('foo'))]) - self.assertEqual(client.config(b('diff')), - [(b('diff'), b('unified'), b('5'))])
--- a/tests/test-context.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -import sys -from tests import common -from hglib.error import CommandError -import hglib -from hglib import context -from hglib.util import b - -class test_context(common.basetest): - def test_non_existent(self): - self.assertRaises(ValueError, context.changectx, self.client, b('foo')) - - def test_basic(self): - self.append('a', 'a') - self.append('b', 'b') - rev0, node0 = self.client.commit(b('first'), addremove=True) - - self.append('c', 'c') - rev1, node1 = self.client.commit(b('second'), addremove=True) - - self.assertRaises(KeyError, self.client.__getitem__, 'doesnotexist') - - ctx = self.client[node0] - - self.assertEquals(ctx.description(), b('first')) - self.assertEquals(str(ctx), node0[:12].decode('latin-1')) - self.assertEquals(ctx.node(), node0) - self.assertEquals(int(ctx), rev0) - self.assertEquals(ctx.rev(), rev0) - self.assertEquals(ctx.branch(), b('default')) - - self.assertTrue(ctx) - - self.assertTrue(b('a') in ctx and b('b') in ctx) - self.assertFalse(b('c') in ctx) - self.assertEquals(list(ctx), [b('a'), b('b')]) - self.assertEquals(ctx.files(), [b('a'), b('b')]) - - self.assertEquals(ctx.modified(), []) - self.assertEquals(ctx.added(), [b('a'), b('b')]) - self.assertEquals(ctx.removed(), []) - self.assertEquals(ctx.ignored(), []) - self.assertEquals(ctx.clean(), []) - - man = {b('a') : b('047b75c6d7a3ef6a2243bd0e99f94f6ea6683597'), - b('b') : b('62452855512f5b81522aa3895892760bb8da9f3f')} - self.assertEquals(ctx.manifest(), man) - - self.assertEquals([int(c) for c in ctx.parents()], [-1]) - self.assertEquals(int(ctx.p1()), -1) - self.assertEquals(int(ctx.p2()), -1) - - self.assertEquals([int(c) for c in ctx.children()], [1]) - self.assertEquals([int(c) for c in ctx.descendants()], [0, 1]) - self.assertEquals([int(c) for c in ctx.ancestors()], [0]) - - self.client.bookmark(b('bookmark'), inactive=True, rev=node0) - self.assertEquals(ctx.bookmarks(), [b('bookmark')]) - - self.client.tag(b('tag'), rev=node0) - # tags are read on construction - self.assertEquals(self.client[node0].tags(), [b('tag')]) - - def test_construction(self): - self.append('a', 'a') - rev0, node0 = self.client.commit(b('first'), addremove=True) - tip = self.client.tip() - - # from client.revision - ctx = context.changectx(self.client, tip) - self.assertEquals(ctx.node(), tip.node) - - # from revset - ctx = context.changectx(self.client, b('all()')) - self.assertEquals(ctx.node(), tip.node) - - def test_in_keyword(self): - """ - test the 'in' keyword using both revision numbers or changeset ids. - """ - if sys.version_info < (2, 7): - return - - self.append('a', 'a') - rev0, node0 = self.client.commit(b('first'), addremove=True) - self.append('a', 'a') - rev1, node1 = self.client.commit(b('second')) - - self.assertIn(1, self.client) - hash_1 = self.client.log(0)[0][1] - self.assertIn(hash_1, self.client) - self.assertNotIn(2, self.client) - hash_2 = self.client.log(1)[0][1] - self.assertIn(hash_2, self.client) - hash_2 = b('deadbeef') - self.assertNotIn(hash_2, self.client)
--- a/tests/test-copy.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -from tests import common -import hglib -from hglib.util import b - -class test_copy(common.basetest): - def test_basic(self): - self.append('a', 'a') - self.client.commit(b('first'), addremove=True) - - self.assertTrue(self.client.copy(b('a'), b('b'))) - self.assertEquals(self.client.status(), [(b('A'), b('b'))]) - self.append('c', 'a') - self.assertTrue(self.client.copy(b('a'), b('c'), after=True)) - self.assertEquals(self.client.status(), - [(b('A'), b('b')), (b('A'), b('c'))]) - - # hg returns 0 even if there were warnings - #def test_warnings(self): - # self.append('a', 'a') - # self.client.commit('first', addremove=True) - - # self.assertTrue(self.client.copy('a', 'b')) - # self.assertFalse(self.client.copy('a', 'b'))
--- a/tests/test-diff.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -from tests import common -from hglib.util import b - -class test_diff(common.basetest): - def test_basic(self): - self.append('a', 'a\n') - self.client.add(b('a')) - diff1 = b("""diff -r 000000000000 a ---- /dev/null -+++ b/a -@@ -0,0 +1,1 @@ -+a -""") - self.assertEquals(diff1, self.client.diff(nodates=True)) - self.assertEquals(diff1, self.client.diff([b('a')], nodates=True)) - rev0, node0 = self.client.commit(b('first')) - diff2 = b("""diff -r 000000000000 -r """) + node0[:12] + b(""" a ---- /dev/null -+++ b/a -@@ -0,0 +1,1 @@ -+a -""") - self.assertEquals(diff2, self.client.diff(change=rev0, nodates=True)) - self.append('a', 'a\n') - rev1, node1 = self.client.commit(b('second')) - diff3 = b("""diff -r """) + node0[:12] + b(""" a ---- a/a -+++ b/a -@@ -1,1 +1,2 @@ - a -+a -""") - self.assertEquals(diff3, self.client.diff(revs=[rev0], nodates=True)) - diff4 = b("""diff -r """) + node0[:12] + b(" -r ") + node1[:12] + b( - """ a ---- a/a -+++ b/a -@@ -1,1 +1,2 @@ - a -+a -""") - self.assertEquals(diff4, self.client.diff(revs=[rev0, rev1], - nodates=True)) - - def test_basic_plain(self): - open('.hg/hgrc', 'a').write('[defaults]\ndiff=--git\n') - self.test_basic()
--- a/tests/test-encoding.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -from tests import common -import hglib -from hglib.util import b - -class test_encoding(common.basetest): - def test_basic(self): - self.client = hglib.open(encoding='utf-8') - self.assertEquals(self.client.encoding, b('utf-8'))
--- a/tests/test-forget.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -from tests import common -from hglib.util import b - -class test_forget(common.basetest): - def test_basic(self): - self.append('a', 'a') - self.client.add([b('a')]) - self.assertTrue(self.client.forget(b('a'))) - - def test_warnings(self): - self.assertFalse(self.client.forget(b('a'))) - self.append('a', 'a') - self.client.add([b('a')]) - self.assertFalse(self.client.forget([b('a'), b('b')]))
--- a/tests/test-grep.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -from tests import common -from hglib.util import b - -class test_grep(common.basetest): - def test_basic(self): - self.append('a', 'x\n') - self.append('b', 'xy\n') - self.client.commit(b('first'), addremove=True) - - # no match - self.assertEquals(list(self.client.grep(b('c'))), []) - - if self.client.version >= (5, 2): - self.assertEquals(list(self.client.grep(b('x'))), - [(b('a'), b('x')), (b('b'), b('xy'))]) - self.assertEquals(list(self.client.grep(b('x'), b('a'))), - [(b('a'), b('x'))]) - - self.assertEquals(list(self.client.grep(b('y'))), - [(b('b'), b('xy'))]) - else: - self.assertEquals(list(self.client.grep(b('x'))), - [(b('a'), b('0'), b('x')), (b('b'), b('0'), b('xy'))]) - self.assertEquals(list(self.client.grep(b('x'), b('a'))), - [(b('a'), b('0'), b('x'))]) - self.assertEquals(list(self.client.grep(b('y'))), - [(b('b'), b('0'), b('xy'))]) - - def test_options(self): - self.append('a', 'x\n') - self.append('b', 'xy\n') - rev, node = self.client.commit(b('first'), addremove=True) - - self.assertEquals([(b('a'), b('0'), b('+'), b('x')), - (b('b'), b('0'), b('+'), b('xy'))], - list(self.client.grep(b('x'), all=True))) - - if self.client.version >= (5, 2): - self.assertEquals([(b('a'),), (b('b'),)], - list(self.client.grep(b('x'), fileswithmatches=True))) - - self.assertEquals([(b('a'), b('1'), b('x')), (b('b'), b('1'), b('xy'))], - list(self.client.grep(b('x'), line=True))) - - self.assertEquals([(b('a'), b('test'), b('x')), - (b('b'), b('test'), b('xy'))], - list(self.client.grep(b('x'), user=True))) - else: - self.assertEquals([(b('a'), b('0')), (b('b'), b('0'))], - list(self.client.grep(b('x'), fileswithmatches=True))) - - self.assertEquals([(b('a'), b('0'), b('1'), b('x')), - (b('b'), b('0'), b('1'), b('xy'))], - list(self.client.grep(b('x'), line=True))) - - self.assertEquals([(b('a'), b('0'), b('test'), b('x')), - (b('b'), b('0'), b('test'), b('xy'))], - list(self.client.grep(b('x'), user=True))) - - self.assertEquals([(b('a'), b('0'), b('1'), b('+'), b('test')), - (b('b'), b('0'), b('1'), b('+'), b('test'))], - list(self.client.grep(b('x'), all=True, user=True, - line=True, - fileswithmatches=True)))
--- a/tests/test-heads.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -from tests import common -from hglib.util import b - -class test_heads(common.basetest): - def test_empty(self): - self.assertEquals(self.client.heads(), []) - - def test_basic(self): - self.append('a', 'a') - rev, node0 = self.client.commit(b('first'), addremove=True) - self.assertEquals(self.client.heads(), [self.client.tip()]) - - self.client.branch(b('foo')) - self.append('a', 'a') - rev, node1 = self.client.commit(b('second')) - - self.assertEquals(self.client.heads(node0, topological=True), [])
--- a/tests/test-hglib.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -from tests import common -import hglib - -class test_hglib(common.basetest): - def setUp(self): - pass - - def test_close_fds(self): - """A weird Python bug that has something to do to inherited file - descriptors, see http://bugs.python.org/issue12786 - """ - common.basetest.setUp(self) - client2 = hglib.open() - self.client.close() - - def test_open_nonexistent(self): - # setup stuff necessary for basetest.tearDown() - self.clients = [] - self._oldopen = hglib.client.hgclient.open - try: - self.clients.append(hglib.open('inexistent')) - # hg 3.5 can't report error (fixed by 7332bf4ae959) - #self.fail('ServerError not raised') - except hglib.error.ServerError as inst: - self.assertTrue('inexistent' in str(inst))
--- a/tests/test-hidden.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -from tests import common -import hglib, datetime -from hglib.error import CommandError -from hglib.util import b - -class test_obsolete_reference(common.basetest): - """make sure obsolete changesets are disabled""" - def test_debugobsolete_failure(self): - f = open('gna1','w') - f.write('g') - f.close() - self.client.add(b('gna1')) - cs = self.client.commit(b('gna1'))[1] #get id - self.assertRaises(CommandError, - self.client.rawcommand, [b('debugobsolete'), cs]) - - -class test_obsolete_baselib(common.basetest): - """base test class with obsolete changesets enabled""" - def setUp(self): - #create an extension which only activates obsolete - super(test_obsolete_baselib, self).setUp() - self.append('.hg/obs.py', - "import mercurial.obsolete\n" - "# 3.2 and later\n" - "mercurial.obsolete.isenabled = lambda r, opt: True\n" - "# Dropped in 5.1\n" - "mercurial.obsolete._enabled = True") - self.append('.hg/hgrc','\n[extensions]\nobs=.hg/obs.py') - -class test_obsolete_client(test_obsolete_baselib): - """check client methods with obsolete changesets enabled""" - def test_debugobsolete_success(self): - """check the obsolete extension is available""" - self.append('gna1','ga') - self.client.add(b('gna1')) - cs = self.client.commit(b('gna1'))[1] #get id - self.client.rawcommand([b('debugobsolete'), cs]) - - def test_obsolete_in(self): - """test the 'hidden' keyword with the 'in' method""" - if self.client.version < (2, 9, 0): - return - self.append('gna1','ga') - self.client.add(b('gna1')) - cs0 = self.client.commit(b('gna1'))[1] #get id - self.append('gna2','gaaa') - self.client.add(b('gna2')) - cs1 = self.client.commit(b('gna2'))[1] #get id - self.client.rawcommand([b('debugobsolete'), cs1]) - self.client.update(cs0) - self.assertFalse(cs1 in self.client) - self.assertTrue(cs0 in self.client) - self.client.hidden = True - self.assertTrue(cs1 in self.client) - -class test_hidden_context(test_obsolete_baselib): - """test the "hidden" context method with obsolete changesets enabled on - hidden and visible changesets""" - def test_hidden(self): - if self.client.version < (2, 9, 0): - return - self.append('gna1','ga') - self.client.add(b('gna1')) - cs0 = self.client.commit(b('gna1'))[1] #get id - ctx0 = self.client[cs0] - self.append('gna2','gaaa') - self.client.add(b('gna2')) - cs1 = self.client.commit(b('gna2'))[1] #get id - ctx1 = self.client[cs1] - self.client.rawcommand([b('debugobsolete'), cs1]) - self.client.update(cs0) - self.assertTrue(ctx1.hidden()) - self.assertFalse(ctx0.hidden())
--- a/tests/test-import.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -import os -from tests import common -from hglib.util import b, BytesIO - -patch = b(""" -# HG changeset patch -# User test -# Date 0 0 -# Node ID c103a3dec114d882c98382d684d8af798d09d857 -# Parent 0000000000000000000000000000000000000000 -1 - -diff -r 000000000000 -r c103a3dec114 a ---- /dev/null Thu Jan 01 00:00:00 1970 +0000 -+++ b/a Thu Jan 01 00:00:00 1970 +0000 -@@ -0,0 +1,1 @@ -+1 -""") - -class test_import(common.basetest): - def test_basic_cstringio(self): - self.client.import_(BytesIO(patch)) - self.assertEquals(self.client.cat([b('a')]), b('1\n')) - - def test_basic_file(self): - f = open('patch', 'wb') - f.write(patch) - f.close() - - # --no-commit - self.client.import_([b('patch')], nocommit=True) - self.assertEquals(open('a').read(), '1\n') - - self.client.update(clean=True) - os.remove('a') - - self.client.import_([b('patch')]) - self.assertEquals(self.client.cat([b('a')]), b('1\n'))
--- a/tests/test-init.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -from tests import common -import hglib, shutil -from hglib.util import b - -class test_init(common.basetest): - def test_exists(self): - self.assertRaises(hglib.error.CommandError, hglib.init) - - def test_basic(self): - self.client.close() - self.client = None - shutil.rmtree('.hg') - - self.client = hglib.init().open() - self.assertTrue(self.client.root().endswith(b('test_init')))
--- a/tests/test-log.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -from tests import common -import hglib -from hglib.util import b - -class test_log(common.basetest): - def test_basic(self): - self.append('a', 'a') - rev0, node0 = self.client.commit(b('first'), addremove=True) - self.append('a', 'a') - rev1, node1 = self.client.commit(b('second')) - - revs = self.client.log() - revs.reverse() - - self.assertTrue(len(revs) == 2) - self.assertEquals(revs[1].node, node1) - - self.assertEquals(revs[0], self.client.log(b('0'))[0]) - self.assertEquals(self.client.log(), self.client.log(files=[b('a')])) - - self.assertEquals(self.client.log(), self.client.log(hidden=True)) - - def test_dash_in_filename(self): - self.append('-a', '-a') - self.client.commit(b('first'), addremove=True) - revs = self.client.log(files=[b('-a')]) - self.assertTrue(len(revs) == 1) - self.assertEquals(revs[0].rev, b('0')) - - def test_empty_short_option(self): - self.append('foobar', 'foobar') - self.client.commit(b('first'), addremove=True) - revs = self.client.log(keyword=b(''), files=[b('foobar')]) - self.assertTrue(len(revs) == 1) - self.assertEquals(revs[0].rev, b('0')) - - # def test_errors(self): - # self.assertRaisesRegexp(CommandError, 'abort: unknown revision', - # self.client.log, 'foo') - # self.append('a', 'a') - # self.client.commit('first', addremove=True) - # self.assertRaisesRegexp(CommandError, - # 'abort: unknown revision', - # self.client.log, 'bar')
--- a/tests/test-manifest.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -from tests import common -import hglib, os, stat -from hglib.util import b - -class test_manifest(common.basetest): - def test_basic(self): - self.append('a', 'a') - files = [b('a')] - manifest = [(b('047b75c6d7a3ef6a2243bd0e99f94f6ea6683597'), b('644'), - False, False, b('a'))] - - if os.name == 'posix': - self.append('b', 'b') - os.chmod('b', os.stat('b')[0] | stat.S_IEXEC) - os.symlink('b', 'c') - - files.extend([b('b'), b('c')]) - manifest.extend([(b('62452855512f5b81522aa3895892760bb8da9f3f'), - b('755'), True, False, b('b')), - (b('62452855512f5b81522aa3895892760bb8da9f3f'), - b('644'), False, True, b('c'))]) - - self.client.commit(b('first'), addremove=True) - - self.assertEquals(list(self.client.manifest(all=True)), files) - - self.assertEquals(list(self.client.manifest()), manifest)
--- a/tests/test-merge.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -from tests import common -import hglib -from hglib.util import b - -class test_merge(common.basetest): - def setUp(self): - common.basetest.setUp(self) - - self.append('a', 'a') - rev, self.node0 = self.client.commit(b('first'), addremove=True) - - self.append('a', 'a') - rev, self.node1 = self.client.commit(b('change')) - - def test_basic(self): - self.client.update(self.node0) - self.append('b', 'a') - rev, node2 = self.client.commit(b('new file'), addremove=True) - self.client.merge(self.node1) - rev, node = self.client.commit(b('merge')) - diff = b("diff -r ") + node2[:12] + b(" -r ") + node[:12] + b(""" a ---- a/a -+++ b/a -@@ -1,1 +1,1 @@ --a -\ No newline at end of file -+aa -\ No newline at end of file -""") - - self.assertEquals(diff, self.client.diff(change=node, nodates=True)) - - def test_merge_prompt_abort(self): - self.client.update(self.node0) - self.client.remove(b('a')) - self.client.commit(b('remove')) - - self.assertRaises(hglib.error.CommandError, self.client.merge) - - def test_merge_prompt_noninteractive(self): - self.client.update(self.node0) - self.client.remove(b('a')) - rev, node = self.client.commit(b('remove')) - - if self.client.version >= (3, 7): - self.assertRaises(hglib.error.CommandError, - self.client.merge, - cb=hglib.merge.handlers.noninteractive) - else: - self.client.merge(cb=hglib.merge.handlers.noninteractive) - - diff = b("diff -r ") + node[:12] + b(""" a ---- /dev/null -+++ b/a -@@ -0,0 +1,1 @@ -+aa -\ No newline at end of file -""") - self.assertEquals(diff, self.client.diff(nodates=True)) - - def test_merge_prompt_cb(self): - self.client.update(self.node0) - self.client.remove(b('a')) - rev, node = self.client.commit(b('remove')) - - def cb(output): - return b('c') - - self.client.merge(cb=cb) - - diff = b("diff -r ") + node[:12] + b(""" a ---- /dev/null -+++ b/a -@@ -0,0 +1,1 @@ -+aa -\ No newline at end of file -""") - self.assertEquals(diff, self.client.diff(nodates=True))
--- a/tests/test-move.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -import os -from tests import common -from hglib.util import b - -class test_move(common.basetest): - def test_basic(self): - self.append('a', 'a') - self.client.add(b('a')) - self.assertTrue(self.client.move(b('a'), b('b'))) - - # hg returns 0 even if there were warnings - #def test_warnings(self): - # self.append('a', 'a') - # self.client.add('a') - # os.mkdir('c') - # self.assertFalse(self.client.move(['a', 'b'], 'c'))
--- a/tests/test-outgoing-incoming.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -from tests import common -import hglib -from hglib.util import b - -class test_outgoing_incoming(common.basetest): - def test_no_path(self): - self.assertRaises(hglib.error.CommandError, self.client.incoming) - - def test_empty(self): - self.client.clone(dest=b('other')) - self.other = hglib.open(b('other')) - - self.assertEquals(self.other.incoming(), []) - self.assertEquals(self.other.outgoing(), []) - - def test_basic(self): - self.append('a', 'a') - self.client.commit(b('first'), addremove=True) - self.append('a', 'a') - self.client.commit(b('second')) - - self.client.clone(dest=b('other')) - other = hglib.open(b('other')) - - self.assertEquals(self.client.log(), other.log()) - self.assertEquals(self.client.outgoing(path=b('other')), - other.incoming()) - - self.append('a', 'a') - rev, node = self.client.commit(b('third')) - out = self.client.outgoing(path=b('other')) - - self.assertEquals(len(out), 1) - self.assertEquals(out[0].node, node) - - self.assertEquals(out, other.incoming()) - - def test_bookmarks(self): - self.append('a', 'a') - self.client.commit(b('first'), addremove=True) - self.append('a', 'a') - self.client.commit(b('second')) - - self.client.clone(dest=b('other')) - other = hglib.open(b('other')) - - self.client.bookmark(b('bm1'), 1) - - self.assertEquals(other.incoming(bookmarks=True), - [(b('bm1'), self.client.tip().node[:12])]) - - self.assertEquals(self.client.outgoing(path=b('other'), bookmarks=True), - [(b('bm1'), self.client.tip().node[:12])])
--- a/tests/test-parents.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -from tests import common -from hglib.util import b - -class test_parents(common.basetest): - def test_noparents(self): - self.assertEquals(self.client.parents(), None) - - def test_basic(self): - self.append('a', 'a') - rev, node = self.client.commit(b('first'), addremove=True) - self.assertEquals(node, self.client.parents()[0].node) - self.assertEquals(node, self.client.parents(file=b('a'))[0].node) - - def test_two_parents(self): - pass
--- a/tests/test-paths.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -import os -from tests import common -import hglib -from hglib.util import b - -class test_paths(common.basetest): - def test_basic(self): - f = open('.hg/hgrc', 'a') - f.write('[paths]\nfoo = bar\n') - f.close() - - # hgrc isn't watched for changes yet, have to reopen - self.client = hglib.open() - paths = self.client.paths() - self.assertEquals(len(paths), 1) - self.assertEquals(paths[b('foo')], - os.path.abspath('bar').encode('latin-1')) - self.assertEquals(self.client.paths(b('foo')), - os.path.abspath('bar').encode('latin-1'))
--- a/tests/test-phase.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -from tests import common -import hglib -from hglib.util import b - -class test_phase(common.basetest): - """test the different ways to use the phase command""" - def test_phase(self): - """test getting data from a single changeset""" - self.append('a', 'a') - rev, node0 = self.client.commit(b('first'), addremove=True) - self.assertEqual([(0, b('draft'))], self.client.phase(node0)) - ctx = self.client[rev] - self.assertEqual(b('draft'), ctx.phase()) - - def test_phase_public(self): - """test phase change from draft to public""" - self.append('a', 'a') - rev, node0 = self.client.commit(b('first'), addremove=True) - self.client.phase(node0, public=True) - self.assertEqual([(0, b('public'))], self.client.phase(node0)) - ctx = self.client[rev] - self.assertEqual(b('public'), ctx.phase()) - - def test_phase_secret(self): - """test phase change from draft to secret""" - self.append('a', 'a') - rev, node0 = self.client.commit(b('first'), addremove=True) - self.assertRaises(hglib.error.CommandError, - self.client.phase, node0, secret=True) - self.client.phase(node0, secret=True, force=True) - self.assertEqual([(0, b('secret'))], self.client.phase(node0)) - ctx = self.client[rev] - self.assertEqual(b('secret'), ctx.phase()) - - - def test_phase_multiple(self): - """test phase changes and show the phases of the different changesets""" - self.append('a', 'a') - rev, node0 = self.client.commit(b('a'), addremove=True) - self.client.phase(node0, public=True) - self.append('b', 'b') - rev, node1 = self.client.commit(b('b'), addremove=True) - self.append('c', 'c') - rev, node2 = self.client.commit(b('c'), addremove=True) - self.client.phase(node2, secret=True, force=True) - self.assertEqual([(0, b('public')), (2, b('secret')), (1, b('draft'))], - self.client.phase([node0, node2, node1]))
--- a/tests/test-pull.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -from tests import common -import hglib -from hglib.util import b - -class test_pull(common.basetest): - def test_basic(self): - self.append('a', 'a') - self.client.commit(b('first'), addremove=True) - - self.client.clone(dest=b('other')) - other = hglib.open(b('other')) - - self.append('a', 'a') - self.client.commit(b('second')) - - self.assertTrue(other.pull()) - self.assertEquals(self.client.log(), other.log()) - - def test_unresolved(self): - self.append('a', 'a') - self.client.commit(b('first'), addremove=True) - - self.client.clone(dest=b('other')) - other = hglib.open(b('other')) - - self.append('a', 'a') - self.client.commit(b('second')) - - self.append('other/a', 'b') - self.assertFalse(other.pull(update=True)) - self.assertTrue((b('M'), b('a')) in other.status())
--- a/tests/test-push.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -from tests import common -import hglib -from hglib.util import b - -class test_push(common.basetest): - def test_basic(self): - self.append('a', 'a') - self.client.commit(b('first'), addremove=True) - - self.client.clone(dest=b('other')) - other = hglib.open(b('other')) - - # broken in hg, doesn't return 1 if nothing to push - #self.assertFalse(self.client.push('other')) - - self.append('a', 'a') - self.client.commit(b('second')) - - self.assertTrue(self.client.push(b('other'))) - self.assertEquals(self.client.log(), other.log())
--- a/tests/test-remove.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -from tests import common -from hglib.util import b - -class test_remove(common.basetest): - def test_basic(self): - self.append('a', 'a') - self.client.commit(b('first'), addremove=True) - self.assertTrue(self.client.remove([b('a')])) - - def test_warnings(self): - self.append('a', 'a') - self.client.commit(b('first'), addremove=True) - self.assertFalse(self.client.remove([b('a'), b('b')]))
--- a/tests/test-resolve.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -from tests import common -import hglib -from hglib.util import b - -class test_resolve(common.basetest): - def setUp(self): - common.basetest.setUp(self) - - self.append('a', 'a') - self.append('b', 'b') - rev, self.node0 = self.client.commit(b('first'), addremove=True) - - self.append('a', 'a') - self.append('b', 'b') - rev, self.node1 = self.client.commit(b('second')) - - def test_basic(self): - self.client.update(self.node0) - self.append('a', 'b') - self.append('b', 'a') - rev, self.node3 = self.client.commit(b('third')) - - self.assertRaises(hglib.error.CommandError, self.client.merge, - self.node1) - self.assertRaises(hglib.error.CommandError, - self.client.resolve, all=True) - - self.assertEquals([(b('U'), b('a')), (b('U'), b('b'))], - self.client.resolve(listfiles=True)) - - self.client.resolve(b('a'), mark=True) - self.assertEquals([(b('R'), b('a')), (b('U'), b('b'))], - self.client.resolve(listfiles=True))
--- a/tests/test-status.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -import os -from tests import common -from hglib.util import b - -class test_status(common.basetest): - def test_empty(self): - self.assertEquals(self.client.status(), []) - - def test_one_of_each(self): - self.append('.hgignore', 'ignored') - self.append('ignored', 'a') - self.append('clean', 'a') - self.append('modified', 'a') - self.append('removed', 'a') - self.append('missing', 'a') - self.client.commit(b('first'), addremove=True) - self.append('modified', 'a') - self.append('added', 'a') - self.client.add([b('added')]) - os.remove('missing') - self.client.remove([b('removed')]) - self.append('untracked') - - l = [(b('M'), b('modified')), - (b('A'), b('added')), - (b('R'), b('removed')), - (b('C'), b('.hgignore')), - (b('C'), b('clean')), - (b('!'), b('missing')), - (b('?'), b('untracked')), - (b('I'), b('ignored'))] - - st = self.client.status(all=True) - - for i in l: - self.assertTrue(i in st) - - def test_copy(self): - self.append('source', 'a') - self.client.commit(b('first'), addremove=True) - self.client.copy(b('source'), b('dest')) - l = [(b('A'), b('dest')), (b(' '), b('source'))] - self.assertEquals(self.client.status(copies=True), l) - - def test_copy_origin_space(self): - self.append('s ource', 'a') - self.client.commit(b('first'), addremove=True) - self.client.copy(b('s ource'), b('dest')) - l = [(b('A'), b('dest')), (b(' '), b('s ource'))] - self.assertEquals(self.client.status(copies=True), l)
--- a/tests/test-summary.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,135 +0,0 @@ -import unittest -from tests import common -import hglib -from hglib.util import b - -class test_summary(common.basetest): - def test_empty(self): - d = {b('parent') : [(-1, b('000000000000'), b('tip'), None)], - b('branch') : b('default'), - b('commit') : True, - b('update') : 0} - - self.assertEquals(self.client.summary(), d) - - def test_basic(self): - self.append('a', 'a') - rev, node = self.client.commit(b('first'), addremove=True) - - d = {b('parent') : [(0, node[:12], b('tip'), b('first'))], - b('branch') : b('default'), - b('commit') : True, - b('update') : 0} - if self.client.version >= (3, 5): - d[b('phases')] = b('1 draft') - - self.assertEquals(self.client.summary(), d) - - def test_commit_dirty(self): - self.append('a', 'a') - rev, node = self.client.commit(b('first'), addremove=True) - self.append('a', 'a') - - d = {b('parent') : [(0, node[:12], b('tip'), b('first'))], - b('branch') : b('default'), - b('commit') : False, - b('update') : 0} - if self.client.version >= (3, 5): - d[b('phases')] = b('1 draft') - - self.assertEquals(self.client.summary(), d) - - def test_secret_commit_clean(self): - if self.client.version < (2, 1): - raise unittest.SkipTest('phase not supported') - self.append('a', 'a') - rev, node = self.client.commit(b('first'), addremove=True) - self.client.phase([b('%d') % rev], secret=True, force=True) - e = self.client.summary() - self.assertTrue(e[b('commit')]) - - def test_update(self): - self.append('a', 'a') - rev, node = self.client.commit(b('first'), addremove=True) - self.append('a', 'a') - self.client.commit(b('second')) - self.client.update(0) - - d = {b('parent') : [(0, node[:12], None, b('first'))], - b('branch') : b('default'), - b('commit') : True, - b('update') : 1} - if self.client.version >= (3, 5): - d[b('phases')] = b('2 draft') - - self.assertEquals(self.client.summary(), d) - - def test_remote(self): - self.append('a', 'a') - rev, node = self.client.commit(b('first'), addremove=True) - - self.client.clone(dest=b('other')) - other = hglib.open('other') - - d = {b('parent') : [(0, node[:12], b('tip'), b('first'))], - b('branch') : b('default'), - b('commit') : True, - b('update') : 0, - b('remote') : (0, 0, 0, 0)} - - self.assertEquals(other.summary(remote=True), d) - - self.append('a', 'a') - self.client.commit(b('second')) - - d[b('remote')] = (1, 0, 0, 0) - self.assertEquals(other.summary(remote=True), d) - - self.client.bookmark(b('bm')) - d[b('remote')] = (1, 1, 0, 0) - self.assertEquals(other.summary(remote=True), d) - - other.bookmark(b('bmother')) - d[b('remote')] = (1, 1, 0, 1) - if self.client.version < (2, 0, 0): - d[b('parent')] = [(0, node[:12], b('tip bmother'), b('first'))] - else: - d[b('bookmarks')] = b('*bmother') - self.assertEquals(other.summary(remote=True), d) - - self.append('other/a', 'a') - rev, node = other.commit(b('second in other')) - - d[b('remote')] = (1, 1, 1, 1) - if self.client.version < (2, 0, 0): - tags = b('tip bmother') - else: - tags = b('tip') - d[b('parent')] = [(1, node[:12], tags, b('second in other'))] - if self.client.version >= (3, 5): - d[b('phases')] = b('1 draft') - - self.assertEquals(other.summary(remote=True), d) - - def test_two_parents(self): - self.append('a', 'a') - rev0, node = self.client.commit(b('first'), addremove=True) - - self.append('a', 'a') - rev1, node1 = self.client.commit(b('second')) - - self.client.update(rev0) - self.append('b', 'a') - rev2, node2 = self.client.commit(b('third'), addremove=True) - - self.client.merge(rev1) - - d = {b('parent') : [(2, node2[:12], b('tip'), b('third')), - (1, node1[:12], None, b('second'))], - b('branch') : b('default'), - b('commit') : False, - b('update') : 0} - if self.client.version >= (3, 5): - d[b('phases')] = b('3 draft') - - self.assertEquals(self.client.summary(), d)
--- a/tests/test-tags.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -from tests import common -import hglib -from hglib.util import b - -class test_tags(common.basetest): - def test_basic(self): - self.append('a', 'a') - rev, node = self.client.commit(b('first'), addremove=True) - self.client.tag(b('my tag')) - self.client.tag(b('local tag'), rev=rev, local=True) - - # filecache that was introduced in 2.0 makes us see the local tag, for - # now we have to reconnect - if self.client.version < (2, 0, 0): - self.client = hglib.open() - - tags = self.client.tags() - self.assertEquals(tags, - [(b('tip'), 1, self.client.tip().node[:12], False), - (b('my tag'), 0, node[:12], False), - (b('local tag'), 0, node[:12], True)])
--- a/tests/test-update.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -from tests import common -from hglib import error -from hglib.util import b, strtobytes - -class test_update(common.basetest): - def setUp(self): - common.basetest.setUp(self) - self.append('a', 'a') - self.rev0, self.node0 = self.client.commit(b('first'), addremove=True) - self.append('a', 'a') - self.rev1, self.node1 = self.client.commit(b('second')) - - def test_basic(self): - u, m, r, ur = self.client.update(self.rev0) - self.assertEquals(u, 1) - self.assertEquals(m, 0) - self.assertEquals(r, 0) - self.assertEquals(ur, 0) - - def test_unresolved(self): - self.client.update(self.rev0) - self.append('a', 'b') - u, m, r, ur = self.client.update() - self.assertEquals(u, 0) - self.assertEquals(m, 0) - self.assertEquals(r, 0) - self.assertEquals(ur, 1) - self.assertTrue((b('M'), b('a')) in self.client.status()) - - def test_merge(self): - self.append('a', '\n\n\n\nb') - rev2, node2 = self.client.commit(b('third')) - self.append('a', 'b') - self.client.commit(b('fourth')) - self.client.update(rev2) - old = open('a').read() - f = open('a', 'wb') - f.write(b('a') + old.encode('latin-1')) - f.close() - u, m, r, ur = self.client.update() - self.assertEquals(u, 0) - self.assertEquals(m, 1) - self.assertEquals(r, 0) - self.assertEquals(ur, 0) - self.assertEquals(self.client.status(), [(b('M'), b('a'))]) - - def test_tip(self): - self.client.update(self.rev0) - u, m, r, ur = self.client.update() - self.assertEquals(u, 1) - self.assertEquals(self.client.parents()[0].node, self.node1) - - self.client.update(self.rev0) - self.append('a', 'b') - rev2, node2 = self.client.commit(b('new head')) - self.client.update(self.rev0) - - self.client.update() - self.assertEquals(self.client.parents()[0].node, node2) - - def test_check_clean(self): - self.assertRaises(ValueError, self.client.update, clean=True, - check=True) - - def test_clean(self): - old = open('a').read() - self.append('a', 'b') - self.assertRaises(error.CommandError, self.client.update, check=True) - - u, m, r, ur = self.client.update(clean=True) - self.assertEquals(u, 1) - self.assertEquals(old, open('a').read()) - - def test_basic_plain(self): - f = open('.hg/hgrc', 'a') - f.write('[defaults]\nupdate=-v\n') - f.close() - self.test_basic() - - def disabled_largefiles(self): - # we don't run reposetup after a session has started, so this - # test is broken - import os - f = open('.hg/hgrc', 'a') - f.write('[extensions]\nlargefiles=\n') - f.close() - self.append('b', 'a') - try: - self.client.rawcommand([b('add'), b('b'), b('--large')]) - except error.CommandError: - return - - rev2, node2 = self.client.commit(b('third')) - # Go back to 0 - self.client.rawcommand([b('update'), strtobytes(self.rev0)], - # Keep the 'changed' version - prompt=lambda s, d: 'c\n') - u, m, r, ur = self.client.update(rev2, clean=True) - self.assertEquals(u, 2) - self.assertEquals(m, 0) - self.assertEquals(r, 0) - self.assertEquals(ur, 0)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_annotate.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,32 @@ +from tests import common +from hglib.util import b + +class test_annotate(common.basetest): + def test_basic(self): + self.append('a', 'a\n') + rev, node0 = self.client.commit(b('first'), addremove=True) + self.append('a', 'a\n') + rev, node1 = self.client.commit(b('second')) + + self.assertEquals(list(self.client.annotate(b('a'))), + [(b('0'), b('a')), (b('1'), b('a'))]) + self.assertEquals(list( + self.client.annotate( + b('a'), user=True, file=True, + number=True, changeset=True, line=True, verbose=True)), + [(b('test 0 ') + node0[:12] + b(' a:1'), b('a')), + (b('test 1 ') + node1[:12] + b(' a:2'), b('a'))]) + + def test_files(self): + self.append('a', 'a\n') + rev, node0 = self.client.commit(b('first'), addremove=True) + self.append('b', 'b\n') + rev, node1 = self.client.commit(b('second'), addremove=True) + self.assertEquals(list(self.client.annotate([b('a'), b('b')])), + [(b('0'), b('a')), (b('1'), b('b'))]) + + def test_two_colons(self): + self.append('a', 'a: b\n') + self.client.commit(b('first'), addremove=True) + self.assertEquals(list(self.client.annotate(b('a'))), + [(b('0'), b('a: b'))])
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_bookmarks.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,26 @@ +from tests import common +from hglib.util import b + +class test_bookmarks(common.basetest): + def test_empty(self): + self.assertEquals(self.client.bookmarks(), ([], -1)) + + def test_basic(self): + self.append('a', 'a') + rev0, node0 = self.client.commit(b('first'), addremove=True) + self.append('a', 'a') + rev1, node1 = self.client.commit(b('second')) + + self.client.bookmark(b('zero'), rev0) + self.assertEquals(self.client.bookmarks(), + ([(b('zero'), rev0, node0[:12])], -1)) + + self.client.bookmark(b('one'), rev1) + self.assertEquals(self.client.bookmarks()[0], + [(b('one'), rev1, node1[:12]), + (b('zero'), rev0, node0[:12])]) + + #def test_spaces(self): + # self.client.bookmark('s pace', self.rev0) + # self.assertEquals(self.client.bookmarks(), + # ([('s pace', 0, self.rev0.node[:12])], -1))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_branch.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,46 @@ +from tests import common +import hglib +from hglib.util import b + +class test_branch(common.basetest): + def test_empty(self): + self.assertEquals(self.client.branch(), b('default')) + + def test_basic(self): + self.assertEquals(self.client.branch(b('foo')), b('foo')) + self.append('a', 'a') + rev, node = self.client.commit(b('first'), addremove=True) + + rev = self.client.log(node)[0] + + self.assertEquals(rev.branch, b('foo')) + self.assertEquals(self.client.branches(), + [(rev.branch, int(rev.rev), rev.node[:12])]) + + def test_reset_with_name(self): + self.assertRaises(ValueError, self.client.branch, b('foo'), clean=True) + + def test_reset(self): + self.client.branch(b('foo')) + self.assertEquals(self.client.branch(clean=True), b('default')) + + def test_exists(self): + self.append('a', 'a') + self.client.commit(b('first'), addremove=True) + self.client.branch(b('foo')) + self.append('a', 'a') + self.client.commit(b('second')) + self.assertRaises(hglib.error.CommandError, + self.client.branch, b('default')) + + def test_force(self): + self.append('a', 'a') + self.client.commit(b('first'), addremove=True) + self.client.branch(b('foo')) + self.append('a', 'a') + self.client.commit(b('second')) + + self.assertRaises(hglib.error.CommandError, + self.client.branch, b('default')) + self.assertEquals(self.client.branch(b('default'), force=True), + b('default'))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_branches.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,25 @@ +from tests import common +import hglib +from hglib.util import b + +class test_branches(common.basetest): + def test_empty(self): + self.assertEquals(self.client.branches(), []) + + def test_basic(self): + self.append('a', 'a') + rev0 = self.client.commit(b('first'), addremove=True) + self.client.branch(b('foo')) + self.append('a', 'a') + rev1 = self.client.commit(b('second')) + branches = self.client.branches() + + expected = [] + for r, n in (rev1, rev0): + r = self.client.log(r)[0] + expected.append((r.branch, int(r.rev), r.node[:12])) + + self.assertEquals(branches, expected) + + def test_active_closed(self): + pass
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_bundle.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,18 @@ +from tests import common +from hglib.util import b + +class test_bundle(common.basetest): + def test_no_changes(self): + self.append('a', 'a') + rev, node0 = self.client.commit(b('first'), addremove=True) + self.assertFalse(self.client.bundle(b('bundle'), destrepo=b('.'))) + + def test_basic(self): + self.append('a', 'a') + rev, node0 = self.client.commit(b('first'), addremove=True) + self.client.clone(dest=b('other')) + + self.append('a', 'a') + rev, node1 = self.client.commit(b('second')) + + self.assertTrue(self.client.bundle(b('bundle'), destrepo=b('other')))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_clone.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,16 @@ +import os +from tests import common +import hglib +from hglib.util import b + +class test_clone(common.basetest): + def test_basic(self): + self.append('a', 'a') + self.client.commit(b('first'), addremove=True) + cloned = hglib.clone(b('.'), b('cloned')) + self.assertRaises(ValueError, cloned.log) + cloned.open() + self.assertEquals(self.client.log(), cloned.log()) + + def test_clone_uncompressed(self): + hglib.clone(b('.'), b('cloned'), uncompressed=True)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_commit.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,67 @@ +from tests import common +import hglib, datetime +from hglib.util import b + +class test_commit(common.basetest): + def test_user(self): + self.append('a', 'a') + rev, node = self.client.commit(b('first'), addremove=True, + user=b('foo')) + rev = self.client.log(node)[0] + self.assertEquals(rev.author, b('foo')) + + def test_no_user(self): + self.append('a', 'a') + self.assertRaises(hglib.error.CommandError, + self.client.commit, b('first'), user=b('')) + + def test_close_branch(self): + self.append('a', 'a') + rev0, node0 = self.client.commit(b('first'), addremove=True) + self.client.branch(b('foo')) + self.append('a', 'a') + rev1, node1 = self.client.commit(b('second')) + revclose = self.client.commit(b('closing foo'), closebranch=True) + rev0, rev1, revclose = self.client.log([node0, node1, revclose[1]]) + + self.assertEquals(self.client.branches(), + [(rev0.branch, int(rev0.rev), rev0.node[:12])]) + + self.assertEquals(self.client.branches(closed=True), + [(revclose.branch, int(revclose.rev), + revclose.node[:12]), + (rev0.branch, int(rev0.rev), rev0.node[:12])]) + + def test_message_logfile(self): + self.assertRaises(ValueError, self.client.commit, b('foo'), + logfile=b('bar')) + self.assertRaises(ValueError, self.client.commit) + + def test_date(self): + self.append('a', 'a') + now = datetime.datetime.now().replace(microsecond=0) + rev0, node0 = self.client.commit( + b('first'), addremove=True, + date=now.isoformat(' ').encode('latin-1')) + + self.assertEquals(now, self.client.tip().date) + + def test_amend(self): + self.append('a', 'a') + now = datetime.datetime.now().replace(microsecond=0) + rev0, node0 = self.client.commit( + b('first'), addremove=True, + date=now.isoformat(' ').encode('latin-1')) + + self.assertEquals(now, self.client.tip().date) + + self.append('a', 'a') + rev1, node1 = self.client.commit(amend=True) + self.assertEquals(now, self.client.tip().date) + self.assertNotEquals(node0, node1) + self.assertEqual(1, len(self.client.log())) + + def test_nul_injection(self): + self.append('a', 'a') + self.assertRaises(ValueError, lambda: self.client.commit(b('fail\0-A'))) + self.assertEqual(0, len(self.client.log()))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_config.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,37 @@ +from tests import common +import os, hglib +from hglib.util import b + +class test_config(common.basetest): + def setUp(self): + common.basetest.setUp(self) + f = open('.hg/hgrc', 'a') + f.write('[section]\nkey=value\n') + f.close() + self.client = hglib.open() + + def test_basic(self): + config = self.client.config() + + self.assertTrue( + (b('section'), b('key'), b('value')) in self.client.config()) + + self.assertTrue([(b('section'), b('key'), b('value'))], + self.client.config(b('section'))) + self.assertTrue([(b('section'), b('key'), b('value'))], + self.client.config([b('section'), b('foo')])) + self.assertRaises(hglib.error.CommandError, + self.client.config, [b('a.b'), b('foo')]) + + def test_show_source(self): + config = self.client.config(showsource=True) + + self.assertTrue((os.path.abspath(b('.hg/hgrc')) + b(':2'), + b('section'), b('key'), b('value')) in config) + +class test_config_arguments(common.basetest): + def test_basic(self): + client = hglib.open(configs=[b('diff.unified=5'), b('a.b=foo')]) + self.assertEqual(client.config(b('a')), [(b('a'), b('b'), b('foo'))]) + self.assertEqual(client.config(b('diff')), + [(b('diff'), b('unified'), b('5'))])
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_context.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,95 @@ +import sys +from tests import common +from hglib.error import CommandError +import hglib +from hglib import context +from hglib.util import b + +class test_context(common.basetest): + def test_non_existent(self): + self.assertRaises(ValueError, context.changectx, self.client, b('foo')) + + def test_basic(self): + self.append('a', 'a') + self.append('b', 'b') + rev0, node0 = self.client.commit(b('first'), addremove=True) + + self.append('c', 'c') + rev1, node1 = self.client.commit(b('second'), addremove=True) + + self.assertRaises(KeyError, self.client.__getitem__, 'doesnotexist') + + ctx = self.client[node0] + + self.assertEquals(ctx.description(), b('first')) + self.assertEquals(str(ctx), node0[:12].decode('latin-1')) + self.assertEquals(ctx.node(), node0) + self.assertEquals(int(ctx), rev0) + self.assertEquals(ctx.rev(), rev0) + self.assertEquals(ctx.branch(), b('default')) + + self.assertTrue(ctx) + + self.assertTrue(b('a') in ctx and b('b') in ctx) + self.assertFalse(b('c') in ctx) + self.assertEquals(list(ctx), [b('a'), b('b')]) + self.assertEquals(ctx.files(), [b('a'), b('b')]) + + self.assertEquals(ctx.modified(), []) + self.assertEquals(ctx.added(), [b('a'), b('b')]) + self.assertEquals(ctx.removed(), []) + self.assertEquals(ctx.ignored(), []) + self.assertEquals(ctx.clean(), []) + + man = {b('a') : b('047b75c6d7a3ef6a2243bd0e99f94f6ea6683597'), + b('b') : b('62452855512f5b81522aa3895892760bb8da9f3f')} + self.assertEquals(ctx.manifest(), man) + + self.assertEquals([int(c) for c in ctx.parents()], [-1]) + self.assertEquals(int(ctx.p1()), -1) + self.assertEquals(int(ctx.p2()), -1) + + self.assertEquals([int(c) for c in ctx.children()], [1]) + self.assertEquals([int(c) for c in ctx.descendants()], [0, 1]) + self.assertEquals([int(c) for c in ctx.ancestors()], [0]) + + self.client.bookmark(b('bookmark'), inactive=True, rev=node0) + self.assertEquals(ctx.bookmarks(), [b('bookmark')]) + + self.client.tag(b('tag'), rev=node0) + # tags are read on construction + self.assertEquals(self.client[node0].tags(), [b('tag')]) + + def test_construction(self): + self.append('a', 'a') + rev0, node0 = self.client.commit(b('first'), addremove=True) + tip = self.client.tip() + + # from client.revision + ctx = context.changectx(self.client, tip) + self.assertEquals(ctx.node(), tip.node) + + # from revset + ctx = context.changectx(self.client, b('all()')) + self.assertEquals(ctx.node(), tip.node) + + def test_in_keyword(self): + """ + test the 'in' keyword using both revision numbers or changeset ids. + """ + if sys.version_info < (2, 7): + return + + self.append('a', 'a') + rev0, node0 = self.client.commit(b('first'), addremove=True) + self.append('a', 'a') + rev1, node1 = self.client.commit(b('second')) + + self.assertIn(1, self.client) + hash_1 = self.client.log(0)[0][1] + self.assertIn(hash_1, self.client) + self.assertNotIn(2, self.client) + hash_2 = self.client.log(1)[0][1] + self.assertIn(hash_2, self.client) + hash_2 = b('deadbeef') + self.assertNotIn(hash_2, self.client)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_copy.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,23 @@ +from tests import common +import hglib +from hglib.util import b + +class test_copy(common.basetest): + def test_basic(self): + self.append('a', 'a') + self.client.commit(b('first'), addremove=True) + + self.assertTrue(self.client.copy(b('a'), b('b'))) + self.assertEquals(self.client.status(), [(b('A'), b('b'))]) + self.append('c', 'a') + self.assertTrue(self.client.copy(b('a'), b('c'), after=True)) + self.assertEquals(self.client.status(), + [(b('A'), b('b')), (b('A'), b('c'))]) + + # hg returns 0 even if there were warnings + #def test_warnings(self): + # self.append('a', 'a') + # self.client.commit('first', addremove=True) + + # self.assertTrue(self.client.copy('a', 'b')) + # self.assertFalse(self.client.copy('a', 'b'))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_diff.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,47 @@ +from tests import common +from hglib.util import b + +class test_diff(common.basetest): + def test_basic(self): + self.append('a', 'a\n') + self.client.add(b('a')) + diff1 = b("""diff -r 000000000000 a +--- /dev/null ++++ b/a +@@ -0,0 +1,1 @@ ++a +""") + self.assertEquals(diff1, self.client.diff(nodates=True)) + self.assertEquals(diff1, self.client.diff([b('a')], nodates=True)) + rev0, node0 = self.client.commit(b('first')) + diff2 = b("""diff -r 000000000000 -r """) + node0[:12] + b(""" a +--- /dev/null ++++ b/a +@@ -0,0 +1,1 @@ ++a +""") + self.assertEquals(diff2, self.client.diff(change=rev0, nodates=True)) + self.append('a', 'a\n') + rev1, node1 = self.client.commit(b('second')) + diff3 = b("""diff -r """) + node0[:12] + b(""" a +--- a/a ++++ b/a +@@ -1,1 +1,2 @@ + a ++a +""") + self.assertEquals(diff3, self.client.diff(revs=[rev0], nodates=True)) + diff4 = b("""diff -r """) + node0[:12] + b(" -r ") + node1[:12] + b( + """ a +--- a/a ++++ b/a +@@ -1,1 +1,2 @@ + a ++a +""") + self.assertEquals(diff4, self.client.diff(revs=[rev0, rev1], + nodates=True)) + + def test_basic_plain(self): + open('.hg/hgrc', 'a').write('[defaults]\ndiff=--git\n') + self.test_basic()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_encoding.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,8 @@ +from tests import common +import hglib +from hglib.util import b + +class test_encoding(common.basetest): + def test_basic(self): + self.client = hglib.open(encoding='utf-8') + self.assertEquals(self.client.encoding, b('utf-8'))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_forget.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,14 @@ +from tests import common +from hglib.util import b + +class test_forget(common.basetest): + def test_basic(self): + self.append('a', 'a') + self.client.add([b('a')]) + self.assertTrue(self.client.forget(b('a'))) + + def test_warnings(self): + self.assertFalse(self.client.forget(b('a'))) + self.append('a', 'a') + self.client.add([b('a')]) + self.assertFalse(self.client.forget([b('a'), b('b')]))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_grep.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,64 @@ +from tests import common +from hglib.util import b + +class test_grep(common.basetest): + def test_basic(self): + self.append('a', 'x\n') + self.append('b', 'xy\n') + self.client.commit(b('first'), addremove=True) + + # no match + self.assertEquals(list(self.client.grep(b('c'))), []) + + if self.client.version >= (5, 2): + self.assertEquals(list(self.client.grep(b('x'))), + [(b('a'), b('x')), (b('b'), b('xy'))]) + self.assertEquals(list(self.client.grep(b('x'), b('a'))), + [(b('a'), b('x'))]) + + self.assertEquals(list(self.client.grep(b('y'))), + [(b('b'), b('xy'))]) + else: + self.assertEquals(list(self.client.grep(b('x'))), + [(b('a'), b('0'), b('x')), (b('b'), b('0'), b('xy'))]) + self.assertEquals(list(self.client.grep(b('x'), b('a'))), + [(b('a'), b('0'), b('x'))]) + self.assertEquals(list(self.client.grep(b('y'))), + [(b('b'), b('0'), b('xy'))]) + + def test_options(self): + self.append('a', 'x\n') + self.append('b', 'xy\n') + rev, node = self.client.commit(b('first'), addremove=True) + + self.assertEquals([(b('a'), b('0'), b('+'), b('x')), + (b('b'), b('0'), b('+'), b('xy'))], + list(self.client.grep(b('x'), all=True))) + + if self.client.version >= (5, 2): + self.assertEquals([(b('a'),), (b('b'),)], + list(self.client.grep(b('x'), fileswithmatches=True))) + + self.assertEquals([(b('a'), b('1'), b('x')), (b('b'), b('1'), b('xy'))], + list(self.client.grep(b('x'), line=True))) + + self.assertEquals([(b('a'), b('test'), b('x')), + (b('b'), b('test'), b('xy'))], + list(self.client.grep(b('x'), user=True))) + else: + self.assertEquals([(b('a'), b('0')), (b('b'), b('0'))], + list(self.client.grep(b('x'), fileswithmatches=True))) + + self.assertEquals([(b('a'), b('0'), b('1'), b('x')), + (b('b'), b('0'), b('1'), b('xy'))], + list(self.client.grep(b('x'), line=True))) + + self.assertEquals([(b('a'), b('0'), b('test'), b('x')), + (b('b'), b('0'), b('test'), b('xy'))], + list(self.client.grep(b('x'), user=True))) + + self.assertEquals([(b('a'), b('0'), b('1'), b('+'), b('test')), + (b('b'), b('0'), b('1'), b('+'), b('test'))], + list(self.client.grep(b('x'), all=True, user=True, + line=True, + fileswithmatches=True)))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_heads.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,17 @@ +from tests import common +from hglib.util import b + +class test_heads(common.basetest): + def test_empty(self): + self.assertEquals(self.client.heads(), []) + + def test_basic(self): + self.append('a', 'a') + rev, node0 = self.client.commit(b('first'), addremove=True) + self.assertEquals(self.client.heads(), [self.client.tip()]) + + self.client.branch(b('foo')) + self.append('a', 'a') + rev, node1 = self.client.commit(b('second')) + + self.assertEquals(self.client.heads(node0, topological=True), [])
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_hglib.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,25 @@ +from tests import common +import hglib + +class test_hglib(common.basetest): + def setUp(self): + pass + + def test_close_fds(self): + """A weird Python bug that has something to do to inherited file + descriptors, see http://bugs.python.org/issue12786 + """ + common.basetest.setUp(self) + client2 = hglib.open() + self.client.close() + + def test_open_nonexistent(self): + # setup stuff necessary for basetest.tearDown() + self.clients = [] + self._oldopen = hglib.client.hgclient.open + try: + self.clients.append(hglib.open('inexistent')) + # hg 3.5 can't report error (fixed by 7332bf4ae959) + #self.fail('ServerError not raised') + except hglib.error.ServerError as inst: + self.assertTrue('inexistent' in str(inst))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_hidden.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,74 @@ +from tests import common +import hglib, datetime +from hglib.error import CommandError +from hglib.util import b + +class test_obsolete_reference(common.basetest): + """make sure obsolete changesets are disabled""" + def test_debugobsolete_failure(self): + f = open('gna1','w') + f.write('g') + f.close() + self.client.add(b('gna1')) + cs = self.client.commit(b('gna1'))[1] #get id + self.assertRaises(CommandError, + self.client.rawcommand, [b('debugobsolete'), cs]) + + +class test_obsolete_baselib(common.basetest): + """base test class with obsolete changesets enabled""" + def setUp(self): + #create an extension which only activates obsolete + super(test_obsolete_baselib, self).setUp() + self.append('.hg/obs.py', + "import mercurial.obsolete\n" + "# 3.2 and later\n" + "mercurial.obsolete.isenabled = lambda r, opt: True\n" + "# Dropped in 5.1\n" + "mercurial.obsolete._enabled = True") + self.append('.hg/hgrc','\n[extensions]\nobs=.hg/obs.py') + +class test_obsolete_client(test_obsolete_baselib): + """check client methods with obsolete changesets enabled""" + def test_debugobsolete_success(self): + """check the obsolete extension is available""" + self.append('gna1','ga') + self.client.add(b('gna1')) + cs = self.client.commit(b('gna1'))[1] #get id + self.client.rawcommand([b('debugobsolete'), cs]) + + def test_obsolete_in(self): + """test the 'hidden' keyword with the 'in' method""" + if self.client.version < (2, 9, 0): + return + self.append('gna1','ga') + self.client.add(b('gna1')) + cs0 = self.client.commit(b('gna1'))[1] #get id + self.append('gna2','gaaa') + self.client.add(b('gna2')) + cs1 = self.client.commit(b('gna2'))[1] #get id + self.client.rawcommand([b('debugobsolete'), cs1]) + self.client.update(cs0) + self.assertFalse(cs1 in self.client) + self.assertTrue(cs0 in self.client) + self.client.hidden = True + self.assertTrue(cs1 in self.client) + +class test_hidden_context(test_obsolete_baselib): + """test the "hidden" context method with obsolete changesets enabled on + hidden and visible changesets""" + def test_hidden(self): + if self.client.version < (2, 9, 0): + return + self.append('gna1','ga') + self.client.add(b('gna1')) + cs0 = self.client.commit(b('gna1'))[1] #get id + ctx0 = self.client[cs0] + self.append('gna2','gaaa') + self.client.add(b('gna2')) + cs1 = self.client.commit(b('gna2'))[1] #get id + ctx1 = self.client[cs1] + self.client.rawcommand([b('debugobsolete'), cs1]) + self.client.update(cs0) + self.assertTrue(ctx1.hidden()) + self.assertFalse(ctx0.hidden())
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_import.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,38 @@ +import os +from tests import common +from hglib.util import b, BytesIO + +patch = b(""" +# HG changeset patch +# User test +# Date 0 0 +# Node ID c103a3dec114d882c98382d684d8af798d09d857 +# Parent 0000000000000000000000000000000000000000 +1 + +diff -r 000000000000 -r c103a3dec114 a +--- /dev/null Thu Jan 01 00:00:00 1970 +0000 ++++ b/a Thu Jan 01 00:00:00 1970 +0000 +@@ -0,0 +1,1 @@ ++1 +""") + +class test_import(common.basetest): + def test_basic_cstringio(self): + self.client.import_(BytesIO(patch)) + self.assertEquals(self.client.cat([b('a')]), b('1\n')) + + def test_basic_file(self): + f = open('patch', 'wb') + f.write(patch) + f.close() + + # --no-commit + self.client.import_([b('patch')], nocommit=True) + self.assertEquals(open('a').read(), '1\n') + + self.client.update(clean=True) + os.remove('a') + + self.client.import_([b('patch')]) + self.assertEquals(self.client.cat([b('a')]), b('1\n'))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_init.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,15 @@ +from tests import common +import hglib, shutil +from hglib.util import b + +class test_init(common.basetest): + def test_exists(self): + self.assertRaises(hglib.error.CommandError, hglib.init) + + def test_basic(self): + self.client.close() + self.client = None + shutil.rmtree('.hg') + + self.client = hglib.init().open() + self.assertTrue(self.client.root().endswith(b('test_init')))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_log.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,44 @@ +from tests import common +import hglib +from hglib.util import b + +class test_log(common.basetest): + def test_basic(self): + self.append('a', 'a') + rev0, node0 = self.client.commit(b('first'), addremove=True) + self.append('a', 'a') + rev1, node1 = self.client.commit(b('second')) + + revs = self.client.log() + revs.reverse() + + self.assertTrue(len(revs) == 2) + self.assertEquals(revs[1].node, node1) + + self.assertEquals(revs[0], self.client.log(b('0'))[0]) + self.assertEquals(self.client.log(), self.client.log(files=[b('a')])) + + self.assertEquals(self.client.log(), self.client.log(hidden=True)) + + def test_dash_in_filename(self): + self.append('-a', '-a') + self.client.commit(b('first'), addremove=True) + revs = self.client.log(files=[b('-a')]) + self.assertTrue(len(revs) == 1) + self.assertEquals(revs[0].rev, b('0')) + + def test_empty_short_option(self): + self.append('foobar', 'foobar') + self.client.commit(b('first'), addremove=True) + revs = self.client.log(keyword=b(''), files=[b('foobar')]) + self.assertTrue(len(revs) == 1) + self.assertEquals(revs[0].rev, b('0')) + + # def test_errors(self): + # self.assertRaisesRegexp(CommandError, 'abort: unknown revision', + # self.client.log, 'foo') + # self.append('a', 'a') + # self.client.commit('first', addremove=True) + # self.assertRaisesRegexp(CommandError, + # 'abort: unknown revision', + # self.client.log, 'bar')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_manifest.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,27 @@ +from tests import common +import hglib, os, stat +from hglib.util import b + +class test_manifest(common.basetest): + def test_basic(self): + self.append('a', 'a') + files = [b('a')] + manifest = [(b('047b75c6d7a3ef6a2243bd0e99f94f6ea6683597'), b('644'), + False, False, b('a'))] + + if os.name == 'posix': + self.append('b', 'b') + os.chmod('b', os.stat('b')[0] | stat.S_IEXEC) + os.symlink('b', 'c') + + files.extend([b('b'), b('c')]) + manifest.extend([(b('62452855512f5b81522aa3895892760bb8da9f3f'), + b('755'), True, False, b('b')), + (b('62452855512f5b81522aa3895892760bb8da9f3f'), + b('644'), False, True, b('c'))]) + + self.client.commit(b('first'), addremove=True) + + self.assertEquals(list(self.client.manifest(all=True)), files) + + self.assertEquals(list(self.client.manifest()), manifest)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_merge.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,78 @@ +from tests import common +import hglib +from hglib.util import b + +class test_merge(common.basetest): + def setUp(self): + common.basetest.setUp(self) + + self.append('a', 'a') + rev, self.node0 = self.client.commit(b('first'), addremove=True) + + self.append('a', 'a') + rev, self.node1 = self.client.commit(b('change')) + + def test_basic(self): + self.client.update(self.node0) + self.append('b', 'a') + rev, node2 = self.client.commit(b('new file'), addremove=True) + self.client.merge(self.node1) + rev, node = self.client.commit(b('merge')) + diff = b("diff -r ") + node2[:12] + b(" -r ") + node[:12] + b(""" a +--- a/a ++++ b/a +@@ -1,1 +1,1 @@ +-a +\ No newline at end of file ++aa +\ No newline at end of file +""") + + self.assertEquals(diff, self.client.diff(change=node, nodates=True)) + + def test_merge_prompt_abort(self): + self.client.update(self.node0) + self.client.remove(b('a')) + self.client.commit(b('remove')) + + self.assertRaises(hglib.error.CommandError, self.client.merge) + + def test_merge_prompt_noninteractive(self): + self.client.update(self.node0) + self.client.remove(b('a')) + rev, node = self.client.commit(b('remove')) + + if self.client.version >= (3, 7): + self.assertRaises(hglib.error.CommandError, + self.client.merge, + cb=hglib.merge.handlers.noninteractive) + else: + self.client.merge(cb=hglib.merge.handlers.noninteractive) + + diff = b("diff -r ") + node[:12] + b(""" a +--- /dev/null ++++ b/a +@@ -0,0 +1,1 @@ ++aa +\ No newline at end of file +""") + self.assertEquals(diff, self.client.diff(nodates=True)) + + def test_merge_prompt_cb(self): + self.client.update(self.node0) + self.client.remove(b('a')) + rev, node = self.client.commit(b('remove')) + + def cb(output): + return b('c') + + self.client.merge(cb=cb) + + diff = b("diff -r ") + node[:12] + b(""" a +--- /dev/null ++++ b/a +@@ -0,0 +1,1 @@ ++aa +\ No newline at end of file +""") + self.assertEquals(diff, self.client.diff(nodates=True))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_move.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,16 @@ +import os +from tests import common +from hglib.util import b + +class test_move(common.basetest): + def test_basic(self): + self.append('a', 'a') + self.client.add(b('a')) + self.assertTrue(self.client.move(b('a'), b('b'))) + + # hg returns 0 even if there were warnings + #def test_warnings(self): + # self.append('a', 'a') + # self.client.add('a') + # os.mkdir('c') + # self.assertFalse(self.client.move(['a', 'b'], 'c'))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_outgoing_incoming.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,53 @@ +from tests import common +import hglib +from hglib.util import b + +class test_outgoing_incoming(common.basetest): + def test_no_path(self): + self.assertRaises(hglib.error.CommandError, self.client.incoming) + + def test_empty(self): + self.client.clone(dest=b('other')) + self.other = hglib.open(b('other')) + + self.assertEquals(self.other.incoming(), []) + self.assertEquals(self.other.outgoing(), []) + + def test_basic(self): + self.append('a', 'a') + self.client.commit(b('first'), addremove=True) + self.append('a', 'a') + self.client.commit(b('second')) + + self.client.clone(dest=b('other')) + other = hglib.open(b('other')) + + self.assertEquals(self.client.log(), other.log()) + self.assertEquals(self.client.outgoing(path=b('other')), + other.incoming()) + + self.append('a', 'a') + rev, node = self.client.commit(b('third')) + out = self.client.outgoing(path=b('other')) + + self.assertEquals(len(out), 1) + self.assertEquals(out[0].node, node) + + self.assertEquals(out, other.incoming()) + + def test_bookmarks(self): + self.append('a', 'a') + self.client.commit(b('first'), addremove=True) + self.append('a', 'a') + self.client.commit(b('second')) + + self.client.clone(dest=b('other')) + other = hglib.open(b('other')) + + self.client.bookmark(b('bm1'), 1) + + self.assertEquals(other.incoming(bookmarks=True), + [(b('bm1'), self.client.tip().node[:12])]) + + self.assertEquals(self.client.outgoing(path=b('other'), bookmarks=True), + [(b('bm1'), self.client.tip().node[:12])])
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_parents.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,15 @@ +from tests import common +from hglib.util import b + +class test_parents(common.basetest): + def test_noparents(self): + self.assertEquals(self.client.parents(), None) + + def test_basic(self): + self.append('a', 'a') + rev, node = self.client.commit(b('first'), addremove=True) + self.assertEquals(node, self.client.parents()[0].node) + self.assertEquals(node, self.client.parents(file=b('a'))[0].node) + + def test_two_parents(self): + pass
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_paths.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,19 @@ +import os +from tests import common +import hglib +from hglib.util import b + +class test_paths(common.basetest): + def test_basic(self): + f = open('.hg/hgrc', 'a') + f.write('[paths]\nfoo = bar\n') + f.close() + + # hgrc isn't watched for changes yet, have to reopen + self.client = hglib.open() + paths = self.client.paths() + self.assertEquals(len(paths), 1) + self.assertEquals(paths[b('foo')], + os.path.abspath('bar').encode('latin-1')) + self.assertEquals(self.client.paths(b('foo')), + os.path.abspath('bar').encode('latin-1'))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_phase.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,47 @@ +from tests import common +import hglib +from hglib.util import b + +class test_phase(common.basetest): + """test the different ways to use the phase command""" + def test_phase(self): + """test getting data from a single changeset""" + self.append('a', 'a') + rev, node0 = self.client.commit(b('first'), addremove=True) + self.assertEqual([(0, b('draft'))], self.client.phase(node0)) + ctx = self.client[rev] + self.assertEqual(b('draft'), ctx.phase()) + + def test_phase_public(self): + """test phase change from draft to public""" + self.append('a', 'a') + rev, node0 = self.client.commit(b('first'), addremove=True) + self.client.phase(node0, public=True) + self.assertEqual([(0, b('public'))], self.client.phase(node0)) + ctx = self.client[rev] + self.assertEqual(b('public'), ctx.phase()) + + def test_phase_secret(self): + """test phase change from draft to secret""" + self.append('a', 'a') + rev, node0 = self.client.commit(b('first'), addremove=True) + self.assertRaises(hglib.error.CommandError, + self.client.phase, node0, secret=True) + self.client.phase(node0, secret=True, force=True) + self.assertEqual([(0, b('secret'))], self.client.phase(node0)) + ctx = self.client[rev] + self.assertEqual(b('secret'), ctx.phase()) + + + def test_phase_multiple(self): + """test phase changes and show the phases of the different changesets""" + self.append('a', 'a') + rev, node0 = self.client.commit(b('a'), addremove=True) + self.client.phase(node0, public=True) + self.append('b', 'b') + rev, node1 = self.client.commit(b('b'), addremove=True) + self.append('c', 'c') + rev, node2 = self.client.commit(b('c'), addremove=True) + self.client.phase(node2, secret=True, force=True) + self.assertEqual([(0, b('public')), (2, b('secret')), (1, b('draft'))], + self.client.phase([node0, node2, node1]))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_pull.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,31 @@ +from tests import common +import hglib +from hglib.util import b + +class test_pull(common.basetest): + def test_basic(self): + self.append('a', 'a') + self.client.commit(b('first'), addremove=True) + + self.client.clone(dest=b('other')) + other = hglib.open(b('other')) + + self.append('a', 'a') + self.client.commit(b('second')) + + self.assertTrue(other.pull()) + self.assertEquals(self.client.log(), other.log()) + + def test_unresolved(self): + self.append('a', 'a') + self.client.commit(b('first'), addremove=True) + + self.client.clone(dest=b('other')) + other = hglib.open(b('other')) + + self.append('a', 'a') + self.client.commit(b('second')) + + self.append('other/a', 'b') + self.assertFalse(other.pull(update=True)) + self.assertTrue((b('M'), b('a')) in other.status())
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_push.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,20 @@ +from tests import common +import hglib +from hglib.util import b + +class test_push(common.basetest): + def test_basic(self): + self.append('a', 'a') + self.client.commit(b('first'), addremove=True) + + self.client.clone(dest=b('other')) + other = hglib.open(b('other')) + + # broken in hg, doesn't return 1 if nothing to push + #self.assertFalse(self.client.push('other')) + + self.append('a', 'a') + self.client.commit(b('second')) + + self.assertTrue(self.client.push(b('other'))) + self.assertEquals(self.client.log(), other.log())
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_remove.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,13 @@ +from tests import common +from hglib.util import b + +class test_remove(common.basetest): + def test_basic(self): + self.append('a', 'a') + self.client.commit(b('first'), addremove=True) + self.assertTrue(self.client.remove([b('a')])) + + def test_warnings(self): + self.append('a', 'a') + self.client.commit(b('first'), addremove=True) + self.assertFalse(self.client.remove([b('a'), b('b')]))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_resolve.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,33 @@ +from tests import common +import hglib +from hglib.util import b + +class test_resolve(common.basetest): + def setUp(self): + common.basetest.setUp(self) + + self.append('a', 'a') + self.append('b', 'b') + rev, self.node0 = self.client.commit(b('first'), addremove=True) + + self.append('a', 'a') + self.append('b', 'b') + rev, self.node1 = self.client.commit(b('second')) + + def test_basic(self): + self.client.update(self.node0) + self.append('a', 'b') + self.append('b', 'a') + rev, self.node3 = self.client.commit(b('third')) + + self.assertRaises(hglib.error.CommandError, self.client.merge, + self.node1) + self.assertRaises(hglib.error.CommandError, + self.client.resolve, all=True) + + self.assertEquals([(b('U'), b('a')), (b('U'), b('b'))], + self.client.resolve(listfiles=True)) + + self.client.resolve(b('a'), mark=True) + self.assertEquals([(b('R'), b('a')), (b('U'), b('b'))], + self.client.resolve(listfiles=True))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_status.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,50 @@ +import os +from tests import common +from hglib.util import b + +class test_status(common.basetest): + def test_empty(self): + self.assertEquals(self.client.status(), []) + + def test_one_of_each(self): + self.append('.hgignore', 'ignored') + self.append('ignored', 'a') + self.append('clean', 'a') + self.append('modified', 'a') + self.append('removed', 'a') + self.append('missing', 'a') + self.client.commit(b('first'), addremove=True) + self.append('modified', 'a') + self.append('added', 'a') + self.client.add([b('added')]) + os.remove('missing') + self.client.remove([b('removed')]) + self.append('untracked') + + l = [(b('M'), b('modified')), + (b('A'), b('added')), + (b('R'), b('removed')), + (b('C'), b('.hgignore')), + (b('C'), b('clean')), + (b('!'), b('missing')), + (b('?'), b('untracked')), + (b('I'), b('ignored'))] + + st = self.client.status(all=True) + + for i in l: + self.assertTrue(i in st) + + def test_copy(self): + self.append('source', 'a') + self.client.commit(b('first'), addremove=True) + self.client.copy(b('source'), b('dest')) + l = [(b('A'), b('dest')), (b(' '), b('source'))] + self.assertEquals(self.client.status(copies=True), l) + + def test_copy_origin_space(self): + self.append('s ource', 'a') + self.client.commit(b('first'), addremove=True) + self.client.copy(b('s ource'), b('dest')) + l = [(b('A'), b('dest')), (b(' '), b('s ource'))] + self.assertEquals(self.client.status(copies=True), l)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_summary.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,135 @@ +import unittest +from tests import common +import hglib +from hglib.util import b + +class test_summary(common.basetest): + def test_empty(self): + d = {b('parent') : [(-1, b('000000000000'), b('tip'), None)], + b('branch') : b('default'), + b('commit') : True, + b('update') : 0} + + self.assertEquals(self.client.summary(), d) + + def test_basic(self): + self.append('a', 'a') + rev, node = self.client.commit(b('first'), addremove=True) + + d = {b('parent') : [(0, node[:12], b('tip'), b('first'))], + b('branch') : b('default'), + b('commit') : True, + b('update') : 0} + if self.client.version >= (3, 5): + d[b('phases')] = b('1 draft') + + self.assertEquals(self.client.summary(), d) + + def test_commit_dirty(self): + self.append('a', 'a') + rev, node = self.client.commit(b('first'), addremove=True) + self.append('a', 'a') + + d = {b('parent') : [(0, node[:12], b('tip'), b('first'))], + b('branch') : b('default'), + b('commit') : False, + b('update') : 0} + if self.client.version >= (3, 5): + d[b('phases')] = b('1 draft') + + self.assertEquals(self.client.summary(), d) + + def test_secret_commit_clean(self): + if self.client.version < (2, 1): + raise unittest.SkipTest('phase not supported') + self.append('a', 'a') + rev, node = self.client.commit(b('first'), addremove=True) + self.client.phase([b('%d') % rev], secret=True, force=True) + e = self.client.summary() + self.assertTrue(e[b('commit')]) + + def test_update(self): + self.append('a', 'a') + rev, node = self.client.commit(b('first'), addremove=True) + self.append('a', 'a') + self.client.commit(b('second')) + self.client.update(0) + + d = {b('parent') : [(0, node[:12], None, b('first'))], + b('branch') : b('default'), + b('commit') : True, + b('update') : 1} + if self.client.version >= (3, 5): + d[b('phases')] = b('2 draft') + + self.assertEquals(self.client.summary(), d) + + def test_remote(self): + self.append('a', 'a') + rev, node = self.client.commit(b('first'), addremove=True) + + self.client.clone(dest=b('other')) + other = hglib.open('other') + + d = {b('parent') : [(0, node[:12], b('tip'), b('first'))], + b('branch') : b('default'), + b('commit') : True, + b('update') : 0, + b('remote') : (0, 0, 0, 0)} + + self.assertEquals(other.summary(remote=True), d) + + self.append('a', 'a') + self.client.commit(b('second')) + + d[b('remote')] = (1, 0, 0, 0) + self.assertEquals(other.summary(remote=True), d) + + self.client.bookmark(b('bm')) + d[b('remote')] = (1, 1, 0, 0) + self.assertEquals(other.summary(remote=True), d) + + other.bookmark(b('bmother')) + d[b('remote')] = (1, 1, 0, 1) + if self.client.version < (2, 0, 0): + d[b('parent')] = [(0, node[:12], b('tip bmother'), b('first'))] + else: + d[b('bookmarks')] = b('*bmother') + self.assertEquals(other.summary(remote=True), d) + + self.append('other/a', 'a') + rev, node = other.commit(b('second in other')) + + d[b('remote')] = (1, 1, 1, 1) + if self.client.version < (2, 0, 0): + tags = b('tip bmother') + else: + tags = b('tip') + d[b('parent')] = [(1, node[:12], tags, b('second in other'))] + if self.client.version >= (3, 5): + d[b('phases')] = b('1 draft') + + self.assertEquals(other.summary(remote=True), d) + + def test_two_parents(self): + self.append('a', 'a') + rev0, node = self.client.commit(b('first'), addremove=True) + + self.append('a', 'a') + rev1, node1 = self.client.commit(b('second')) + + self.client.update(rev0) + self.append('b', 'a') + rev2, node2 = self.client.commit(b('third'), addremove=True) + + self.client.merge(rev1) + + d = {b('parent') : [(2, node2[:12], b('tip'), b('third')), + (1, node1[:12], None, b('second'))], + b('branch') : b('default'), + b('commit') : False, + b('update') : 0} + if self.client.version >= (3, 5): + d[b('phases')] = b('3 draft') + + self.assertEquals(self.client.summary(), d)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_tags.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,21 @@ +from tests import common +import hglib +from hglib.util import b + +class test_tags(common.basetest): + def test_basic(self): + self.append('a', 'a') + rev, node = self.client.commit(b('first'), addremove=True) + self.client.tag(b('my tag')) + self.client.tag(b('local tag'), rev=rev, local=True) + + # filecache that was introduced in 2.0 makes us see the local tag, for + # now we have to reconnect + if self.client.version < (2, 0, 0): + self.client = hglib.open() + + tags = self.client.tags() + self.assertEquals(tags, + [(b('tip'), 1, self.client.tip().node[:12], False), + (b('my tag'), 0, node[:12], False), + (b('local tag'), 0, node[:12], True)])
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_update.py Wed Mar 08 17:04:58 2023 +0100 @@ -0,0 +1,102 @@ +from tests import common +from hglib import error +from hglib.util import b, strtobytes + +class test_update(common.basetest): + def setUp(self): + common.basetest.setUp(self) + self.append('a', 'a') + self.rev0, self.node0 = self.client.commit(b('first'), addremove=True) + self.append('a', 'a') + self.rev1, self.node1 = self.client.commit(b('second')) + + def test_basic(self): + u, m, r, ur = self.client.update(self.rev0) + self.assertEquals(u, 1) + self.assertEquals(m, 0) + self.assertEquals(r, 0) + self.assertEquals(ur, 0) + + def test_unresolved(self): + self.client.update(self.rev0) + self.append('a', 'b') + u, m, r, ur = self.client.update() + self.assertEquals(u, 0) + self.assertEquals(m, 0) + self.assertEquals(r, 0) + self.assertEquals(ur, 1) + self.assertTrue((b('M'), b('a')) in self.client.status()) + + def test_merge(self): + self.append('a', '\n\n\n\nb') + rev2, node2 = self.client.commit(b('third')) + self.append('a', 'b') + self.client.commit(b('fourth')) + self.client.update(rev2) + old = open('a').read() + f = open('a', 'wb') + f.write(b('a') + old.encode('latin-1')) + f.close() + u, m, r, ur = self.client.update() + self.assertEquals(u, 0) + self.assertEquals(m, 1) + self.assertEquals(r, 0) + self.assertEquals(ur, 0) + self.assertEquals(self.client.status(), [(b('M'), b('a'))]) + + def test_tip(self): + self.client.update(self.rev0) + u, m, r, ur = self.client.update() + self.assertEquals(u, 1) + self.assertEquals(self.client.parents()[0].node, self.node1) + + self.client.update(self.rev0) + self.append('a', 'b') + rev2, node2 = self.client.commit(b('new head')) + self.client.update(self.rev0) + + self.client.update() + self.assertEquals(self.client.parents()[0].node, node2) + + def test_check_clean(self): + self.assertRaises(ValueError, self.client.update, clean=True, + check=True) + + def test_clean(self): + old = open('a').read() + self.append('a', 'b') + self.assertRaises(error.CommandError, self.client.update, check=True) + + u, m, r, ur = self.client.update(clean=True) + self.assertEquals(u, 1) + self.assertEquals(old, open('a').read()) + + def test_basic_plain(self): + f = open('.hg/hgrc', 'a') + f.write('[defaults]\nupdate=-v\n') + f.close() + self.test_basic() + + def disabled_largefiles(self): + # we don't run reposetup after a session has started, so this + # test is broken + import os + f = open('.hg/hgrc', 'a') + f.write('[extensions]\nlargefiles=\n') + f.close() + self.append('b', 'a') + try: + self.client.rawcommand([b('add'), b('b'), b('--large')]) + except error.CommandError: + return + + rev2, node2 = self.client.commit(b('third')) + # Go back to 0 + self.client.rawcommand([b('update'), strtobytes(self.rev0)], + # Keep the 'changed' version + prompt=lambda s, d: 'c\n') + u, m, r, ur = self.client.update(rev2, clean=True) + self.assertEquals(u, 2) + self.assertEquals(m, 0) + self.assertEquals(r, 0) + self.assertEquals(ur, 0)
--- a/tests/with_hg.py Wed Mar 09 15:08:11 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -import os -from nose.plugins import Plugin - -class WithHgPlugin(Plugin): - name = 'with-hg' - enabled = False - - def options(self, parser, env): - Plugin.options(self, parser, env) - parser.add_option('--with-hg', - action='store', - type='string', - metavar='HG', - dest='with_hg', - help='test using specified hg script.') - - def configure(self, options, conf): - Plugin.configure(self, options, conf) - if options.with_hg: - self.enabled = True - self.hgpath = os.path.realpath(options.with_hg) - - def begin(self): - import hglib - - p = hglib.util.popen([self.hgpath, 'version']) - p.communicate() - - if p.returncode: - raise ValueError("custom hg %r doesn't look like Mercurial" - % self.hgpath) - - hglib.HGPATH = self.hgpath