This instance will be upgraded to Heptapod 0.21.0rc2 on 2021-04-16 at 11:00 UTC+2 (a few minutes of down time)

hglib_repo_test.py 1.68 KB
Newer Older
1 2 3 4
"""Test for repository helper functions in hglib"""

import os
from nose.tools import *
5
import pytest
6

7
from mercurial import hg
8 9 10 11
from tortoisehg.util import hglib

import helpers

12
def setup_module():
13 14 15 16 17 18 19 20
    global _tmpdir
    _tmpdir = helpers.mktmpdir(__name__)

    hg = helpers.HgClient(os.path.join(_tmpdir, 'empty'))
    hg.init()
    setup_repoid()

def openrepo(name):
21
    return hg.repository(hglib.loadui(), os.path.join(_tmpdir, name))
22 23 24 25 26 27 28 29 30 31 32 33


_repoidnodes = [
    '093f0fe4b6a9db9ad3537827ddb92c4dcf1406f9',
    '121d24cace2c5ed7211158e5eb4ad8ac4691f505',
    '0000000000000000000000000000000000000000',  # -1
    ]

def setup_repoid():
    for name in ['repoid-trivial', 'repoid-allhidden', 'repoid-rev0hidden']:
        hg = helpers.HgClient(os.path.join(_tmpdir, name))
        hg.init()
34 35
        # to use "hg debugobsolete" and suppress "obsolete feature not enabled"
        hg.fappend('.hg/hgrc', '[experimental]\nevolution.createmarkers = 1\n')
36 37 38 39 40 41 42 43 44 45 46 47
        hg.ftouch('foo')
        hg.commit('-Am0')
        hg.update('null')
        hg.ftouch('bar')
        hg.commit('-Am1')
        hg.update('null')
    hg = helpers.HgClient(os.path.join(_tmpdir, 'repoid-allhidden'))
    for n in _repoidnodes:
        hg.debugobsolete(n)
    hg = helpers.HgClient(os.path.join(_tmpdir, 'repoid-rev0hidden'))
    hg.debugobsolete(_repoidnodes[0])

48 49 50 51 52 53 54
@pytest.mark.parametrize('reponame, rootrev', [
    ('empty', -1),
    ('repoid-trivial', 0),
    ('repoid-allhidden', -1),
    ('repoid-rev0hidden', 1)
])
def test_repoid(reponame, rootrev):
55 56 57 58
    repo = openrepo(reponame)
    nodehex = _repoidnodes[rootrev]
    assert_equal(nodehex[:12], hglib.shortrepoid(repo))
    assert_equal(nodehex.decode('hex'), hglib.repoidnode(repo))