<commit_before>import os

from dynaconf import LazySettings


def test_dynaconf_namespace_renamed(tmpdir):
    settings = LazySettings(
        DYNACONF_NAMESPACE="FOO",
        DYNACONF_SETTINGS_MODULE="foo.py",
        SETTINGS_MODULE="foo.py",
        PROJECT_ROOT=str(tmpdir),
        DYNACONF_SILENT_ERRORS=True,
        DYNACONF_ALWAYS_FRESH_VARS=["BAR"],
    )

    assert settings.ENV_FOR_DYNACONF == "FOO"
    assert settings.SETTINGS_FILE_FOR_DYNACONF == "foo.py"
    assert settings.ROOT_PATH_FOR_DYNACONF == str(tmpdir)
    assert settings.SILENT_ERRORS_FOR_DYNACONF is True
    assert settings.FRESH_VARS_FOR_DYNACONF == ["BAR"]


def test_namespace_for_dynaconf_renamed(tmpdir):
    settings = LazySettings(
        NAMESPACE_FOR_DYNACONF="FOO",
        DYNACONF_SETTINGS_MODULE="foo.py",
        SETTINGS_MODULE="foo.py",
        PROJECT_ROOT_FOR_DYNACONF=str(tmpdir),
        DYNACONF_SILENT_ERRORS=True,
        DYNACONF_ALWAYS_FRESH_VARS=["BAR"],
    )

    assert settings.ENV_FOR_DYNACONF == "FOO"
    assert settings.SETTINGS_FILE_FOR_DYNACONF == "foo.py"
    assert settings.ROOT_PATH_FOR_DYNACONF == str(tmpdir)
    assert settings.SILENT_ERRORS_FOR_DYNACONF is True
    assert settings.FRESH_VARS_FOR_DYNACONF == ["BAR"]


def test_envvar_prefix_for_dynaconf(tmpdir):
    os.environ["AWESOMEAPP_FOO"] = "1"
    os.environ["AWESOMEAPP_BAR"] = "false"
    os.environ["AWESOMEAPP_LIST"] = '["item1", "item2"]'
    os.environ["AWESOMEAPP_FLOAT"] = "42.2"

    settings = LazySettings(ENVVAR_PREFIX_FOR_DYNACONF="AWESOMEAPP")

    assert settings.FOO == 1
    assert settings.BAR is False
    assert settings.LIST == ["item1", "item2"]
    assert settings.FLOAT == 42.2

    settings2 = LazySettings(GLOBAL_ENV_FOR_DYNACONF="AWESOMEAPP")

    assert settings2.FOO == 1
    assert settings2.BAR is False
    assert settings2.LIST == ["item1", "item2"]
    assert settings2.FLOAT == 42.2<commit_msg>Hide DeprecationWarning from Pytest when testing for them (#186)<commit_after>import os

import pytest

from dynaconf import LazySettings


@pytest.mark.parametrize(
    "deprecated,value,new",
    [
        ("DYNACONF_NAMESPACE", "FOO", "ENV_FOR_DYNACONF"),
        ("NAMESPACE_FOR_DYNACONF", "FOO", "ENV_FOR_DYNACONF"),
        ("DYNACONF_SETTINGS_MODULE", "foo.py", "SETTINGS_FILE_FOR_DYNACONF"),
        ("SETTINGS_MODULE", "foo.py", "SETTINGS_FILE_FOR_DYNACONF"),
        ("PROJECT_ROOT", "./", "ROOT_PATH_FOR_DYNACONF"),
        ("DYNACONF_SILENT_ERRORS", True, "SILENT_ERRORS_FOR_DYNACONF"),
        ("DYNACONF_ALWAYS_FRESH_VARS", ["BAR"], "FRESH_VARS_FOR_DYNACONF"),
        ("GLOBAL_ENV_FOR_DYNACONF", "MYAPP", "ENVVAR_PREFIX_FOR_DYNACONF"),
        ("BASE_NAMESPACE_FOR_DYNACONF", "THIS", "DEFAULT_ENV_FOR_DYNACONF"),
    ],
)
def test_dynaconf_namespace_renamed(tmpdir, recwarn, deprecated, value, new):
    settings = LazySettings(**{deprecated: value})

    assert len(recwarn) == 1
    assert issubclass(recwarn[0].category, DeprecationWarning)
    assert deprecated in str(recwarn[0].message)
    assert new in str(recwarn[0].message)
    assert settings.get(new) == value


def test_envvar_prefix_for_dynaconf(tmpdir, recwarn):
    os.environ["AWESOMEAPP_FOO"] = "1"
    os.environ["AWESOMEAPP_BAR"] = "false"
    os.environ["AWESOMEAPP_LIST"] = '["item1", "item2"]'
    os.environ["AWESOMEAPP_FLOAT"] = "42.2"

    settings = LazySettings(ENVVAR_PREFIX_FOR_DYNACONF="AWESOMEAPP")

    assert settings.FOO == 1
    assert settings.BAR is False
    assert settings.LIST == ["item1", "item2"]
    assert settings.FLOAT == 42.2

    settings2 = LazySettings(GLOBAL_ENV_FOR_DYNACONF="AWESOMEAPP")

    assert len(recwarn) == 1
    assert issubclass(recwarn[0].category, DeprecationWarning)
    assert "GLOBAL_ENV_FOR_DYNACONF" in str(recwarn[0].message)

    assert settings2.FOO == 1
    assert settings2.BAR is False
    assert settings2.LIST == ["item1", "item2"]
    assert settings2.FLOAT == 42.2
{'fraction_non_alphanumeric': 0.1214049376431662, 'fraction_numerical': 0.014252990582845508, 'mean_word_length': 4.346938775510204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4783557', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1416, 'n_words': 224}