tests/test-demandimport.py
author Augie Fackler <raf@durin42.com>
Mon, 22 Dec 2014 17:27:31 -0500
branchstable
changeset 23643 2205d00b6d2b
parent 21025 54af51c18c4c
child 27535 0d0f4070f6d7
permissions -rw-r--r--
demandimport: blacklist distutils.msvc9compiler (issue4475) This module depends on _winreg, which is windows-only. Recent versions of setuptools load distutils.msvc9compiler and expect it to ImportError immediately when on non-Windows platforms, so we need to let them do that. This breaks in an especially mystifying way, because setuptools uses vars() on the imported module. We then throw an exception, which vars doesn't pick up on well. For example: In [3]: class wat(object): ...: @property ...: def __dict__(self): ...: assert False ...: In [4]: vars(wat()) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-4-2781ada5ffe6> in <module>() ----> 1 vars(wat()) TypeError: vars() argument must have __dict__ attribute Which is similar to the problem we run into.
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)