tests/test-symlink-os-yes-fs-no.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Fri, 26 Mar 2021 18:37:25 +0100
branchstable
changeset 46802 112826b59476
parent 43076 2372284d9457
child 48875 6000f5b25c9b
permissions -rw-r--r--
re2: feed unicode string to re2 module when necessary My previous test were using the `pyre2` Python project, that wrap the Google RE2 library in python as a `re2` module and accept bytes as input. However the `fb-re2` Python project is also offering a wrapping of the Google RE2 library in python as a `re2` module ans accept only unicode on python3. So we detect this situation and convert thing to unicode when necessary. Hooray… We should consider using a rust wrapping for regexp handling. We needs regexps in Rust anyway and this give use more control with less variants and more sanity. Differential Revision: https://phab.mercurial-scm.org/D10284
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28916
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     1
from __future__ import absolute_import
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     2
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     3
import os
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     4
import sys
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     5
import time
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     6
from mercurial import (
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     7
    commands,
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     8
    hg,
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
     9
    pycompat,
28916
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
    10
    ui as uimod,
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
    11
    util,
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
    12
)
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    13
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    14
TESTDIR = os.environ["TESTDIR"]
14116
cd3032437064 tests: move test bundles in a bundles/ subdirectory
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11769
diff changeset
    15
BUNDLEPATH = os.path.join(TESTDIR, 'bundles', 'test-no-symlinks.hg')
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    16
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    17
# only makes sense to test on os which supports symlinks
14971
0b21ae0a2366 tests: use getattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents: 14553
diff changeset
    18
if not getattr(os, "symlink", False):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37935
diff changeset
    19
    sys.exit(80)  # SKIPPED_STATUS defined in run-tests.py
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    20
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 30448
diff changeset
    21
u = uimod.ui.load()
17015
73d20de5f30b tests: add missing no-outer-repo requirements
Mads Kiilerich <mads@kiilerich.com>
parents: 14971
diff changeset
    22
# hide outer repo
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    23
hg.peer(u, {}, b'.', create=True)
17015
73d20de5f30b tests: add missing no-outer-repo requirements
Mads Kiilerich <mads@kiilerich.com>
parents: 14971
diff changeset
    24
37431
5ac84b20f184 tests: use unbundle in test-symlink-os-yes-fs-no.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30559
diff changeset
    25
# unbundle with symlink support
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    26
hg.peer(u, {}, b'test0', create=True)
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    27
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    28
repo = hg.repository(u, b'test0')
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    29
commands.unbundle(u, repo, pycompat.fsencode(BUNDLEPATH), update=True)
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    30
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    31
# wait a bit, or the status call wont update the dirstate
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    32
time.sleep(1)
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    33
commands.status(u, repo)
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    34
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    35
# now disable symlink support -- this is what os.symlink would do on a
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    36
# non-symlink file system
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    37
def symlink_failure(src, dst):
18178
6ae45c0b4625 test-symlink-os-yes-fs-no.py: clean up use of two-argument raise
Augie Fackler <raf@durin42.com>
parents: 17015
diff changeset
    38
    raise OSError(1, "Operation not permitted")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37935
diff changeset
    39
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37935
diff changeset
    40
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    41
os.symlink = symlink_failure
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37935
diff changeset
    42
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37935
diff changeset
    43
30448
8836f13e3c5b posix: give checklink a fast path that cache the check file and is read only
Mads Kiilerich <madski@unity3d.com>
parents: 28916
diff changeset
    44
def islink_failure(path):
8836f13e3c5b posix: give checklink a fast path that cache the check file and is read only
Mads Kiilerich <madski@unity3d.com>
parents: 28916
diff changeset
    45
    return False
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37935
diff changeset
    46
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37935
diff changeset
    47
30448
8836f13e3c5b posix: give checklink a fast path that cache the check file and is read only
Mads Kiilerich <madski@unity3d.com>
parents: 28916
diff changeset
    48
os.path.islink = islink_failure
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    49
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    50
# dereference links as if a Samba server has exported this to a
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    51
# Windows client
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    52
for f in b'test0/a.lnk', b'test0/d/b.lnk':
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    53
    os.unlink(f)
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    54
    fp = open(f, 'wb')
14168
135e244776f0 prevent transient leaks of file handle by using new helper functions
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 14116
diff changeset
    55
    fp.write(util.readfile(f[:-4]))
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    56
    fp.close()
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    57
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    58
# reload repository
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 30448
diff changeset
    59
u = uimod.ui.load()
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    60
repo = hg.repository(u, b'test0')
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    61
commands.status(u, repo)
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    62
37431
5ac84b20f184 tests: use unbundle in test-symlink-os-yes-fs-no.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30559
diff changeset
    63
# try unbundling a repo which contains symlinks
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 30448
diff changeset
    64
u = uimod.ui.load()
37431
5ac84b20f184 tests: use unbundle in test-symlink-os-yes-fs-no.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30559
diff changeset
    65
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    66
repo = hg.repository(u, b'test1', create=True)
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    67
commands.unbundle(u, repo, pycompat.fsencode(BUNDLEPATH), update=True)