示例#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"
示例#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"
示例#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"
示例#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
示例#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"
示例#6
0
 def test_keyerror(self):
     config = Config()
     with pytest.raises(KeyError):
         config["foo"]
示例#7
0
 def test_default_attrs(self):
     config = Config()
     assert config.file == ""
     assert config._dict == {}
示例#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)
示例#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"