File: test_py_imports.py

package info (click to toggle)
python-py 1.11.0-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,512 kB
  • sloc: python: 11,660; makefile: 119; sh: 7
file content (71 lines) | stat: -rw-r--r-- 1,977 bytes parent folder | download | duplicates (43)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import py
import sys


@py.test.mark.parametrize('name', [x for x in dir(py) if x[0] != '_'])
def test_dir(name):
    obj = getattr(py, name)
    if hasattr(obj, '__map__'):  # isinstance(obj, Module):
        keys = dir(obj)
        assert len(keys) > 0
        print (obj.__map__)
        for name in list(obj.__map__):
            assert hasattr(obj, name), (obj, name)


def test_virtual_module_identity():
    from py import path as path1
    from py import path as path2
    assert path1 is path2
    from py.path import local as local1
    from py.path import local as local2
    assert local1 is local2


def test_importall():
    base = py._pydir
    nodirs = [
    ]
    if sys.version_info >= (3, 0):
        nodirs.append(base.join('_code', '_assertionold.py'))
    else:
        nodirs.append(base.join('_code', '_assertionnew.py'))

    def recurse(p):
        return p.check(dotfile=0) and p.basename != "attic"

    for p in base.visit('*.py', recurse):
        if p.basename == '__init__.py':
            continue
        relpath = p.new(ext='').relto(base)
        if base.sep in relpath:  # not py/*.py itself
            for x in nodirs:
                if p == x or p.relto(x):
                    break
            else:
                relpath = relpath.replace(base.sep, '.')
                modpath = 'py.%s' % relpath
                try:
                    check_import(modpath)
                except py.test.skip.Exception:
                    pass


def check_import(modpath):
    py.builtin.print_("checking import", modpath)
    assert __import__(modpath)


def test_star_import():
    exec("from py import *")


def test_all_resolves():
    seen = py.builtin.set([py])
    lastlength = None
    while len(seen) != lastlength:
        lastlength = len(seen)
        for item in py.builtin.frozenset(seen):
            for value in item.__dict__.values():
                if isinstance(value, type(py.test)):
                    seen.add(value)