def test_insert_license(src_file_path, comment_prefix, new_src_file_expected,
                        tmpdir):
    with chdir_to_test_resources():
        path = tmpdir.join('src_file_path')
        shutil.copy(src_file_path, path.strpath)
        assert insert_license(
            ['--comment-style', comment_prefix,
             path.strpath]) == (1 if new_src_file_expected else 0)
        if new_src_file_expected:
            with open(new_src_file_expected) as expected_content_file:
                expected_content = expected_content_file.read()
            new_file_content = path.open().read()
            assert new_file_content == expected_content
예제 #2
0
def test_fuzzy_match_license(license_file_path, src_file_path, comment_style,
                             new_src_file_expected, fail_check, tmpdir):
    with chdir_to_test_resources():
        path = tmpdir.join('src_file_path')
        shutil.copy(src_file_path, path.strpath)
        args = [
            '--license-filepath', license_file_path, '--comment-style',
            comment_style, '--fuzzy-match-generates-todo', path.strpath
        ]
        assert insert_license(args) == (1 if fail_check else 0)
        if new_src_file_expected:
            with open(new_src_file_expected) as expected_content_file:
                expected_content = expected_content_file.read()
            new_file_content = path.open().read()
            assert new_file_content == expected_content
def test_remove_license(src_file_path, is_python, new_src_file_expected,
                        tmpdir):
    with chdir_to_test_resources():
        path = tmpdir.join('src_file_path')
        shutil.copy(src_file_path, path.strpath)
        argv = ['--remove-header', path.strpath]
        if is_python:
            argv = ['--comment-style', '#'] + argv
        else:
            argv = ['--comment-style', '/*| *| */'] + argv
        assert insert_license(argv) == (1 if new_src_file_expected else 0)
        if new_src_file_expected:
            with open(new_src_file_expected) as expected_content_file:
                expected_content = expected_content_file.read()
            new_file_content = path.open().read()
            assert new_file_content == expected_content