Rename test function & fix a bug with default value handling

This commit is contained in:
Jeff Epler 2022-12-09 14:35:50 -06:00
parent 040fac0724
commit 6dca9db225
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE
2 changed files with 6 additions and 6 deletions

View File

@ -421,11 +421,11 @@ STATIC void set_sys_argv(char *argv[], int argc, int start_arg) {
#endif
mp_obj_t common_hal_os_getenv_path(const char *path, const char *key, mp_obj_t default_);
STATIC mp_obj_t get_key(mp_obj_t path_in, mp_obj_t key_to_get_in) {
STATIC mp_obj_t getenv_from_file(mp_obj_t path_in, mp_obj_t key_to_get_in) {
return common_hal_os_getenv_path(mp_obj_str_get_str(path_in),
mp_obj_str_get_str(key_to_get_in), mp_const_none);
mp_obj_str_get_str(key_to_get_in), default_);
}
MP_DEFINE_CONST_FUN_OBJ_2(get_key_obj, get_key);
MP_DEFINE_CONST_FUN_OBJ_2(getenv_from_file_obj, get_key);
MP_NOINLINE int main_(int argc, char **argv);
@ -547,7 +547,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
MP_DECLARE_CONST_FUN_OBJ_0(extra_cpp_coverage_obj);
mp_store_global(MP_QSTR_extra_coverage, MP_OBJ_FROM_PTR(&extra_coverage_obj));
mp_store_global(MP_QSTR_extra_cpp_coverage, MP_OBJ_FROM_PTR(&extra_cpp_coverage_obj));
mp_store_global(MP_QSTR_get_key, MP_OBJ_FROM_PTR(&get_key_obj));
mp_store_global(MP_QSTR_getenv_from_file, MP_OBJ_FROM_PTR(&getenv_from_file_obj));
}
#endif

View File

@ -1,7 +1,7 @@
import os
try:
get_key
getenv_from_file
except NameError:
# Because run-tests.py suppresses site-packages, this test can't be run
# on the host interpreter. However, it can be run manually to
@ -10,7 +10,7 @@ except NameError:
# After 3.11 becomes standard, change this to use tomllib.
import tomlkit
def get_key(filename, key):
def getenv_from_file(filename, key):
with open(filename) as f:
s = tomlkit.load(f)
return s.get(key, None)