def test_lazy_format_class(): value = Lazy("{this[FOO]}/bar") settings = {"FOO": "foo"} assert value(settings) == "foo/bar" assert str(value) == value.value assert repr(value) == "'@{value.formatter} {value.value}'".format( value=value)
def test_unparse(): """Assert bare types are reversed cast""" assert unparse_conf_data("teste") == "teste" assert unparse_conf_data(123) == "@int 123" assert unparse_conf_data(123.4) == "@float 123.4" assert unparse_conf_data(False) == "@bool False" assert unparse_conf_data(True) == "@bool True" assert unparse_conf_data(["a", "b"]) == '@json ["a", "b"]' assert unparse_conf_data({"name": "Bruno"}) == '@json {"name": "Bruno"}' assert unparse_conf_data(None) == "@none " assert unparse_conf_data(Lazy("{foo}")) == "@format {foo}"
env="development", must_exist=True, when=Validator("BASE_IMAGE", must_exist=True, env=settings.ENV_FOR_DYNACONF), ), Validator( "IMAGE_4", "IMAGE_5", env=("development", "production"), must_exist=True, when=Validator("BASE_IMAGE", must_exist=False, env=settings.ENV_FOR_DYNACONF), ), Validator( "PORT", must_exist=True, ne=8000, when=Validator("MYSQL_HOST", eq="localhost"), ), Validator("A_DICT.NESTED_1.NESTED_2.NESTED_3.NESTED_4", must_exist=True, eq=1), Validator("A_DICT.NESTED_1.NOT.YET.LOADED", must_exist=True, eq=1), Validator("FOOBAR", default=Lazy(formatter=lambda x, **y: str(x))), ) # Validate settings except those that we don't want to validate yet settings.validators.validate(exclude="A_DICT.NESTED_1.NOT")
def test_try_to_encode(): value = Lazy("{this[FOO]}/bar") assert try_to_encode(value) == "@format {this[FOO]}/bar"
def test_lazy_format_is_json_serializable(): value = Lazy("{this[FOO]}/bar") assert ( json.dumps({"val": value}, cls=DynaconfEncoder) == '{"val": "@format {this[FOO]}/bar"}' )
def test_lazy_format_class_jinja(): value = Lazy("{{this['FOO']}}/bar", formatter=Formatters.jinja_formatter) settings = {"FOO": "foo"} assert value(settings) == "foo/bar"