本文整理汇总了Python中tap.parser.Parser.parse_file方法的典型用法代码示例。如果您正苦于以下问题:Python Parser.parse_file方法的具体用法?Python Parser.parse_file怎么用?Python Parser.parse_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tap.parser.Parser
的用法示例。
在下文中一共展示了Parser.parse_file方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parse_empty_file
# 需要导入模块: from tap.parser import Parser [as 别名]
# 或者: from tap.parser.Parser import parse_file [as 别名]
def test_parse_empty_file(self):
temp = tempfile.NamedTemporaryFile(delete=False)
temp.close()
parser = Parser()
lines = []
for line in parser.parse_file(temp.name):
lines.append(line)
self.assertEqual(0, len(lines))
示例2: test_parses_file
# 需要导入模块: from tap.parser import Parser [as 别名]
# 或者: from tap.parser.Parser import parse_file [as 别名]
def test_parses_file(self):
sample = inspect.cleandoc(
"""1..2
ok 1 A passing test
not ok 2 A failing test""")
temp = tempfile.NamedTemporaryFile(delete=False)
temp.write(sample.encode('utf-8'))
temp.close()
parser = Parser()
lines = []
for line in parser.parse_file(temp.name):
lines.append(line)
self.assertEqual(3, len(lines))
self.assertEqual('plan', lines[0].category)
self.assertEqual('test', lines[1].category)
self.assertTrue(lines[1].ok)
self.assertEqual('test', lines[2].category)
self.assertFalse(lines[2].ok)
示例3: Loader
# 需要导入模块: from tap.parser import Parser [as 别名]
# 或者: from tap.parser.Parser import parse_file [as 别名]
class Loader(object):
"""Load TAP lines into unittest-able objects."""
ignored_lines = set(['diagnostic', 'unknown'])
def __init__(self):
self._parser = Parser()
def load(self, files):
"""Load any files found into a suite.
Any directories are walked and their files are added as TAP files.
:returns: A ``unittest.TestSuite`` instance
"""
suite = unittest.TestSuite()
for filepath in files:
if os.path.isdir(filepath):
self._find_tests_in_directory(filepath, suite)
else:
suite.addTest(self.load_suite_from_file(filepath))
return suite
def load_suite_from_file(self, filename):
"""Load a test suite with test lines from the provided TAP file.
:returns: A ``unittest.TestSuite`` instance
"""
suite = unittest.TestSuite()
rules = Rules(filename, suite)
if not os.path.exists(filename):
rules.handle_file_does_not_exist()
return suite
line_counter = 0
for line in self._parser.parse_file(filename):
line_counter += 1
if line.category in self.ignored_lines:
continue
if line.category == 'test':
suite.addTest(Adapter(filename, line))
rules.saw_test()
elif line.category == 'plan':
if line.skip:
rules.handle_skipping_plan(line)
return suite
rules.saw_plan(line, line_counter)
elif line.category == 'bail':
rules.handle_bail(line)
return suite
elif line.category == 'version':
rules.saw_version_at(line_counter)
rules.check(line_counter)
return suite
def _find_tests_in_directory(self, directory, suite):
"""Find test files in the directory and add them to the suite."""
for dirpath, dirnames, filenames in os.walk(directory):
for filename in filenames:
filepath = os.path.join(dirpath, filename)
suite.addTest(self.load_suite_from_file(filepath))