tests/test-demandimport.py
author timeless <timeless@mozdev.org>
Wed, 21 Sep 2016 03:39:37 +0000
changeset 29981 129e38a76f2c
parent 29868 4b50e1f922a0
child 30022 26a4e46af2bc
permissions -rw-r--r--
tests: clarify demandimport disabled state
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28948
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
     1
from __future__ import print_function
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
     2
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     3
from mercurial import demandimport
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     4
demandimport.enable()
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     5
23643
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
     6
import os
29868
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
     7
import subprocess
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
     8
import sys
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
     9
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
    10
# Only run if demandimport is allowed
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
    11
if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'],
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
    12
                    'demandimport']):
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
    13
    sys.exit(80)
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
    14
23643
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    15
if os.name != 'nt':
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    16
    try:
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    17
        import distutils.msvc9compiler
28948
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    18
        print('distutils.msvc9compiler needs to be an immediate '
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    19
              'importerror on non-windows platforms')
23643
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    20
        distutils.msvc9compiler
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    21
    except ImportError:
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    22
        pass
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    23
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    24
import re
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
rsub = re.sub
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    27
def f(obj):
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    28
    l = repr(obj)
4802
3a4310e8fe72 test-demandimport: match upper-case hexadecimal
Patrick Mezard <pmezard@gmail.com>
parents: 4631
diff changeset
    29
    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
    30
    l = rsub("from '.*'", "from '?'", l)
13083
c0290fc6b486 test-demandimport.py: PyPy support
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 12865
diff changeset
    31
    l = rsub("'<[a-z]*>'", "'<whatever>'", l)
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    32
    return l
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    33
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    34
import os
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    35
28948
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    36
print("os =", f(os))
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    37
print("os.system =", f(os.system))
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    38
print("os =", f(os))
4631
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
from mercurial import util
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    41
28948
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    42
print("util =", f(util))
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    43
print("util.system =", f(util.system))
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    44
print("util =", f(util))
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    45
print("util.system =", f(util.system))
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    46
27535
0d0f4070f6d7 test-demandimport: ensure that relative imports are deferred
Bryan O'Sullivan <bos@serpentine.com>
parents: 23643
diff changeset
    47
from mercurial import hgweb
28948
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    48
print("hgweb =", f(hgweb))
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    49
print("hgweb_mod =", f(hgweb.hgweb_mod))
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    50
print("hgweb =", f(hgweb))
27535
0d0f4070f6d7 test-demandimport: ensure that relative imports are deferred
Bryan O'Sullivan <bos@serpentine.com>
parents: 23643
diff changeset
    51
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    52
import re as fred
28948
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    53
print("fred =", f(fred))
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    54
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    55
import sys as re
28948
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    56
print("re =", f(re))
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    57
28948
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    58
print("fred =", f(fred))
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    59
print("fred.sub =", f(fred.sub))
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    60
print("fred =", f(fred))
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    61
28948
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    62
print("re =", f(re))
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    63
print("re.stderr =", f(re.stderr))
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    64
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
    65
54af51c18c4c demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable
Mads Kiilerich <madski@unity3d.com>
parents: 13083
diff changeset
    66
demandimport.disable()
54af51c18c4c demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable
Mads Kiilerich <madski@unity3d.com>
parents: 13083
diff changeset
    67
os.environ['HGDEMANDIMPORT'] = 'disable'
29981
129e38a76f2c tests: clarify demandimport disabled state
timeless <timeless@mozdev.org>
parents: 29868
diff changeset
    68
# this enable call should not actually enable demandimport!
21025
54af51c18c4c demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable
Mads Kiilerich <madski@unity3d.com>
parents: 13083
diff changeset
    69
demandimport.enable()
54af51c18c4c demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable
Mads Kiilerich <madski@unity3d.com>
parents: 13083
diff changeset
    70
from mercurial import node
28948
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    71
print("node =", f(node))