tests/test-demandimport.py
author Augie Fackler <augie@google.com>
Tue, 30 Jun 2015 19:19:17 -0400
changeset 25708 d3d32643c060
parent 23643 2205d00b6d2b
child 27535 0d0f4070f6d7
permissions -rw-r--r--
wireproto: correctly escape batched args and responses (issue4739) This issue appears to be as old as wireproto batching itself: I can reproduce the failure as far back as 08ef6b5f3715 trivially by rebasing the test changes in this patch, which was back in the 1.9 era. I didn't test before that change, because prior to that the testfile has a different name and I'm lazy. Note that the test thought it was checking this case, but it actually wasn't: it put a literal ; in the arg and response for its greet command, but the mangle/unmangle step defined in the test meant that instead of "Fo, =;o" going over the wire, "Gp-!><p" went instead, which doesn't contain any special characters (those being [.=;]) and thus not exercising the escaping. The test has been updated to use pre-unmangled special characters, so the request is now "Fo+<:o", which mangles to "Gp,=;p". I have confirmed that the test fails without the adjustment to the escaping rules in wireproto.py. No existing clients of RPC batching were depending on the old behavior in any way. The only *actual* users of batchable RPCs in core were: 1) largefiles, wherein it batches up many statlfile calls. It sends hexlified hashes over the wire and gets a 0, 1, or 2 back as a response. No risk of special characters. 2) setdiscovery, which was using heads() and known(), both of which communicate via hexlified nodes. Again, no risk of special characters. Since the escaping functionality has been completely broken since it was introduced, we know that it has no users. As such, we can change the escaping mechanism without having to worry about backwards compatibility issues. For the curious, this was detected by chance: it happens that the lz4-compressed text of a test file for remotefilelog compressed to something containing a ;, which then caused the failure when I moved remotefilelog to using batching for file content fetching.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     1
from mercurial import demandimport
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     2
demandimport.enable()
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     3
23643
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
     4
import os
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
     5
if os.name != 'nt':
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
     6
    try:
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
     7
        import distutils.msvc9compiler
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
     8
        print ('distutils.msvc9compiler needs to be an immediate '
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
     9
               'importerror on non-windows platforms')
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    10
        distutils.msvc9compiler
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    11
    except ImportError:
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    12
        pass
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    13
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    14
import re
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    15
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    16
rsub = re.sub
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    17
def f(obj):
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    18
    l = repr(obj)
4802
3a4310e8fe72 test-demandimport: match upper-case hexadecimal
Patrick Mezard <pmezard@gmail.com>
parents: 4631
diff changeset
    19
    l = rsub("0x[0-9a-fA-F]+", "0x?", l)
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    20
    l = rsub("from '.*'", "from '?'", l)
13083
c0290fc6b486 test-demandimport.py: PyPy support
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 12865
diff changeset
    21
    l = rsub("'<[a-z]*>'", "'<whatever>'", l)
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    22
    return l
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    23
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    24
import os
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    25
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    26
print "os =", f(os)
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    27
print "os.system =", f(os.system)
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    28
print "os =", f(os)
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    29
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    30
from mercurial import util
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    31
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    32
print "util =", f(util)
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    33
print "util.system =", f(util.system)
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    34
print "util =", f(util)
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    35
print "util.system =", f(util.system)
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    36
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    37
import re as fred
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    38
print "fred =", f(fred)
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    39
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    40
import sys as re
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    41
print "re =", f(re)
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    42
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    43
print "fred =", f(fred)
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    44
print "fred.sub =", f(fred.sub)
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    45
print "fred =", f(fred)
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    46
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    47
print "re =", f(re)
9174
705278e70457 Fix test-demandimport and test-trusted under Windows
James Abbatiello <abbeyj at gmail.com>
parents: 8449
diff changeset
    48
print "re.stderr =", f(re.stderr)
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    49
print "re =", f(re)
21025
54af51c18c4c demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable
Mads Kiilerich <madski@unity3d.com>
parents: 13083
diff changeset
    50
54af51c18c4c demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable
Mads Kiilerich <madski@unity3d.com>
parents: 13083
diff changeset
    51
demandimport.disable()
54af51c18c4c demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable
Mads Kiilerich <madski@unity3d.com>
parents: 13083
diff changeset
    52
os.environ['HGDEMANDIMPORT'] = 'disable'
54af51c18c4c demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable
Mads Kiilerich <madski@unity3d.com>
parents: 13083
diff changeset
    53
demandimport.enable()
54af51c18c4c demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable
Mads Kiilerich <madski@unity3d.com>
parents: 13083
diff changeset
    54
from mercurial import node
54af51c18c4c demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable
Mads Kiilerich <madski@unity3d.com>
parents: 13083
diff changeset
    55
print "node =", f(node)