tests/test-filelog.py
author Matt Harbison <matt_harbison@yahoo.com>
Fri, 31 Jan 2020 22:20:39 -0500
branchstable
changeset 44148 aab70b540d3d
parent 43076 2372284d9457
child 45849 c102b704edb5
permissions -rwxr-xr-x
resourceutil: account for the non-resource-like file hierarchy under py2exe After 9e367157a990, config files for py2exe were expected to be in C:\Program Files\Mercurial\mercurial\defaultrc because of the implied resource structure of 'mercurial.defaultrc.*.rc', relative to the executable. Accomodating this would require changes to the WIX and Inno scripts (and perhaps the script that generates the WIX script), as well as 3rd party bundlers like TortoiseHg. But these files aren't read as resources anyway- they fall back to the filesystem APIs. (If we really wanted to carry on the charade, the installer would have to also sprinkle various empty __init__.py files around.) Instead, this simply prunes the 'mercurial.' portion of the resource name when run with py2exe. (PyOxidizer uses the resources API, not the filesystem fallback, so it is unaffected.) Since this hack only affects the py2 Windows installers and is less risky, I think it's reasonable. We haven't needed to load any 3rd party resource up to this point, and would have to make packaging changes anyway to handle that. Differential Revision: https://phab.mercurial-scm.org/D8058
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11540
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/env python
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
     2
"""
26098
ce26928cbe41 spelling: behaviour -> behavior
timeless@mozdev.org
parents: 20684
diff changeset
     3
Tests the behavior of filelog w.r.t. data starting with '\1\n'
11540
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
     4
"""
28744
6537e14301ef py3: use print_function in test-filelog.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28743
diff changeset
     5
from __future__ import absolute_import, print_function
29205
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28805
diff changeset
     6
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28805
diff changeset
     7
from mercurial.node import (
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28805
diff changeset
     8
    hex,
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28805
diff changeset
     9
    nullid,
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28805
diff changeset
    10
)
28743
83373fc2b287 py3: use absolute_import in test-filelog.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 26098
diff changeset
    11
from mercurial import (
83373fc2b287 py3: use absolute_import in test-filelog.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 26098
diff changeset
    12
    hg,
28805
efc739551c17 test-filelog: alias ui as uimod
Yuya Nishihara <yuya@tcha.org>
parents: 28744
diff changeset
    13
    ui as uimod,
28743
83373fc2b287 py3: use absolute_import in test-filelog.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 26098
diff changeset
    14
)
11540
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    15
30564
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 29205
diff changeset
    16
myui = uimod.ui.load()
37977
f71c97d9b97b tests: port test-filelog.py to Python 3
Augie Fackler <augie@google.com>
parents: 30564
diff changeset
    17
repo = hg.repository(myui, path=b'.', create=True)
11540
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    18
37977
f71c97d9b97b tests: port test-filelog.py to Python 3
Augie Fackler <augie@google.com>
parents: 30564
diff changeset
    19
fl = repo.file(b'foobar')
11540
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    20
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37977
diff changeset
    21
11540
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    22
def addrev(text, renamed=False):
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    23
    if renamed:
17486
73e3e368bd42 spelling: doesn't/does not
timeless@mozdev.org
parents: 16498
diff changeset
    24
        # data doesn't matter. Just make sure filelog.renamed() returns True
37977
f71c97d9b97b tests: port test-filelog.py to Python 3
Augie Fackler <augie@google.com>
parents: 30564
diff changeset
    25
        meta = {b'copyrev': hex(nullid), b'copy': b'bar'}
11540
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    26
    else:
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    27
        meta = {}
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    28
15876
2de1244361aa tests: lock before creating transaction in test-filelog
Mads Kiilerich <mads@kiilerich.com>
parents: 11540
diff changeset
    29
    lock = t = None
11540
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    30
    try:
15876
2de1244361aa tests: lock before creating transaction in test-filelog
Mads Kiilerich <mads@kiilerich.com>
parents: 11540
diff changeset
    31
        lock = repo.lock()
37977
f71c97d9b97b tests: port test-filelog.py to Python 3
Augie Fackler <augie@google.com>
parents: 30564
diff changeset
    32
        t = repo.transaction(b'commit')
11540
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    33
        node = fl.add(text, meta, t, 0, nullid, nullid)
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    34
        return node
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    35
    finally:
15876
2de1244361aa tests: lock before creating transaction in test-filelog
Mads Kiilerich <mads@kiilerich.com>
parents: 11540
diff changeset
    36
        if t:
2de1244361aa tests: lock before creating transaction in test-filelog
Mads Kiilerich <mads@kiilerich.com>
parents: 11540
diff changeset
    37
            t.close()
2de1244361aa tests: lock before creating transaction in test-filelog
Mads Kiilerich <mads@kiilerich.com>
parents: 11540
diff changeset
    38
        if lock:
2de1244361aa tests: lock before creating transaction in test-filelog
Mads Kiilerich <mads@kiilerich.com>
parents: 11540
diff changeset
    39
            lock.release()
11540
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    40
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37977
diff changeset
    41
11540
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    42
def error(text):
28744
6537e14301ef py3: use print_function in test-filelog.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28743
diff changeset
    43
    print('ERROR: ' + text)
11540
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    44
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37977
diff changeset
    45
37977
f71c97d9b97b tests: port test-filelog.py to Python 3
Augie Fackler <augie@google.com>
parents: 30564
diff changeset
    46
textwith = b'\1\nfoo'
f71c97d9b97b tests: port test-filelog.py to Python 3
Augie Fackler <augie@google.com>
parents: 30564
diff changeset
    47
without = b'foo'
11540
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    48
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    49
node = addrev(textwith)
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    50
if not textwith == fl.read(node):
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    51
    error('filelog.read for data starting with \\1\\n')
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    52
if fl.cmp(node, textwith) or not fl.cmp(node, without):
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    53
    error('filelog.cmp for data starting with \\1\\n')
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    54
if fl.size(0) != len(textwith):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37977
diff changeset
    55
    error(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37977
diff changeset
    56
        'FIXME: This is a known failure of filelog.size for data starting '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37977
diff changeset
    57
        'with \\1\\n'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37977
diff changeset
    58
    )
11540
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    59
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    60
node = addrev(textwith, renamed=True)
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    61
if not textwith == fl.read(node):
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    62
    error('filelog.read for a renaming + data starting with \\1\\n')
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    63
if fl.cmp(node, textwith) or not fl.cmp(node, without):
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    64
    error('filelog.cmp for a renaming + data starting with \\1\\n')
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    65
if fl.size(1) != len(textwith):
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    66
    error('filelog.size for a renaming + data starting with \\1\\n')
2370e270a29a filelog: test behaviour for data starting with "\1\n"
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff changeset
    67
28744
6537e14301ef py3: use print_function in test-filelog.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28743
diff changeset
    68
print('OK.')