Esempio n. 1
0
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() == []
Esempio n. 2
0
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() == []
Esempio n. 3
0
 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]}])
Esempio n. 4
0
 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]
     }])
Esempio n. 5
0
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() == []