Esempio n. 1
0
def test_class_file_source__sources_not_found():
    from pycobertura.cobertura import Line
    cobertura = make_cobertura('tests/cobertura.xml')
    expected_sources = {
        'Main.java': [Line(0, 'tests/Main.java not found', None, None)],
        'search/BinarySearch.java':
        [Line(0, 'tests/search/BinarySearch.java not found', None, None)],
        'search/ISortedArraySearch.java': [
            Line(0, 'tests/search/ISortedArraySearch.java not found', None,
                 None)
        ],
        'search/LinearSearch.java':
        [Line(0, 'tests/search/LinearSearch.java not found', None, None)],
    }
    for filename in cobertura.files():
        assert cobertura.file_source(filename) == expected_sources[filename]
def test_hunkify_coverage__no_valid_hunks_found():
    from pycobertura.utils import hunkify_lines
    from pycobertura.cobertura import Line

    lines = [
        Line(1, 'a', None, None),
        Line(2, 'b', None, None),
        Line(3, 'c', None, None),
        Line(4, 'd', None, None),
        Line(5, 'e', None, None),
        Line(6, 'f', None, None),
        Line(7, 'g', None, None),
        Line(8, 'h', None, None),
        Line(9, 'i', None, None),
    ]

    hunks = hunkify_lines(lines)

    assert hunks == []
Esempio n. 3
0
def test_class_file_source__sources_found(report, source, source_prefix):
    from pycobertura.cobertura import Line
    cobertura = make_cobertura(report,
                               source=source,
                               source_prefix=source_prefix)
    expected_sources = {
        'dummy/__init__.py': [],
        'dummy/dummy.py': [
            Line(1, 'def foo():\n', True, None),
            Line(2, '    pass\n', True, None),
            Line(3, '\n', None, None),
            Line(4, 'def bar():\n', True, None),
            Line(5, "    a = 'a'\n", False, None),
            Line(6, "    b = 'b'\n", False, None),
        ],
        'dummy/dummy2.py': [
            Line(1, 'def baz():\n', True, None),
            Line(2, '    pass\n', True, None)
        ],
        'dummy/dummy4.py': [
            Line(1, 'def barbaz():\n', False, None),
            Line(2, '    pass\n', False, None),
            Line(3, '\n', None, None),
            Line(4, 'def foobarbaz():\n', False, None),
            Line(5, '    a = 1 + 3\n', False, None),
            Line(6, '    pass\n', False, None)
        ],
    }
    for filename in cobertura.files():
        assert cobertura.file_source(filename) == \
               expected_sources[filename]
def test_hunkify_coverage__overlapping():
    from pycobertura.utils import hunkify_lines
    from pycobertura.cobertura import Line

    lines = [
        Line(1, 'a', None, None),
        Line(2, 'b', True, None),
        Line(3, 'c', True, None),
        Line(4, 'd', None, None),
        Line(5, 'e', None, None),
        Line(6, 'f', True, None),
        Line(7, 'g', True, None),
        Line(8, 'h', None, None),
    ]

    hunks = hunkify_lines(lines)

    assert hunks == [
        [
            Line(1, 'a', None, None),
            Line(2, 'b', True, None),
            Line(3, 'c', True, None),
            Line(4, 'd', None, None),
            Line(5, 'e', None, None),
            Line(6, 'f', True, None),
            Line(7, 'g', True, None),
            Line(8, 'h', None, None),
        ],
    ]
def test_hunkify_coverage__2_distant_hunks_w_full_context_makes_2_hunk():
    from pycobertura.utils import hunkify_lines
    from pycobertura.cobertura import Line

    lines = [
        Line(1, 'a', None, None),  # context 1
        Line(2, 'b', None, None),  # context 1
        Line(3, 'c', None, None),  # context 1
        Line(4, 'd', True, None),
        Line(5, 'e', None, None),  # context 1
        Line(6, 'f', None, None),  # context 1
        Line(7, 'g', None, None),  # context 1
        Line(8, 'h', None, None),
        Line(9, 'i', None, None),  # context 2
        Line(10, 'j', None, None),  # context 2
        Line(11, 'k', None, None),  # context 2
        Line(12, 'l', False, None),
        Line(13, 'm', None, None),  # context 2
        Line(14, 'n', None, None),  # context 2
        Line(15, 'o', None, None),  # context 2
    ]

    hunks = hunkify_lines(lines)

    assert hunks == [
        [
            Line(1, 'a', None, None),
            Line(2, 'b', None, None),
            Line(3, 'c', None, None),
            Line(4, 'd', True, None),
            Line(5, 'e', None, None),
            Line(6, 'f', None, None),
            Line(7, 'g', None, None),
        ],
        [
            Line(9, 'i', None, None),
            Line(10, 'j', None, None),
            Line(11, 'k', None, None),
            Line(12, 'l', False, None),
            Line(13, 'm', None, None),
            Line(14, 'n', None, None),
            Line(15, 'o', None, None),
        ],
    ]
Esempio n. 6
0
def test_diff_class_source():
    from pycobertura.cobertura import CoberturaDiff
    from pycobertura.cobertura import Line

    cobertura1 = make_cobertura('tests/dummy.source1/coverage.xml')
    cobertura2 = make_cobertura('tests/dummy.source2/coverage.xml')
    differ = CoberturaDiff(cobertura1, cobertura2)

    expected_sources = {
        'dummy/__init__.py': [],
        'dummy/dummy.py': [
            Line(1, u'def foo():\n', None, None),
            Line(2, u'    pass\n', None, None),
            Line(3, u'\n', None, None),
            Line(4, u'def bar():\n', None, None),
            Line(5, u"    a = 'a'\n", True, 'cov-up'),
            Line(6, u"    d = 'd'\n", True, 'line-edit')
        ],
        'dummy/dummy2.py': [
            Line(1, u'def baz():\n', None, None),
            Line(2, u"    c = 'c'\n", True, 'line-edit'),
            Line(3, u'\n', None, 'line-edit'),
            Line(4, u'def bat():\n', True, 'line-edit'),
            Line(5, u'    pass\n', False, 'cov-down')
        ],
        'dummy/dummy3.py': [
            Line(1, u'def foobar():\n', False, 'line-edit'),
            Line(
                2,
                u'    pass  # This is a very long comment that was purposefully written so we could test how HTML rendering looks like when the boundaries of the page are reached. And here is a non-ascii char: \u015e\n',
                False, 'line-edit')
        ],
    }

    for filename in cobertura2.files():
        assert differ.file_source(filename) == \
               expected_sources[filename]