本文整理汇总了Python中metapensiero.pj.api.eval_object函数的典型用法代码示例。如果您正苦于以下问题:Python eval_object函数的具体用法?Python eval_object怎么用?Python eval_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了eval_object函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_list_in
def test_list_in():
def list_in():
return [
1 in [10, 11],
'foo' in 'barfoobar',
11 in [10, 11]
]
assert list_in() == eval_object(list_in, 'list_in();')
expected = (
'var _pj;\n'
'function _pj_snippets(container) {\n'
' function _in(left, right) {\n'
' if (((right instanceof Array) || ((typeof right) === "string"))) {\n'
' return (right.indexOf(left) > (- 1));\n'
' } else {\n'
' return (left in right);\n'
' }\n'
' }\n'
' container["_in"] = _in;\n'
' return container;\n'
'}\n'
'_pj = {};\n'
'_pj_snippets(_pj);\n'
'function list_in() {\n'
' return [_pj._in(1, [10, 11]), _pj._in("foo", "barfoobar"), _pj._in(11, '
'[10, 11])];\n'
'}\n'
)
assert translate_object(list_in)[0] == expected
示例2: test_multiple_assignment_and_sum
def test_multiple_assignment_and_sum():
def sum():
x = y = 2
return x + y
assert sum() == eval_object(sum, 'sum();')
示例3: test_dict_member_deletion
def test_dict_member_deletion():
def deletion():
d = {'foo': 1, 'bar': 2}
del d['bar']
return d
assert deletion() == eval_object(deletion, 'deletion();')
示例4: test_for_items_in_array
def test_for_items_in_array():
def dofor():
x = 0
for t in [1, 2, 3, 100]:
x += t
return x
assert dofor() == eval_object(dofor, 'dofor();')
示例5: test_for_range_step
def test_for_range_step():
def dofor():
x = 0
for i in range(0, 10, 2):
x += i
return x
assert dofor() == eval_object(dofor, 'dofor();')
示例6: test_for_range_less_simpler
def test_for_range_less_simpler():
def dofor():
x = 0
for i in range(3, 5):
x += i
return x
assert dofor() == eval_object(dofor, 'dofor();')
示例7: test_for_items_in_dict
def test_for_items_in_dict():
def dofor():
x = ''
d = {'foo': 'FOO', 'bar': 'BAR'}
for k in dict(d):
x += k + d[k]
return x
result = eval_object(dofor, 'dofor();')
assert result == 'fooFOObarBAR' or result == 'barBARfooFOO'
示例8: test_assert
def test_assert():
def test_ass():
try:
assert False, "Error raised"
except Exception as e:
return e
return True
assert {'message': 'Error raised', 'name': 'PJAssertionError'} == eval_object(test_ass, 'test_ass();')
示例9: test_if_else_elif
def test_if_else_elif():
def test_if():
if 3 < 3:
x = 1
elif 2 < 3:
x = 2
else:
x = 3
return x
assert test_if() == eval_object(test_if, 'test_if();')
示例10: test_slices
def test_slices():
def test():
foo = 'fooFoo'
a = [
foo[1],
foo[-3:],
foo[2:-1],
foo[:5]
]
return a
assert test() == ['o', 'Foo', 'oFo', 'fooFo'] == eval_object(test, 'test();')
示例11: test_while_and_aug_assignment
def test_while_and_aug_assignment():
def _while():
x = 0
i = 10
while True:
x += i
i -= 1
if i < 0:
break
else:
continue
return x
assert _while() == eval_object(_while, '_while();')
示例12: test_float_conversion
def test_float_conversion():
def test_float():
return float('7.5') + float('7.1')
assert eval_object(test_float, 'test_float();') == test_float()
示例13: test_bitwise_or
def test_bitwise_or():
def _or():
return [0 | 0, 0 | 1, 1 | 0, 1 | 1]
assert _or() == eval_object(_or, '_or();')
示例14: test_list_comprehension
def test_list_comprehension():
def _list():
return [x + 1 for x in [1, 2, 3, 100]]
assert _list() == eval_object(_list, '_list();')
示例15: test_integer
def test_integer():
def test_int():
return int('5') + int('6')
assert eval_object(test_int, 'test_int();') == test_int()