本文整理汇总了Python中pymetabiosis.module.import_module函数的典型用法代码示例。如果您正苦于以下问题:Python import_module函数的具体用法?Python import_module怎么用?Python import_module使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了import_module函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_convert_return_value
def test_convert_return_value():
builtin = import_module("__builtin__")
operator = import_module("operator")
assert builtin.int(32) == 32
assert builtin.float(3.123) == 3.123
for s in ['a string']: # TODO 'a string \00yep']:
assert builtin.str(s) == s
u = u"some буквы are странные"
assert builtin.unicode(u) == u
t = (1, (2.3,))
assert builtin.tuple(t) == t
d = {'a': 'b', 1: 2}
assert builtin.dict(d) == d
lst = ['a', 1, [2]]
assert builtin.list(lst) == lst
assert builtin.bool(True) is True
assert builtin.bool(False) is False
assert builtin.bool(None) is False
assert operator.eq(None, None) is True
assert operator.eq(None, False) is False
开发者ID:jaidevd,项目名称:pymetabiosis,代码行数:28,代码来源:test_wrapper.py
示例2: test_no_convert
def test_no_convert():
operator = import_module("operator")
functools = import_module("functools")
builtin = import_module("__builtin__", noconvert=True)
lst = builtin.list()
part = functools.partial(operator.iadd, lst)
part([1, 2, 3])
assert pypy_convert(lst.obj) == [1, 2, 3]
开发者ID:jaidevd,项目名称:pymetabiosis,代码行数:11,代码来源:test_wrapper.py
示例3: test_callbacks_on_wrappers
def test_callbacks_on_wrappers():
builtin = import_module("__builtin__", noconvert=True)
p1, p2, p3, p4 = points = [
Point(0, 0),
Point(0, 1),
Point(1, 2),
Point(3, 4)]
lst = builtin.list([p3, p2, p1, p4])
lst.sort(key=lambda x: x.norm())
assert _pypy_convert_list(lst) == points
# method callbacks
class Norm(object):
def __init__(self, n):
self.n = n
def norm(self, point):
return math.pow(point.norm()**2, 1.0 / self.n)
norm = Norm(2)
lst.reverse()
lst.sort(key=norm.norm)
assert _pypy_convert_list(lst) == points
# dict.get as a callback
d = dict((p, p.norm()) for p in points)
lst.reverse()
lst.sort(key=d.get)
开发者ID:jaidevd,项目名称:pymetabiosis,代码行数:26,代码来源:test_wrapper.py
示例4: test_slice
def test_slice():
builtin = import_module("__builtin__", noconvert=True)
lst = builtin.list(list(xrange(10)))
assert _pypy_convert_list(lst) == list(xrange(10))
assert _pypy_convert_list(lst[-1:]) == [9]
assert _pypy_convert_list(lst[:2]) == [0, 1]
assert _pypy_convert_list(lst[-9:3]) == [1, 2]
开发者ID:michael-karotsieris,项目名称:pymetabiosis,代码行数:7,代码来源:test_wrapper.py
示例5: test_opaque_objects
def test_opaque_objects():
builtin = import_module("__builtin__")
builtin_noconvert = import_module("__builtin__", noconvert=True)
p1, p2 = Point(1.0, 2.0), Point(3.0, -1.0)
d = DictSubclass()
lst = builtin.list([p1, p2, d])
assert lst == [p1, p2, d]
lst_cpy = builtin_noconvert.list([p1, p2, d])
assert pypy_convert(lst_cpy[0].obj) == p1
assert pypy_convert(lst_cpy[1].obj) == p2
assert pypy_convert(lst_cpy[2].obj) == d
lst_cpy.reverse()
assert pypy_convert(lst_cpy[0].obj) == d
assert pypy_convert(lst_cpy[1].obj) == p2
assert pypy_convert(lst_cpy[2].obj) == p1
开发者ID:jaidevd,项目名称:pymetabiosis,代码行数:17,代码来源:test_wrapper.py
示例6: test_exceptions
def test_exceptions():
builtin = import_module("__builtin__")
with pytest.raises(AttributeError):
builtin.foo
with pytest.raises(ValueError): # TODO UnicodeDecodeError
builtin.unicode('\124\323')
开发者ID:jaidevd,项目名称:pymetabiosis,代码行数:8,代码来源:test_wrapper.py
示例7: test_len
def test_len():
builtin = import_module("__builtin__", noconvert=True)
lst = builtin.list([1, 'a'])
assert len(lst) == 2
assert len(builtin.list()) == 0
assert len(builtin.str('abc')) == 3
with pytest.raises(TypeError):
len(builtin.iter([1]))
开发者ID:jaidevd,项目名称:pymetabiosis,代码行数:9,代码来源:test_wrapper.py
示例8: test_str_repr_dir
def test_str_repr_dir():
builtin = import_module("__builtin__", noconvert=True)
assert str(builtin.None) == 'None'
assert str(builtin.str('a')) == 'a'
assert repr(builtin.str('a')) == "'a'"
assert set(['rjust', 'rpartition', 'rstrip', '__le__'])\
.issubset(dir(builtin.str('a')))
开发者ID:jaidevd,项目名称:pymetabiosis,代码行数:9,代码来源:test_wrapper.py
示例9: register_cpy_numpy_to_pypy_builtin_converters
def register_cpy_numpy_to_pypy_builtin_converters():
''' Converts numpy types to builtin python types on PyPy side
'''
numpy = import_module("numpy")
builtin = import_module("__builtin__", noconvert=True)
def call_direct(f):
f = MetabiosisWrapper(f.obj, noconvert=False)
return lambda x: f._call((x,), args_kwargs_converted=True)
cpy_to_pypy_converters.update({
numpy.bool_.obj: call_direct(builtin.bool),
numpy.int8.obj: call_direct(builtin.int),
numpy.int16.obj: call_direct(builtin.int),
numpy.int32.obj: call_direct(builtin.int),
numpy.int64.obj: call_direct(builtin.int),
numpy.float16.obj: call_direct(builtin.float),
numpy.float32.obj: call_direct(builtin.float),
numpy.float64.obj: call_direct(builtin.float),
})
if hasattr(numpy, "float128"):
cpy_to_pypy_converters.update({numpy.float128.obj: call_direct(builtin.float)})
开发者ID:jaidevd,项目名称:pymetabiosis,代码行数:22,代码来源:numpy_convert.py
示例10: test_callbacks_exceptions
def test_callbacks_exceptions():
builtin = import_module("__builtin__")
d = {1: 2}
fn = lambda x: d[x]
assert builtin.apply(fn, (1,)) == 2
# exception in callback
with pytest.raises(KeyError):
builtin.apply(fn, (2,))
# exception in converting result
try:
builtin.apply(lambda : object())
except SystemError:
assert False
except Exception:
pass
开发者ID:jaidevd,项目名称:pymetabiosis,代码行数:15,代码来源:test_wrapper.py
示例11: test_sqlite
def test_sqlite():
# Taken from Python 2.7's sqlite doc
sqlite3 = import_module("sqlite3")
con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("create table people (name_last, age)")
who = "Yeltsin"
age = 72
cur.execute("insert into people values (?, ?)", (who, age))
cur.execute("select * from people where name_last=:who and age=:age", {"who": who, "age": age})
ret = cur.fetchone()
assert ret == (u'Yeltsin', 72)
开发者ID:jaidevd,项目名称:pymetabiosis,代码行数:17,代码来源:test_wrapper.py
示例12: test_scalar_converter
def test_scalar_converter():
try:
numpy = import_module("numpy")
except ImportError:
pytest.skip("numpy isn't installed on the cpython side")
assert numpy.bool_(True) is True
assert numpy.bool_(False) is False
assert numpy.int8(10) == 10
assert numpy.int16(-10) == -10
assert numpy.int32(int(2**31-1)).__int__() == int(2**31-1)
assert numpy.int64(42) == 42
assert numpy.float16(10.0) == 10.0
assert numpy.float32(-10) == -10.0
assert numpy.float64(42.0) == 42.0
if hasattr(numpy, "float128"):
assert numpy.float128(-42.0) == -42.0
开发者ID:aaiyer,项目名称:pymetabiosis,代码行数:19,代码来源:test_numpy_convert.py
示例13: test_getitem_setitem_delitem
def test_getitem_setitem_delitem():
builtin = import_module("__builtin__", noconvert=True)
d = builtin.dict({1: 'foo', (1, 'a'): 'zoo'})
with pytest.raises(KeyError):
d[2]
assert pypy_convert(d[1].obj) == 'foo'
assert pypy_convert(d[(1, 'a')].obj) == 'zoo'
key, lst = (1, 2), ['a', 'b']
d[key] = lst
assert pypy_convert(d[key].obj) == lst
with pytest.raises(TypeError):
d[[1, 2]] = 0
del d[1]
with pytest.raises(KeyError):
d[1]
with pytest.raises(KeyError):
del d[2]
开发者ID:jaidevd,项目名称:pymetabiosis,代码行数:22,代码来源:test_wrapper.py
示例14: test_getattr_on_module
def test_getattr_on_module():
sqlite = import_module("sqlite3")
assert isinstance(sqlite, MetabiosisWrapper)
connect = sqlite.connect
assert isinstance(connect, MetabiosisWrapper)
assert repr(connect).startswith("<built-in function connect>")
开发者ID:jaidevd,项目名称:pymetabiosis,代码行数:6,代码来源:test_wrapper.py
示例15: test_setattr_on_module
def test_setattr_on_module():
this = import_module("this")
assert isinstance(this, MetabiosisWrapper)
this.a = 42
assert this.a == 42
开发者ID:aaiyer,项目名称:pymetabiosis,代码行数:5,代码来源:test_wrapper.py
示例16: test_gettype
def test_gettype():
sqlite3 = import_module("sqlite3")
assert repr(sqlite3.get_type()) == "<type 'module'>"
开发者ID:jaidevd,项目名称:pymetabiosis,代码行数:4,代码来源:test_wrapper.py
示例17: test_import_error
def test_import_error():
with pytest.raises(ImportError):
import_module('thereisnosuchmodule4sure')
开发者ID:aaiyer,项目名称:pymetabiosis,代码行数:3,代码来源:test_module.py
示例18: test_getattr_convert
def test_getattr_convert():
builtin = import_module("__builtin__", noconvert=True)
s = builtin.slice(10, 11)
s.noconvert = False
assert s.start == 10
开发者ID:jaidevd,项目名称:pymetabiosis,代码行数:5,代码来源:test_wrapper.py
示例19: test_setattr_on_module
def test_setattr_on_module():
pickle = import_module("pickle")
assert isinstance(pickle, MetabiosisWrapper)
pickle.a = 42
assert pickle.a == 42
开发者ID:michael-karotsieris,项目名称:pymetabiosis,代码行数:5,代码来源:test_wrapper.py
示例20: test_callbacks_simple
def test_callbacks_simple():
builtin = import_module("__builtin__", noconvert=True)
lst = builtin.list([1, 2, 3, 4, 5, 6])
lst.sort(key=lambda x: x % 3)
assert _pypy_convert_list(lst) == [3, 6, 1, 4, 2, 5]
开发者ID:jaidevd,项目名称:pymetabiosis,代码行数:5,代码来源:test_wrapper.py
注:本文中的pymetabiosis.module.import_module函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论