本文整理汇总了Python中test.test_helper.run函数的典型用法代码示例。如果您正苦于以下问题:Python run函数的具体用法?Python run怎么用?Python run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_assigning_to_any_special_variable_is_disallowed
def test_assigning_to_any_special_variable_is_disallowed(self):
for var in ('p', 'ff', 'files'):
with self.assertRaises(AssertionError) as cm:
print("testing var " + var)
run(var + ' = 1', [0])
self.assertEqual(cm.exception.message, "can't assign to `%s` (expression: %s)" % (var,var + ' = 1'))
开发者ID:lilydjwg,项目名称:piep,代码行数:7,代码来源:test_entire_file_ops.py
示例2: test_lists_are_not_downgraded_to_streams
def test_lists_are_not_downgraded_to_streams(self):
self.assertEqual(
run('pp[0], pp[0]', ['1','2']),
['1','2'])
self.assertEqual(
run('list(pp) | pp[0], pp[0]', ['1','2']),
['1','1'])
开发者ID:lilydjwg,项目名称:piep,代码行数:8,代码来源:test_entire_file_ops.py
示例3: test_sort
def test_sort(self):
self.assertEqual(
run('pp.sort()', [3,2,1,1]),
['1', '1','2','3'])
self.assertEqual(
run('pp.sort(uniq=True)', [3,2,1,1]),
['1','2','3'])
开发者ID:lilydjwg,项目名称:piep,代码行数:8,代码来源:test_entire_file_ops.py
示例4: test_modules_are_not_importable_from_cwd_by_default
def test_modules_are_not_importable_from_cwd_by_default(self):
# for the same reason $PATH does not include
# "." - it could be an attack vector
with temp_cwd():
with open("mymod.py", 'w') as f:
f.write("def up(s): return s.upper()")
self.assertRaises(ImportError,
lambda: run('-m', 'mymod', 'mymod.up(p)', ['a']))
开发者ID:lilydjwg,项目名称:piep,代码行数:8,代码来源:test_env.py
示例5: test_complex_parsing
def test_complex_parsing(self):
self.assertEqual(
run('("%s) %s || %s" % ((i + 1) | 0x00, p, p.upper())) | p', ['a', 'b', 'c']),
[
'1) a || A',
'2) b || B',
'3) c || C',
])
开发者ID:lilydjwg,项目名称:piep,代码行数:8,代码来源:test_line_ops.py
示例6: test_zip_shortest
def test_zip_shortest(self):
with tempfile.NamedTemporaryFile() as f:
f.write('a\nb\nc\n')
f.seek(0)
self.assertEqual(
run('--join=-',
'--file=' + f.name, 'pp.zip_shortest(files[0]) | p[0], p[1].upper()', ['1']),
['1-A'])
开发者ID:lilydjwg,项目名称:piep,代码行数:9,代码来源:test_entire_file_ops.py
示例7: test_file_alias_when_one_file_used
def test_file_alias_when_one_file_used(self):
with tempfile.NamedTemporaryFile() as f:
f.write('a\nb\nc\n')
f.seek(0)
self.assertEqual(
run('--join=-',
'--file=' + f.name, 'pp.zip(ff) | p[0] or "", p[1].upper()', ['1']),
['1-A','-B','-C'])
开发者ID:lilydjwg,项目名称:piep,代码行数:9,代码来源:test_entire_file_ops.py
示例8: test_a_pair_of_files
def test_a_pair_of_files(self):
with tempfile.NamedTemporaryFile() as f:
f.write('a\nb\nc\n')
f.seek(0)
self.assertEqual(
run('--join=-',
'--file=' + f.name, 'pp.zip(files[0]) | p[0] or "", p[1].upper()', ['1']),
['1-A','-B','-C'])
开发者ID:lilydjwg,项目名称:piep,代码行数:9,代码来源:test_entire_file_ops.py
示例9: test_file_usage_causes_file_wise_mode
def test_file_usage_causes_file_wise_mode(self):
with tempfile.NamedTemporaryFile() as f:
f.write('a\nb\nc\n')
f.seek(0)
self.assertEqual(
run(
'--file=' + f.name,
'len(ff)', [1,2,3,4,5,6]), ['3'])
with tempfile.NamedTemporaryFile() as f2:
f2.write('a\nb\nc\nd\n')
f2.seek(0)
self.assertEqual(
run(
'--file=' + f.name,
'--file=' + f2.name,
'map(len, files)', [1,2,3,4,5,6]), ['3', '4'])
开发者ID:lilydjwg,项目名称:piep,代码行数:19,代码来源:test_entire_file_ops.py
示例10: test_regex_functions
def test_regex_functions(self):
self.assertEqual(run('p.splitre(" +")' , ['a b c']) , ['a b c'])
self.assertEqual(run('p.match("b..")' , ['a beef c']) , ['bee'])
self.assertEqual(run('p.match("b(..)",1)' , ['a beef c']) , ['ee'])
self.assertEqual(run('p.match("b(?P<m>..)?","m")' , ['a beef c']) , ['ee'])
self.assertEqual(run('p.match("b(?P<m>..)?","m")' , ['a b']) , [])
self.assertEqual(run('p.matches("b..")' , ['a bee c', 'nope']) , ['a bee c'])
开发者ID:lilydjwg,项目名称:piep,代码行数:7,代码来源:test_line_ops.py
示例11: test_shell_coercion_to_string
def test_shell_coercion_to_string(self):
self.assertEqual(run('sh("echo", p) | "oo" in p', ['foo', 'bar', 'boo']), ['foo', 'boo'])
self.assertEqual(run('sh("echo", p) | p > "doo"', ['foo', 'bar', 'boo']), ['foo'])
self.assertEqual(run('sh("echo", p) | p[1] == "o"', ['foo', 'bar', 'boo']), ['foo', 'boo'])
self.assertEqual(run('sh("echo", p) | p + "o"', ['foo', 'bar', 'boo']), ['fooo', 'baro', 'booo'])
self.assertEqual(run('sh("echo", "%s", p) | p % "1"', ['foo', 'bar', 'boo']), ['1 foo', '1 bar', '1 boo'])
self.assertEqual(run('sh("echo", p) | p * 2', ['foo', 'bar', 'boo']), ['foofoo', 'barbar', 'booboo'])
开发者ID:lilydjwg,项目名称:piep,代码行数:7,代码来源:test_globals.py
示例12: test_chunk_returns_enhanced_list
def test_chunk_returns_enhanced_list(self):
self.assertEqual(
run('pp.divide(lambda l: "---" in l, keep_header=False) | p.len()',
[
'leading',
'----',
'chunk 1 line 1',
'chunk 1 line 2',
'----',
'chunk 2 line 1',
'chunk 2 line 2',
'---',
]),
['1', '2', '2'])
开发者ID:lilydjwg,项目名称:piep,代码行数:14,代码来源:test_entire_file_ops.py
示例13: test_chunk_on_predicate
def test_chunk_on_predicate(self):
self.assertEqual(
run('pp.divide(lambda l: "---" in l) | ".".join(p)',
[
'leading',
'----',
'chunk 1 line 1',
'chunk 1 line 2',
'----',
'chunk 2 line 1',
'chunk 2 line 2',
'---',
]),
['leading',
'----.chunk 1 line 1.chunk 1 line 2',
'----.chunk 2 line 1.chunk 2 line 2',
'---']
)
开发者ID:lilydjwg,项目名称:piep,代码行数:18,代码来源:test_entire_file_ops.py
示例14: test_reversed
def test_reversed(self):
self.assertEqual(
run('pp.reverse()', ['1', '2']),
['2','1'])
开发者ID:lilydjwg,项目名称:piep,代码行数:4,代码来源:test_entire_file_ops.py
示例15: test_head_works_lazily
def test_head_works_lazily(self):
self.assertEqual(
run('pp[:4]', itertools.cycle('abc')),
['a','b','c', 'a'])
开发者ID:lilydjwg,项目名称:piep,代码行数:4,代码来源:test_entire_file_ops.py
示例16: test_multi_head_and_tail
def test_multi_head_and_tail(self):
self.assertEqual(
run('pp[:5] | "hello", p | pp[-2:]', [1, 2, 3, 4, 5, 6, 7, 8, 9. ,10]),
['hello 4', 'hello 5'])
开发者ID:lilydjwg,项目名称:piep,代码行数:4,代码来源:test_entire_file_ops.py
示例17: test_merge
def test_merge(self):
self.assertEqual(
run('p.split(".") | pp.merge() | p + "!"', ['1.2.3', '4.5.6']),
['1!', '2!', '3!', '4!', '5!', '6!'])
开发者ID:lilydjwg,项目名称:piep,代码行数:4,代码来源:test_entire_file_ops.py
示例18: test_int
def test_int(self):
self.assertEqual(
run('pp.len()', ['1','2','3']), ['3'])
开发者ID:lilydjwg,项目名称:piep,代码行数:3,代码来源:test_entire_file_ops.py
示例19: test_single_string
def test_single_string(self):
self.assertEqual(
run('pp.join(".")', ['1','2','3']), ['1.2.3'])
开发者ID:lilydjwg,项目名称:piep,代码行数:3,代码来源:test_entire_file_ops.py
示例20: test_reprocess_sequence_elements
def test_reprocess_sequence_elements(self):
self.assertEqual(
run('[p,p] | pp.merge()', ['a','b','c']),
['a','a','b','b','c','c'])
开发者ID:lilydjwg,项目名称:piep,代码行数:4,代码来源:test_entire_file_ops.py
注:本文中的test.test_helper.run函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论