Example #1
0
    def test_load_config_from_file_empty_string_does_nothing(
            self, mock_filename):
        main = MainFrame()
        save_config({'probability_plural_noun': 0.0})
        main.load_config()

        current_state = main.get_state()

        mock_filename.return_value = ''
        main.load_config_from_file()
        self.assertEqual(current_state, main.get_state())
Example #2
0
    def test_init_button_assignment_load_config(self, mock_filename):
        filename = os.path.join(TESTS_FILES, 'tst.cfg')
        mock_filename.return_value = filename
        save_config_to_filename({'file_prefix': 'silly'}, filename)

        main = MainFrame()
        action_frame = get_action_frame(main)

        default = main.get_state()

        main.load_config_from_file()
        self.assertNotEqual(default, main.get_state())

        action_frame.reload_config.invoke()
        self.assertEqual(default, main.get_state())

        os.remove(filename)
Example #3
0
    def test_load_config_from_file_loads_from_file(self, mock_filename):
        filename = os.path.join(TESTS_FILES, 'tst.cfg')

        mock_filename.return_value = filename

        save_config_to_filename({'probability_plural_noun': 0.0}, filename)

        main = MainFrame()
        default_state = main.get_state()

        main.load_config_from_file()

        self.assertNotEqual(main.get_state(), default_state)

        loader = ConfigLoader()
        loader.set_state_from_file(filename)
        self.assertEqual(loader.state, main.get_state())

        os.remove(filename)
Example #4
0
    def test_load_config_from_file_bad_file_without_reset(
            self, mock_filename, mock_error):
        filename = os.path.join(TESTS_FILES, 'tst.cfg')
        bad_path = os.path.join(TESTS_FILES, 'nope', 'really_nope')

        mock_filename.return_value = filename

        save_config_to_filename({'save_directory': bad_path}, filename)

        main = MainFrame()
        save_config({'probability_plural_noun': 0.0})
        main.load_config()
        current_state = main.get_state()

        main.load_config_from_file()

        self.assertEqual(main.get_state(), current_state)
        self.assertEqual(mock_error.call_args[0][0], 'bad config file')
        msg = "ConfigFileError: Config Loader failed to create the following directory:\n"
        self.assertIn(msg, mock_error.call_args[0][1])

        os.remove(filename)
Example #5
0
    def test_load_config_from_file_bad_file_with_reset(self, mock_filename,
                                                       mock_error):
        filename = os.path.join(TESTS_FILES, 'tst.cfg')

        mock_filename.return_value = filename

        save_config_to_filename({'probability_plural_noun': 'oops'}, filename)

        main = MainFrame()
        default_state = main.get_state()
        save_config({'probability_plural_noun': 0.0})
        main.load_config()

        main.load_config_from_file()

        self.assertEqual(main.get_state(), default_state)
        mock_error.assert_called_with(
            'bad config file',
            "ConfigFileError: Tried to set key: 'probability_plural_noun' to incompatible value: 'oops'."
        )

        os.remove(filename)