Ejemplo n.º 1
0
    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])
Ejemplo n.º 2
0
    def test_reporter(self):
        sh.coverage('run', 'runtests.py')
        results = Coveralls(repo_token='xxx').get_coverage()
        assert len(results) == 2

        assert_coverage(results[0], {
            'source': ('# coding: utf-8\n\n\n'
                       'def hello():\n'
                       '    print(\'world\')\n\n\n'
                       'class Foo(object):\n'
                       '    """ Bar """\n\n\n'
                       'def baz():\n'
                       '    print(\'this is not tested\')\n\n'
                       'def 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]})

        assert_coverage(results[1], {
            'source': ('# coding: utf-8\n'
                       'from project import hello, branch\n\n'
                       "if __name__ == '__main__':\n"
                       '    hello()\n'
                       '    branch(False, True)\n'
                       '    branch(True, True)'),
            'name': 'runtests.py',
            'coverage': [None, 1, None, 1, 1, 1, 1]})
Ejemplo n.º 3
0
 def test_reporter(self):
     sh.coverage('run', 'runtests.py')
     assert self.cover.get_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]}, {
         'source': "# coding: utf-8\nfrom project import hello\n\nif __name__ == '__main__':\n    hello()",
         'name': 'runtests.py', 'coverage': [None, 1, None, 1, 1]}]
Ejemplo n.º 4
0
def test_malformed_encoding_declaration(capfd):
    os.chdir(join(dirname(dirname(__file__)), 'nonunicode'))
    sh.coverage('run', 'malformed.py')
    logging.getLogger('coveralls').addHandler(logging.StreamHandler())
    result_object = Coveralls(repo_token='xxx').get_coverage()
    assert result_object == []
    out, err = capfd.readouterr()
    assert 'Source file malformed.py can not be properly decoded' in err
Ejemplo n.º 5
0
def test_malformed_encoding_declaration(capfd):
    os.chdir(NONUNICODE_DIR)
    sh.coverage('run', 'malformed.py')

    logging.getLogger('coveralls').addHandler(logging.StreamHandler())
    assert Coveralls(repo_token='xxx').get_coverage() == []

    _, err = capfd.readouterr()
    assert 'Source file malformed.py can not be properly decoded' in err
Ejemplo n.º 6
0
def test_malformed_encoding_declaration(capfd):
    os.chdir(NONUNICODE_DIR)
    sh.coverage('run', 'malformed.py')

    logging.getLogger('coveralls').addHandler(logging.StreamHandler())
    assert Coveralls(repo_token='xxx').get_coverage() == []

    _, err = capfd.readouterr()
    assert 'Source file malformed.py can not be properly decoded' in err
Ejemplo n.º 7
0
def test_non_unicode():
    os.chdir(NONUNICODE_DIR)
    sh.coverage('run', 'nonunicode.py')

    actual_json = json.dumps(Coveralls(repo_token='xxx').get_coverage())
    expected_json_part = ('"source": "# coding: iso-8859-15\\n\\n'
                          'def hello():\\n'
                          '    print(\'I like P\\u00f3lya distribution.\')')
    assert expected_json_part in actual_json
Ejemplo n.º 8
0
def test_malformed_encoding_declaration_py3_or_coverage4(capfd):
    os.chdir(join(dirname(dirname(__file__)), 'nonunicode'))
    sh.coverage('run', 'malformed.py')
    logging.getLogger('coveralls').addHandler(logging.StreamHandler())
    result_object = Coveralls(repo_token='xxx').get_coverage()
    assert len(result_object) == 1
    assert_coverage({'coverage': [None, None, 1, 0], 'name': 'malformed.py',
                     'source': '# -*- cоding: utf-8 -*-\n\ndef hello():\n    return 1\n'},
                    result_object[0])
Ejemplo n.º 9
0
def test_non_unicode():
    os.chdir(NONUNICODE_DIR)
    sh.coverage('run', 'nonunicode.py')

    actual_json = json.dumps(Coveralls(repo_token='xxx').get_coverage())
    expected_json_part = (
        '"source": "# coding: iso-8859-15\\n\\n'
        'def hello():\\n'
        '    print(\'I like P\\u00f3lya distribution.\')')
    assert expected_json_part in actual_json
Ejemplo n.º 10
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]}])
Ejemplo n.º 11
0
 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])
Ejemplo n.º 12
0
 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])
Ejemplo n.º 13
0
 def test_reporter_with_branches(self):
     sh.coverage('run', '--branch', '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, 0, 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, 0, 1, 1, 1]}, results[1])
Ejemplo n.º 14
0
def test_malformed_encoding_declaration_py3_or_coverage4():
    os.chdir(NONUNICODE_DIR)
    sh.coverage('run', 'malformed.py')

    result = Coveralls(repo_token='xxx').get_coverage()
    assert len(result) == 1

    assert result[0]['coverage'] == [None, None, 1, 0]
    assert result[0]['name'] == 'malformed.py'
    assert result[0]['source'].strip() == ('# -*- cоding: utf-8 -*-\n\n'
                                           'def hello():\n'
                                           '    return 1')
    assert 'branches' not in result[0]
Ejemplo n.º 15
0
def test_malformed_encoding_declaration_py3_or_coverage4():
    os.chdir(NONUNICODE_DIR)
    sh.coverage('run', 'malformed.py')

    result = Coveralls(repo_token='xxx').get_coverage()
    assert len(result) == 1

    assert result[0]['coverage'] == [None, None, 1, 0]
    assert result[0]['name'] == 'malformed.py'
    assert result[0]['source'].strip() == ('# -*- cоding: utf-8 -*-\n\n'
                                           'def hello():\n'
                                           '    return 1')
    assert 'branches' not in result[0]
Ejemplo n.º 16
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]
     }])
Ejemplo n.º 17
0
    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])
Ejemplo n.º 18
0
 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 Coveralls(repo_token='xxx').get_coverage() == []
Ejemplo n.º 19
0
def test_non_unicode():
    os.chdir(join(dirname(dirname(__file__)), 'nonunicode'))
    sh.coverage('run', 'nonunicode.py')
    expected_json_part = '"source": "# coding: iso-8859-15\\n\\ndef hello():\\n    print (\'I like P\\u00f3lya distribution.\')'
    assert expected_json_part in json.dumps(Coveralls(repo_token='xxx').get_coverage())
Ejemplo n.º 20
0
 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() == []
Ejemplo n.º 21
0
 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() == []
Ejemplo n.º 22
0
 def test_missing_file(self):
     sh.echo('print("Python rocks!")', _out='extra.py')
     sh.coverage('run', 'extra.py')
     sh.rm('-f', 'extra.py')
     assert Coveralls(repo_token='xxx').get_coverage() == []
 def gdoc_to(self, *args, **kwargs):
     return sh.coverage('run', '-a', GDOC_TO, *args, **kwargs)
 def gdoc_to(self, *args, **kwargs):
     return sh.coverage('run', '-a', GDOC_TO, *args, **kwargs)