Exemple #1
0
def test_toml_misconfiguration_handling(capsys, config_file_contents,
                                        message_part):
    with tempfile.NamedTemporaryFile(mode="w+", suffix=".toml") as config_file:
        config_file.write(config_file_contents)
        config_file.seek(0)

        with pytest.raises(SystemExit, match="2"):
            extract_django_settings_module(config_file.name)

    error_message = "usage: " + TEMPLATE_TOML.format(message_part)
    assert error_message == capsys.readouterr().err
def test_misconfiguration_handling(capsys, config_file_contents, message_part):
    #  type: (typing.Any, typing.List[str], str) -> None
    """Invalid configuration raises `SystemExit` with a precise error message."""
    with tempfile.NamedTemporaryFile(mode='w+') as config_file:
        if not config_file_contents:
            config_file.close()
        else:
            config_file.write('\n'.join(config_file_contents).expandtabs(4))
            config_file.seek(0)

        with pytest.raises(SystemExit, match='2'):
            extract_django_settings_module(config_file.name)

    error_message = TEMPLATE.format(message_part)
    assert error_message == capsys.readouterr().err
def test_correct_configuration() -> None:
    """Django settings module gets extracted given valid configuration."""
    config_file_contents = [
        '[mypy.plugins.django-stubs]',
        '\tsome_other_setting = setting',
        '\tdjango_settings_module = my.module',
    ]
    with tempfile.NamedTemporaryFile(mode='w+') as config_file:
        config_file.write('\n'.join(config_file_contents).expandtabs(4))
        config_file.seek(0)

        extracted = extract_django_settings_module(config_file.name)

    assert extracted == 'my.module'
Exemple #4
0
def test_correct_toml_configuration() -> None:
    config_file_contents = """
    [tool.django-stubs]
    some_other_setting = "setting"
    django_settings_module = "my.module"
    """

    with tempfile.NamedTemporaryFile(mode="w+", suffix=".toml") as config_file:
        config_file.write(config_file_contents)
        config_file.seek(0)

        extracted = extract_django_settings_module(config_file.name)

    assert extracted == "my.module"
Exemple #5
0
    def __init__(self, options: Options) -> None:
        super().__init__(options)

        django_settings_module = mypy_django_main.extract_django_settings_module(
            options.config_file)
        self.django_context = DjangoContext(django_settings_module)