Ejemplo n.º 1
0
def test_single_year_update(tmp_path):
    """ Tests that a copyright header's years are updated correctly """
    shutil.copytree(src=ROOT, dst=Path(tmp_path, 'sample'))
    baz = Path(tmp_path, 'sample/test/resources/sample/scripts/baz.py')
    copywriter.TxtFile(baz).update()
    with baz.open() as f:
        assert 'Copyright 2019-2020 Bob' in f.read()
Ejemplo n.º 2
0
def test_year_range_update(tmp_path):
    """ Tests that a copyright header's years are updated correctly """
    shutil.copytree(src=ROOT, dst=Path(tmp_path, 'sample'))
    bar = Path(tmp_path, 'sample/test/resources/sample/src/bar.c')
    copywriter.TxtFile(bar).update()
    with bar.open() as f:
        assert f.read() == '// Copyright 2018-2020 Bob\n'
Ejemplo n.º 3
0
def test_bash_addition(tmp_path: Path):
    """ Tests addition of a copyright header to a bash file. """
    path = _get_test_file(tmp_path, 'missing/no_doc/bash.sh')
    expected = textwrap.dedent("""
    #
    # Copyright 2020 Monty
    #
    echo "foo"
    """[1:])  # skip opening newline.
    copywriter.TxtFile(path).add('Copyright {year} Monty')
    with path.open() as f:
        assert f.read() == expected
Ejemplo n.º 4
0
def test_cmake_addition(tmp_path: Path):
    """ Tests addition of a copyright header to a cmake file. """
    path = _get_test_file(tmp_path, 'missing/no_doc/cmake.cmake')
    expected = textwrap.dedent("""
    #
    # Copyright 2020 Monty
    #
    
    message(STATUS "Doing the thing.")
    """[1:])  # skip opening newline.
    copywriter.TxtFile(path).add('Copyright {year} Monty')
    with path.open() as f:
        assert f.read() == expected
Ejemplo n.º 5
0
def test_bash_with_shebang_expansion(tmp_path: Path):
    """ Tests expansion of a copyright header to a bash file. """
    path = _get_test_file(tmp_path,
                          'missing/existing_doc/bash_with_shebang.sh')
    expected = textwrap.dedent("""
    #!/usr/bin/bash
    #
    # Copyright 2020 Monty
    #
    # Some documentation
    
    echo "foo"
    """[1:])  # skip opening newline.
    copywriter.TxtFile(path).add('Copyright {year} Monty')
    with path.open() as f:
        assert f.read() == expected
Ejemplo n.º 6
0
def test_py_addition(tmp_path: Path):
    """ Tests addition of a copyright header to a cmake file. """
    path = _get_test_file(tmp_path, 'missing/no_doc/py.py')
    expected = textwrap.dedent("""
    \"\"\"
    Copyright 2020 Monty
    \"\"\"
    
    
    def foo(a, b):
        \"\"\"
        Adds a to b.
        \"\"\"
        return a + b
    """[1:])  # skip opening newline.
    copywriter.TxtFile(path).add('Copyright {year} Monty')
    with path.open() as f:
        content = f.read()
    assert content == expected
Ejemplo n.º 7
0
def test_c_header_addition(tmp_path: Path):
    """ Tests addition of a copyright header to a C/C++ source file. """
    path = _get_test_file(tmp_path, 'missing/no_doc/c.h')
    expected = textwrap.dedent("""
    /*
     * Copyright 2020 Monty
     */
    #include <stdio.h>
    
    
    /**
     * @brief Adds A to B.
     */
    int foo(int a, int b) {
        return a + b;
    }
    """[1:])  # skip opening newline.
    copywriter.TxtFile(path).add('Copyright {year} Monty')
    with path.open() as f:
        assert f.read() == expected
Ejemplo n.º 8
0
def test_py_with_shebang_expansion(tmp_path: Path):
    """ Tests expansion of a copyright header to a cmake file. """
    path = _get_test_file(tmp_path, 'missing/existing_doc/py_with_shebang.py')
    expected = textwrap.dedent("""
    #!/usr/bin/env/python3
    \"\"\"
    Copyright 2020 Monty

    Python file containing documentation.
    \"\"\"


    def foo(a, b):
        \"\"\"
        Adds a to b.
        \"\"\"
        return a + b
    """[1:])  # skip opening newline.
    copywriter.TxtFile(path).add('Copyright {year} Monty')
    with path.open() as f:
        content = f.read()
    assert content == expected
Ejemplo n.º 9
0
def test_copyright_header_is_found_in_c_line_comment():
    txt = copywriter.TxtFile(Path(SAMPLE, 'src', 'bar.c'))
    assert txt.copyright_str == 'Copyright 2018-2019 Bob'
Ejemplo n.º 10
0
def test_copyright_header_is_found_in_c_block_comment():
    txt = copywriter.TxtFile(Path(SAMPLE, 'src', 'foo.c'))
    assert txt.copyright_str == 'Copyright 2019-2020 Bob'
Ejemplo n.º 11
0
def test_copyright_header_is_found_in_py_comment():
    txt = copywriter.TxtFile(Path(SAMPLE, 'scripts', 'foo.py'))
    assert txt.copyright_str == 'Copyright 2019 - 2020 Bob'
Ejemplo n.º 12
0
def test_copyright_header_is_found_in_py_docstring():
    txt = copywriter.TxtFile(Path(SAMPLE, 'scripts', 'baz.py'))
    assert txt.copyright_str == 'Copyright 2019 Bob'
Ejemplo n.º 13
0
def test_copyright_header_is_found_in_bash():
    txt = copywriter.TxtFile(Path(SAMPLE, 'build.sh'))
    assert txt.copyright_str == 'Copyright 2019-2020 Bob'
Ejemplo n.º 14
0
def test_copyright_header_is_found_in_cmake():
    txt = copywriter.TxtFile(Path(SAMPLE, 'CMakeLists.txt'))
    assert txt.copyright_str == 'Copyright 2019-2020 Bob'
Ejemplo n.º 15
0
def test_format_detection():
    fmt = copywriter.TxtFile(Path(SAMPLE, 'scripts/baz.py')).format
    assert 'Copyright {year} Bob' == fmt