本文整理匯總了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]}])