Ejemplo n.º 1
0
 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"
Ejemplo n.º 2
0
 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"
Ejemplo n.º 3
0
 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"
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
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"
Ejemplo n.º 6
0
 def test_keyerror(self):
     config = Config()
     with pytest.raises(KeyError):
         config["foo"]
Ejemplo n.º 7
0
 def test_default_attrs(self):
     config = Config()
     assert config.file == ""
     assert config._dict == {}
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
 def test_replace_env(self):
     var = Mock(name="re_var", group=Mock(return_value="foo"))
     value = Config._replace_env(var)
     assert value == "bar"