Esempio n. 1
0
def test_write_report_missing_key(mock_opened_file):
    """Tests that writing a report for an example with a missing key skips the
    example but does not otherwise fail."""
    path = 'test_path.py'
    service = 'testsvc'

    cleanup_report.write_report(
        [{
            'metadata_path': 'metadata.yaml',
            'wrong_key': [{
                'path': path,
                'services': [service]
            }]
        }, {
            'metadata_path': 'metadata.yaml',
            'files': [{
                'path': path,
                'services': [service]
            }]
        }], [cleanup_report.make_github_url('', path)], 'test.csv')
    calls = make_expected_calls(1, 1, 1, [
        ','.join([cleanup_report.make_github_url('', path), 'Python', service])
    ])
    handle = mock_opened_file()
    handle.write.assert_has_calls(calls)
Esempio n. 2
0
def test_write_report_dup_files(mock_opened_file):
    """Tests writing a report when a file is listed twice in the metadata."""
    handle = mock_opened_file()
    cleanup_report.write_report([{
        'metadata_path':
        'metadata.yaml',
        'files': [
            {
                'path': 'example_path1.py',
                'services': ['example_svc']
            },
            {
                'path': 'example_path1.py',
                'services': ['example_svc']
            },
        ]
    }], [
        cleanup_report.make_github_url('', 'example_path1.py'),
    ], 'test.csv')
    calls = make_expected_calls(1, 1, 1, [
        ','.join([
            cleanup_report.make_github_url('', 'example_path1.py'), 'Python',
            'example_svc'
        ])
    ])
    handle.write.assert_has_calls(calls)
Esempio n. 3
0
def test_write_report_unclean_files(mock_opened_file):
    """Tests writing a report when files exist in the repo that have not been
    cleaned."""
    handle = mock_opened_file()
    cleanup_report.write_report(
        [{
            'metadata_path': 'metadata.yaml',
            'files': [
                {
                    'path': 'example_path1.py',
                    'services': ['example_svc']
                },
            ]
        }], [
            cleanup_report.make_github_url('', 'example_path1.py'),
            cleanup_report.make_github_url('', 'example_path2.py'),
            cleanup_report.make_github_url('', 'example_path3.py')
        ], 'test.csv')
    calls = make_expected_calls(1, 1, 3, [
        ','.join([
            cleanup_report.make_github_url('', 'example_path1.py'), 'Python',
            'example_svc'
        ])
    ])
    handle.write.assert_has_calls(calls)
Esempio n. 4
0
def test_write_report_missing_file(mock_opened_file):
    """Tests writing a report where a file is listed in the metadata but does
    not exist in the repo."""
    handle = mock_opened_file()
    cleanup_report.write_report([{
        'metadata_path':
        'metadata.yaml',
        'files': [{
            'path': 'example_path1.py',
            'services': ['example_svc']
        }, {
            'path': 'example_path2.py',
            'services': ['example_svc']
        }, {
            'path': 'example_path3.py',
            'services': ['example_svc']
        }]
    }], [
        cleanup_report.make_github_url('', 'example_path1.py'),
        cleanup_report.make_github_url('', 'example_path3.py')
    ], 'test.csv')
    calls = make_expected_calls(1, 2, 2, [
        ','.join([
            cleanup_report.make_github_url('', 'example_path1.py'), 'Python',
            'example_svc'
        ]), ','.join([
            cleanup_report.make_github_url('', 'example_path3.py'), 'Python',
            'example_svc'
        ])
    ])
    handle.write.assert_has_calls(calls)
def test_write_report_unclean_files(mock_opened_file, clean_files, repo_files,
                                    dirty):
    """Tests writing a report when files exist in the repo that have not been
    cleaned."""
    handle = mock_opened_file()
    cleanup_report.write_report([{
        'metadata_path':
        'metadata.yaml',
        'files': [{
            'path': file,
            'services': ['example_svc']
        } for file in clean_files]
    }], [cleanup_report.make_github_url('', file) for file in repo_files],
                                'test.csv',
                                summarize=False,
                                dirty=dirty)
    calls = make_expected_calls(1, len(clean_files), len(repo_files), [
        ','.join([
            cleanup_report.make_github_url('', file), 'Python', 'example_svc'
        ]) for file in clean_files
    ])
    if dirty:
        repo_lookup = [file.lower() for file in repo_files]
        clean_lookup = [file.lower() for file in clean_files]
        dirty_files = sorted(
            [file for file in repo_lookup if file not in clean_lookup])

        calls.append(call("\n"))
        if dirty_files:
            calls.append(call("**Dirty files found:**\n"))
            calls.append(
                call('\n'.join([
                    cleanup_report.make_github_url('', file)
                    for file in dirty_files
                ])))
        else:
            calls.append(call("**No dirty files found!**"))
    handle.write.assert_has_calls(calls)
Esempio n. 6
0
def test_write_single_report(mock_opened_file):
    """Tests writing a report of a single file."""
    path = 'test_path.py'
    service = 'testsvc'
    cleanup_report.write_report(
        [{
            'metadata_path': 'metadata.yaml',
            'files': [{
                'path': path,
                'services': [service]
            }]
        }], [cleanup_report.make_github_url('', path)], 'test.csv')
    handle = mock_opened_file()
    calls = make_expected_calls(
        1, 1, 1,
        [','.join([cleanup_report.GITHUB_URL + path, 'Python', service])])
    handle.write.assert_has_calls(calls)
Esempio n. 7
0
def test_write_multi_report(mock_opened_file):
    """Tests writing a report for a list of examples."""
    examples = []
    files = []
    lines = []
    for count in range(1, 5):
        path = f'test_path_{count}.cpp'
        service = f'testsvc{count}'
        examples.append({
            'metadata_path': 'metadata.yaml',
            'files': [{
                'path': path,
                'services': [service]
            }]
        })
        lines.append(','.join(
            [cleanup_report.GITHUB_URL + path, 'C++', service]))
        files.append(cleanup_report.make_github_url('', path))

    cleanup_report.write_report(examples, files, 'test.csv')
    handle = mock_opened_file()
    calls = make_expected_calls(len(lines), len(lines), len(lines), lines)
    handle.write.assert_has_calls(calls)
Esempio n. 8
0
        }], [cleanup_report.make_github_url('', path)], 'test.csv')
    calls = make_expected_calls(1, 1, 1, [
        ','.join([cleanup_report.make_github_url('', path), 'Python', service])
    ])
    handle = mock_opened_file()
    handle.write.assert_has_calls(calls)


@pytest.mark.parametrize("examples,repo_files,lines", [
    ([{
        'metadata_path': 'metadata.yaml',
        'files': [{
            'path': 'example_path.py',
            'services': ['test_svc']
        }]
    }], [cleanup_report.make_github_url('', 'example_path.py')], [
        ','.join([
            cleanup_report.make_github_url('', 'example_path.py'), 'Python',
            'test_svc'
        ])
    ]),
    ([{
        'metadata_path':
        'metadata.yaml',
        'files': [{
            'path': 'example_path.py',
            'services': ['test_svc1', 'test_svc2', 'test_svc3']
        }]
    }], [cleanup_report.make_github_url('', 'example_path.py')], [
        ','.join([
            cleanup_report.make_github_url('', 'example_path.py'), 'Python',