| 
1 |  | -from pyconfigparser import ConfigParser, ConfigError, ConfigFileNotFoundError  | 
 | 1 | +from pyconfigparser import ConfigParser, ConfigError, ConfigFileNotFoundError, _is_variable  | 
2 | 2 | from config.schemas import SIMPLE_SCHEMA_CONFIG, UNSUPPORTED_OBJECT_KEYS_SCHEMA  | 
3 | 3 | import unittest  | 
4 | 4 | import os  | 
@@ -92,6 +92,33 @@ def assign_a_bad_type_ignore_unsetted_env_vars():  | 
92 | 92 |  self.assertIs(configparser.ignore_unset_env_vars, True)  | 
93 | 93 |  self.assertIsInstance(configparser.ignore_unset_env_vars, bool)  | 
94 | 94 | 
 
  | 
 | 95 | + def test_variable_pattern_matching(self) -> None:  | 
 | 96 | + """Test the regex pattern for environment variable matching."""  | 
 | 97 | + | 
 | 98 | + valid_env_vars = [  | 
 | 99 | + "$FOO",  | 
 | 100 | + "${FOO}",  | 
 | 101 | + "$My_Var123"  | 
 | 102 | + ]  | 
 | 103 | + | 
 | 104 | + invalid_env_vars = [  | 
 | 105 | + "FOO", # no $  | 
 | 106 | + "$", # missing name  | 
 | 107 | + "${}", # empty braces  | 
 | 108 | + "$1VAR", # starts with number  | 
 | 109 | + "${1VAR}", # starts with number in braces  | 
 | 110 | + "foo$VAR", # not at start  | 
 | 111 | + "<L/f\\U<Uj2{.S95@^$Rx" # random password  | 
 | 112 | + ]  | 
 | 113 | + | 
 | 114 | + for var in valid_env_vars:  | 
 | 115 | + with self.subTest(var=var):  | 
 | 116 | + self.assertTrue(_is_variable(var), f"{var} should match")  | 
 | 117 | + | 
 | 118 | + for var in invalid_env_vars:  | 
 | 119 | + with self.subTest(var=var):  | 
 | 120 | + self.assertFalse(_is_variable(var), f"{var} should not match")  | 
 | 121 | + | 
95 | 122 | 
 
  | 
96 | 123 | if __name__ == '__main__':  | 
97 | 124 |  unittest.main()  | 
0 commit comments