@@ -31,6 +31,42 @@ def test_option_default_none(config):
3131 assert config .option () is None
3232
3333
34+ def test_as_ (config ):
35+ config .from_env ("CONFIG_INT" , as_ = int )
36+ assert config () == 42
37+ assert isinstance (config (), int )
38+
39+
40+ def test_as__default (config ):
41+ config .from_env ("UNDEFINED" , as_ = int , default = "33" )
42+ assert config () == 33
43+ assert isinstance (config (), int )
44+
45+
46+ def test_as__undefined_required (config ):
47+ with raises (ValueError ):
48+ config .from_env ("UNDEFINED" , as_ = int , required = True )
49+ assert config () == {}
50+
51+
52+ def test_option_as_ (config ):
53+ config .option .from_env ("CONFIG_INT" , as_ = int )
54+ assert config .option () == 42
55+ assert isinstance (config .option (), int )
56+
57+
58+ def test_option_as__default (config ):
59+ config .option .from_env ("UNDEFINED" , as_ = int , default = "33" )
60+ assert config .option () == 33
61+ assert isinstance (config .option (), int )
62+
63+
64+ def test_option_as__undefined_required (config ):
65+ with raises (ValueError ):
66+ config .option .from_env ("UNDEFINED" , as_ = int , required = True )
67+ assert config .option () is None
68+
69+
3470@mark .parametrize ("config_type" , ["strict" ])
3571def test_undefined_in_strict_mode (config ):
3672 with raises (ValueError ):
0 commit comments