def test_getitem(self): m_open = mock_open( read_data=("foo: bar\n" "checklist file: nowcast_checklist.yaml\n" "python: python\n" "logging:\n" " handlers: []")) config = Config() with patch("nemo_nowcast.config.open", m_open): config.load("nowcast.yaml") assert config["foo"] == "bar"
def test_set_no_key_default_value(self): m_open = mock_open( read_data=("foo: bar\n" "checklist file: nowcast_checklist.yaml\n" "python: python\n" "logging:\n" " handlers: []")) config = Config() with patch("nemo_nowcast.config.open", m_open): config.load("nowcast.yaml") assert config.get("bar", default="baz") == "baz"
def test_replace_python_interpreter_envvar(self): m_open = mock_open( read_data=("foo: bar\n" "checklist file: nowcast_checklist.yaml\n" "python: $(NOWCAST.ENV.foo)/bin/python\n" "logging:\n" " handlers: []")) config = Config() config._replace_env = Mock(return_value="bar") with patch("nemo_nowcast.config.open", m_open): config.load("nowcast.yaml") assert config["python"] == "bar/bin/python"
def test_ignore_log_stream_handler(self): m_open = mock_open( read_data=("foo: bar\n" "checklist file: nowcast_checklist.yaml\n" "python: python\n" "logging:\n" " handlers:\n" " console: {}")) config = Config() config._replace_env = Mock(return_value="bar") with patch("nemo_nowcast.config.open", m_open): config.load("nowcast.yaml") assert config._replace_env.call_count == 0
def test_replace_log_file_envvar_local_logging(self): m_open = mock_open( read_data=("foo: bar\n" "checklist file: nowcast_checklist.yaml\n" "python: python\n" "logging:\n" " handlers:\n" " info_test:\n" " filename: $(NOWCAST.ENV.foo)/nowcast.log")) config = Config() config._replace_env = Mock(return_value="bar") with patch("nemo_nowcast.config.open", m_open): config.load("nowcast.yaml") filename = config["logging"]["handlers"]["info_test"]["filename"] assert filename == "bar/nowcast.log"
def test_keyerror(self): config = Config() with pytest.raises(KeyError): config["foo"]
def test_default_attrs(self): config = Config() assert config.file == "" assert config._dict == {}
def test_envvar_not_set(self): var = Mock(name="re_var", group=Mock(return_value="foo")) with pytest.raises(KeyError): value = Config._replace_env(var)
def test_replace_env(self): var = Mock(name="re_var", group=Mock(return_value="foo")) value = Config._replace_env(var) assert value == "bar"