本文整理汇总了Python中coveralls.Coveralls.get_coverage方法的典型用法代码示例。如果您正苦于以下问题:Python Coveralls.get_coverage方法的具体用法?Python Coveralls.get_coverage怎么用?Python Coveralls.get_coverage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coveralls.Coveralls
的用法示例。
在下文中一共展示了Coveralls.get_coverage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ReporterTest
# 需要导入模块: from coveralls import Coveralls [as 别名]
# 或者: from coveralls.Coveralls import get_coverage [as 别名]
class ReporterTest(unittest.TestCase):
def setUp(self):
os.chdir(join(dirname(dirname(__file__)), 'example'))
sh.rm('-f', '.coverage')
sh.rm('-f', 'extra.py')
self.cover = Coveralls(repo_token='xxx')
def test_reporter(self):
sh.coverage('run', 'runtests.py')
results = self.cover.get_coverage()
assert len(results) == 2
assert_coverage({
'source': '# coding: utf-8\n\n\ndef hello():\n print(\'world\')\n\n\nclass Foo(object):\n """ Bar """\n\n\ndef baz():\n print(\'this is not tested\')',
'name': 'project.py',
'coverage': [None, None, None, 1, 1, None, None, 1, None, None, None, 1, 0]}, results[0])
assert_coverage({
'source': "# coding: utf-8\nfrom project import hello\n\nif __name__ == '__main__':\n hello()",
'name': 'runtests.py', 'coverage': [None, 1, None, 1, 1]}, results[1])
def test_missing_file(self):
sh.echo('print("Python rocks!")', _out="extra.py")
sh.coverage('run', 'extra.py')
sh.rm('-f', 'extra.py')
assert self.cover.get_coverage() == []
def test_not_python(self):
sh.echo('print("Python rocks!")', _out="extra.py")
sh.coverage('run', 'extra.py')
sh.echo("<h1>This isn't python!</h1>", _out="extra.py")
assert self.cover.get_coverage() == []
示例2: ReporterTest
# 需要导入模块: from coveralls import Coveralls [as 别名]
# 或者: from coveralls.Coveralls import get_coverage [as 别名]
class ReporterTest(unittest.TestCase):
def setUp(self):
os.chdir(join(dirname(dirname(__file__)), 'example'))
sh.rm('-f', '.coverage')
sh.rm('-f', 'extra.py')
self.cover = Coveralls(repo_token='xxx')
def test_reporter(self):
sh.coverage('run', 'runtests.py')
results = self.cover.get_coverage()
assert len(results) == 2
assert_coverage({
'source': '# coding: utf-8\n\n\ndef hello():\n print(\'world\')\n\n\nclass Foo(object):\n """ Bar """\n\n\ndef baz():\n print(\'this is not tested\')\n\ndef branch(cond1, cond2):\n if cond1:\n print(\'condition tested both ways\')\n if cond2:\n print(\'condition not tested both ways\')',
'name': 'project.py',
'coverage': [None, None, None, 1, 1, None, None, 1, None, None, None, 1, 0, None, 1, 1, 1, 1, 1]}, results[0])
assert_coverage({
'source': "# coding: utf-8\nfrom project import hello, branch\n\nif __name__ == '__main__':\n hello()\n branch(False, True)\n branch(True, True)",
'name': 'runtests.py', 'coverage': [None, 1, None, 1, 1, 1, 1]}, results[1])
def test_reporter_with_branches(self):
sh.coverage('run', '--branch', 'runtests.py')
results = self.cover.get_coverage()
assert len(results) == 2
# Branches are expressed as four values each in a flat list
assert not len(results[0]['branches']) % 4
assert not len(results[1]['branches']) % 4
assert_coverage({
'source': '# coding: utf-8\n\n\ndef hello():\n print(\'world\')\n\n\nclass Foo(object):\n """ Bar """\n\n\ndef baz():\n print(\'this is not tested\')\n\ndef branch(cond1, cond2):\n if cond1:\n print(\'condition tested both ways\')\n if cond2:\n print(\'condition not tested both ways\')',
'name': 'project.py',
'branches': [16, 0, 17, 1, 16, 0, 18, 1, 18, 0, 19, 1, 18, 0, 15, 0],
'coverage': [None, None, None, 1, 1, None, None, 1, None, None, None, 1, 0, None, 1, 1, 1, 1, 1]}, results[0])
assert_coverage({
'source': "# coding: utf-8\nfrom project import hello, branch\n\nif __name__ == '__main__':\n hello()\n branch(False, True)\n branch(True, True)",
'name': 'runtests.py',
'branches': [4, 0, 5, 1, 4, 0, 2, 0],
'coverage': [None, 1, None, 1, 1, 1, 1]}, results[1])
def test_missing_file(self):
sh.echo('print("Python rocks!")', _out="extra.py")
sh.coverage('run', 'extra.py')
sh.rm('-f', 'extra.py')
assert self.cover.get_coverage() == []
def test_not_python(self):
sh.echo('print("Python rocks!")', _out="extra.py")
sh.coverage('run', 'extra.py')
sh.echo("<h1>This isn't python!</h1>", _out="extra.py")
assert self.cover.get_coverage() == []
示例3: test_reporter
# 需要导入模块: from coveralls import Coveralls [as 别名]
# 或者: from coveralls.Coveralls import get_coverage [as 别名]
def test_reporter(self):
os.chdir(join(dirname(dirname(__file__)), 'example'))
sh.coverage('run', 'runtests.py')
cover = Coveralls(repo_token='xxx')
expect(cover.get_coverage()).should.be.equal([{
'source': '# coding: utf-8\n\n\ndef hello():\n print(\'world\')\n\n\nclass Foo(object):\n """ Bar """\n\n\ndef baz():\n print(\'this is not tested\')',
'name': 'project.py',
'coverage': [None, None, None, 1, 1, None, None, 1, None, None, None, 1, 0]}, {
'source': "# coding: utf-8\nfrom project import hello\n\nif __name__ == '__main__':\n hello()",
'name': 'runtests.py', 'coverage': [None, 1, None, 1, 1]}])