Issues (17)

tests/test_license_file.py (2 issues)

1
"""
2
License file testing module for the generated project.
3
"""
4
import datetime
5
import os
6
from . import bake_cookie, load_cookiecutter_json
7
8
9
def test_license_file_exists(cookies):
10
    "Check that the LICENSE file exists"
11
    with bake_cookie(cookies) as result:
12
        license_file_path = result.project_path.joinpath("LICENSE.rst")
13
        assert os.path.exists(license_file_path)
14
15
16
def test_licenses_dir_not_present(cookies):
17
    "Check that the LICENSES dir is removed"
18
    with bake_cookie(cookies) as result:
19
        licenses_dir_path = result.project_path.joinpath("LICENSES")
20
        assert not os.path.exists(licenses_dir_path)
21
22
23
def test_bake_selecting_license(cookies):
24
    """
25
    Test all licenses that the project can generate and make sure they contain
26
    known strings.
27
    """
28
    supported_licenses = load_cookiecutter_json()["project_license"]
29
    now = datetime.datetime.now()
30
31
    for license in supported_licenses:
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in license.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
32
        with bake_cookie(cookies, extra_context={"project_license": license}) as result:
33
            license_file_path = result.project_path.joinpath("LICENSE.rst")
34
35
            with open(license_file_path, "r") as fp:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "fp" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
36
                license_file = fp.read()
37
                license_file_lines = license_file.splitlines()
38
39
            if license == "Proprietary":
40
                assert "All rights reserved." in license_file_lines[3]
41
            else:
42
                assert license in license_file_lines[2]
43
44
            assert (
45
                f"license = {license}"
46
                in result.project_path.joinpath("setup.cfg").read_text()
47
            )
48
49
            assert str("Cookie Baker") in license_file
50
            assert str("[email protected]") in license_file
51
            assert str(now.year) in license_file
52