本文整理汇总了Python中coveralls.Coveralls类的典型用法代码示例。如果您正苦于以下问题:Python Coveralls类的具体用法?Python Coveralls怎么用?Python Coveralls使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Coveralls类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main(argv=None):
options = docopt(__doc__, argv=argv)
if options['debug']:
options['--verbose'] = True
level = logging.DEBUG if options['--verbose'] else logging.INFO
log.addHandler(logging.StreamHandler())
log.setLevel(level)
try:
coverallz = Coveralls(config_file=options['--rcfile'])
if not options['debug']:
log.info("Submitting coverage to coveralls.io...")
result = coverallz.wear()
log.info("Coverage submitted!")
log.info(result['message'])
log.info(result['url'])
log.debug(result)
else:
log.info("Testing coveralls-python...")
coverallz.wear(dry_run=True)
except KeyboardInterrupt: # pragma: no cover
log.info('Aborted')
except CoverallsException as e:
log.error(e)
except KeyError as e: # pragma: no cover
log.error(e)
except Exception: # pragma: no cover
raise
示例2: ReporterTest
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() == []
示例3: main
def main(argv=None):
options = docopt(__doc__, argv=argv)
if options["debug"]:
options["--verbose"] = True
level = logging.DEBUG if options["--verbose"] else logging.INFO
log.addHandler(logging.StreamHandler())
log.setLevel(level)
try:
coverallz = Coveralls()
if not options["debug"]:
log.info("Submitting coverage to coveralls.io...")
result = coverallz.wear()
log.info("Coverage submitted!")
log.info(result["message"])
log.info(result["url"])
log.debug(result)
else:
log.info("Testing coveralls-python...")
coverallz.wear(dry_run=True)
except KeyboardInterrupt: # pragma: no cover
log.info("Aborted")
except CoverallsException as e:
log.error(e)
except Exception: # pragma: no cover
raise
示例4: test_merge_empty_data
def test_merge_empty_data(self, mock_requests):
api = Coveralls(repo_token='xxx')
coverage_file = tempfile.NamedTemporaryFile()
coverage_file.write(b'{}')
coverage_file.seek(0)
api.merge(coverage_file.name)
result = api.create_report()
assert json.loads(result)['source_files'] == []
示例5: test_merge
def test_merge(self, mock_requests):
api = Coveralls(repo_token='xxx')
coverage_file = tempfile.NamedTemporaryFile()
coverage_file.write(b'{"source_files": [{"name": "foobar", "coverage": []}]}')
coverage_file.seek(0)
api.merge(coverage_file.name)
result = api.create_report()
assert json.loads(result)['source_files'] == [{'name': 'foobar', 'coverage': []}]
示例6: test_merge_invalid_data
def test_merge_invalid_data(self, mock_logger, mock_requests):
api = Coveralls(repo_token='xxx')
coverage_file = tempfile.NamedTemporaryFile()
coverage_file.write(b'{"random": "stuff"}')
coverage_file.seek(0)
api.merge(coverage_file.name)
result = api.create_report()
assert json.loads(result)['source_files'] == []
mock_logger.assert_called_once_with('No data to be merged; does the '
'json file contain "source_files" data?')
示例7: test_reporter
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]}])
示例8: ReporterTest
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() == []
示例9: test_git
def test_git(self):
cover = Coveralls(repo_token='xxx')
git_info = cover.git_info()
commit_id = git_info['git']['head'].pop('id')
assert re.match(r'^[a-f0-9]{40}$', commit_id)
assert git_info == {'git': {
'head': {
'committer_email': '[email protected]',
'author_email': '[email protected]',
'author_name': 'Daniël',
'message': 'first commit',
'committer_name': 'Daniël',
},
'remotes': [{
'url': 'https://github.com/username/Hello-World.git',
'name': 'origin'
}],
'branch': 'master'
}}
示例10: test_git
def test_git(self):
cover = Coveralls(repo_token='xxx')
git_info = cover.git_info()
commit_id = git_info['git']['head'].pop('id')
self.assertTrue(re.match(r'^[a-f0-9]{40}$', commit_id))
# expect(commit_id).should.match(r'^[a-f0-9]{40}$', re.I | re.U) sure 1.1.7 is broken for py2.6
expect(git_info).should.be.equal({'git': {
'head': {
'committer_email': '[email protected]',
'author_email': '[email protected]',
'author_name': 'Guido',
'message': 'first commit',
'committer_name': 'Guido',
},
'remotes': [{
'url': u'https://github.com/username/Hello-World.git',
'name': u'origin'
}],
'branch': u'master'}})
示例11: main
def main(argv=None):
options = docopt(__doc__, argv=argv)
if options['debug']:
options['--verbose'] = True
level = logging.DEBUG if options['--verbose'] else logging.INFO
log.addHandler(logging.StreamHandler())
log.setLevel(level)
try:
token_required = not options['debug'] and not options['--output']
coverallz = Coveralls(token_required, config_file=options['--rcfile'])
if options['--merge']:
coverallz.merge(options['--merge'])
if options['debug']:
log.info("Testing coveralls-python...")
coverallz.wear(dry_run=True)
elif options['--output']:
log.info('Write coverage report to file...')
coverallz.save_report(options['--output'])
else:
log.info("Submitting coverage to coveralls.io...")
result = coverallz.wear()
log.info("Coverage submitted!")
log.info(result['message'])
log.info(result['url'])
log.debug(result)
except KeyboardInterrupt: # pragma: no cover
log.info('Aborted')
except CoverallsException as e:
log.error(e)
sys.exit(1)
except KeyError as e: # pragma: no cover
log.error(e)
sys.exit(2)
except Exception: # pragma: no cover
raise
示例12: setUp
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')