예제 #1
0
 def test_load_config_saved(self):
     m = mock.Mock()
     loader = m.a()
     cm = ConfigMixin()
     cm.add_config_item(key="test-int", saver=lambda: 123, loader=loader, default=456)
     with temporary_path() as tmp:
         cm.config_path = tmp.joinpath("config")
         cm.save_config()
         cm.load_config()
         self.assertTrue(loader.called)
         self.assertTrue(loader.called_with('123'))
예제 #2
0
 def test_load_config_default_no_file(self):
     m = mock.Mock()
     loader = m.a()
     cm = ConfigMixin()
     cm.add_config_item(key="test-int", saver=lambda: 123, loader=loader, default=456)
     with temporary_path() as tmp:
         cm.config_path = tmp.joinpath("config")
         cm.load_config()
         self.assertTrue(loader.called)
         # not yet saved, should be called with default value
         self.assertTrue(loader.called_with('456'))
예제 #3
0
    def test_load_config_errors(self):
        def loader_with_errors(value: int):  # noqa
            raise RuntimeError

        cm = ConfigMixin()
        cm.add_config_item(key="test-int", saver=lambda: 123, loader=loader_with_errors, default=456)
        with temporary_path() as tmp:
            cm.config_path = tmp.joinpath("config")
            cm.save_config()
            try:
                cm.load_config()
            except RuntimeError:
                self.fail("No errors should be raised.")