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)

filedata_test.py 2.18 KB
Newer Older
1
import functools
2 3
import os
from nose.tools import *
4
import pytest
5 6 7 8 9

from tortoisehg.hgqt import filedata, thgrepo

import helpers

10
def setup_module():
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    global _tmpdir
    _tmpdir = helpers.mktmpdir(__name__)

    hg = helpers.HgClient(os.path.join(_tmpdir, 'status'))
    hg.init()
    hg.fwrite('.hg/hgrc', '[tortoisehg]\nmaxdiff = 1\n')  # 1kB

    hg.fwrite('text', 'foo\n')
    hg.fwrite('binary', '\0')
    hg.fwrite('text-over1kb', ('a' * 63 + '\n') * 16 + '\n')
    hg.commit('-Am', 'add')

    paths = ['text', 'binary', 'text-over1kb']
    for p in paths:
        hg.copy(p, p + '.copied')
    hg.commit('-m', 'copy')

    for p in paths:
        hg.rename(p, p + '.renamed')
    hg.commit('-m', 'rename')

32
def loaddata(reponame, rev, path, prev=None):
33 34 35
    # thgrepository extension is necessary because of repo.maxdiff
    repo = thgrepo.repository(path=os.path.join(_tmpdir, reponame))
    ctx = repo[rev]
36 37 38 39 40
    if prev is None:
        pctx = ctx.p1()
    else:
        pctx = repo[prev]
    fd = filedata.createFileData(ctx, pctx, path)
41 42 43 44
    fd.load()
    return fd


45 46 47 48 49 50 51 52
@pytest.mark.parametrize('get_fd, message', [
    (functools.partial(loaddata, 'status', rev, path + sfx), msg)
    for rev, sfx in [(0, ''), (1, '.copied'), (2, '.renamed')]
    for path, msg in [('binary', 'is binary'),
                      ('text-over1kb', 'is larger than')]
])
def test_error_added(get_fd, message):
    fd = get_fd()
53
    assert message in fd.error, (message, fd.error)
54 55 56 57 58 59
    # no data should be loaded
    assert_false(fd.contents)
    assert_false(fd.olddata)
    assert_false(fd.diff)

def check_flabel(fd, message):
60
    assert message in fd.flabel, (message, fd.flabel)
61

62 63 64 65 66 67 68 69 70
@pytest.mark.parametrize('get_fd, message', [
    (functools.partial(loaddata, 'status', rev, path + sfx), msg)
    for path in ['text', 'binary', 'text-over1kb']
    for rev, sfx, msg in [(0, '', 'added'),
                          (1, '.copied', 'copied from'),
                          (2, '.renamed', 'renamed from')]
])
def test_flabel_added(get_fd, message):
    check_flabel(get_fd(), message)
71 72 73 74

def test_flabel_far_rename():
    fd = loaddata('status', 2, 'text.copied', 0)
    check_flabel(fd, 'renamed from')  # source 'text' is removed at rev 2