def test_config_operators(): """ Test the `log_config`, `clear_config`, `add_config` and `get_config` together. It's difficult to test them alone. """ @configurable def configured(arg): pass assert len(get_config()) == 0 add_config({configured: HParams()}) log_config() # Smoke test assert len(get_config()) == 1 clear_config() assert len(get_config()) == 0
def test_merge_configs(): """ Test the merging of two configurations via `add_config`. """ @configurable def configured(arg, arg_two): pass @configurable def other_configured(arg): pass clear_config() add_config({configured: HParams(arg='arg', arg_two='arg_two')}) add_config({other_configured: HParams()}) assert len(get_config()) == 2 assert get_config()[_get_function_signature(configured.__wrapped__)]['arg'] == 'arg' add_config({configured: HParams(arg='gra')}) assert len(get_config()) == 2 assert get_config()[_get_function_signature(configured.__wrapped__)]['arg'] == 'gra' assert get_config()[_get_function_signature(configured.__wrapped__)]['arg_two'] == 'arg_two' clear_config()
def test_add_config__empty(): """ Test if `add_config` works with an empty config. """ clear_config() add_config({}) assert {} == get_config()
def run_before_test(): # Reset the global state before every test clear_config() set_lazy_resolution(False) yield