Exemplo n.º 1
0
def test_nothing_found():
    """
    Make sure nothing fails when no annotation is found.
    """
    config = FakeConfig()

    r = FakeExtension(config, VerboseEcho())
    with open('tests/extensions/base_test_files/empty.foo') as f:
        r.search(f)
Exemplo n.º 2
0
def test_strip_single_line_comment_tokens():
    config = FakeConfig()

    extension = FakeExtension(config, VerboseEcho())
    text = """baz line1
  baz line2
bazline3
baz   line4"""
    expected_result = """ line1
 line2
line3
   line4"""
    # pylint: disable=protected-access
    assert expected_result == extension._strip_single_line_comment_tokens(text)
Exemplo n.º 3
0
def test_get_group_for_token_multiple_groups():
    config = FakeConfig()
    config.groups = {'group1': ['token1'], 'group2': ['token2', 'foo']}
    search = FakeSearch(config)
    assert search._get_group_for_token('foo') == 'group2'  # pylint: disable=protected-access
Exemplo n.º 4
0
def test_format_results_for_report():
    """
    Test that report formatting puts annotations into groups correctly
    """
    config = FakeConfig()
    config.echo.set_verbosity(3)
    config.groups = {'group1': ['token1'], 'group2': ['token2', 'foo']}

    search = FakeSearch(config)

    # Create a fake result set for _format_results_for_report to work on
    fake_results = OrderedDict()

    # First file has 6 annotations. expected_group_id is a special key for this test, allowing us to loop through
    # these below and know what group each result should be in.
    fake_results['foo/bar.py'] = [
        {
            'found_by': 'test',
            'filename': 'foo/bar.py',
            'line_number': 1,
            'annotation_token': 'token2',
            'annotation_data': 'file 1 annotation 1',
            'expected_group_id': 1
        },
        {
            'found_by': 'test',
            'filename': 'foo/bar.py',
            'line_number': 2,
            'annotation_token': 'foo',
            'annotation_data': 'file 1 annotation 2',
            'expected_group_id': 1
        },
        {
            'found_by': 'test',
            'filename': 'foo/bar.py',
            'line_number': 4,
            'annotation_token': 'not_in_a_group',
            'annotation_data': 'file 1 annotation 3',
            'expected_group_id': None
        },
        {
            'found_by': 'test',
            'filename': 'foo/bar.py',
            'line_number': 10,
            'annotation_token': 'token1',
            'annotation_data': 'file 1 annotation 4',
            'expected_group_id': 2
        },
        {
            'found_by': 'test',
            'filename': 'foo/bar.py',
            'line_number': 12,
            'annotation_token': 'token2',
            'annotation_data': 'file 1 annotation 5',
            'expected_group_id': 3
        },
        {
            'found_by': 'test',
            'filename': 'foo/bar.py',
            'line_number': 13,
            'annotation_token': 'foo',
            'annotation_data': 'file 1 annotation 6',
            'expected_group_id': 3
        },
    ]

    fake_results['foo/baz.py'] = [{
        'found_by': 'test',
        'filename': 'foo/bar.py',
        'line_number': 1,
        'annotation_token': 'token2',
        'annotation_data': 'file 2 annotation 1',
        'expected_group_id': 4
    }, {
        'found_by': 'test',
        'filename': 'foo/bar.py',
        'line_number': 2,
        'annotation_token': 'foo',
        'annotation_data': 'file 1 annotation 2',
        'expected_group_id': 4
    }]

    # Run the format function
    results = search._format_results_for_report(fake_results)  # pylint: disable=protected-access

    for filename in fake_results:
        for fake in fake_results[filename]:
            for formatted in results[filename]:
                # When we find the same annotation, make sure that grouping is correct
                if fake['annotation_data'] == formatted['annotation_data']:
                    # Ungrouped annotations should not have the 'report_group_id' key
                    if fake['expected_group_id'] is None:
                        assert 'report_group_id' not in formatted
                    # Otherwise it should match our expected value
                    else:
                        assert fake['expected_group_id'] == formatted[
                            'report_group_id']
                    break
Exemplo n.º 5
0
def test_get_group_for_token_missing_token():
    config = FakeConfig()
    search = FakeSearch(config)
    assert search._get_group_for_token('foo') is None  # pylint: disable=protected-access