示例#1
0
    def test_export_config_file_no_save(self, mock_filename, mock_save_config):
        filename = os.path.join(TESTS_FILES, 'tst.cfg')

        mock_filename.return_value = filename

        main = MainFrame()
        main.export_config_file()
        self.assertEqual(mock_save_config.call_count, 1)

        mock_filename.return_value = ''

        main.export_config_file()
        self.assertEqual(mock_save_config.call_count, 1)
示例#2
0
    def test_export_config_file_saves_correctly(self, mock_filename):
        filename = os.path.join(TESTS_FILES, 'tst.cfg')

        if os.path.exists(filename):
            os.remove(filename)

        main = MainFrame()
        default_state = main.get_state()
        save_config({'font_size': 15})
        main.load_config()
        current_state = main.get_state()

        ConfigLoader().revert_to_default()

        config_state = ConfigLoader().state
        expected_state = config_state.copy()
        expected_state['font_size'] = 15

        # test current state
        self.assertEqual(default_state, config_state)
        self.assertEqual(current_state, expected_state)
        self.assertNotEqual(default_state, current_state)

        mock_filename.return_value = filename
        main.export_config_file()

        saved_config = ConfigLoader()
        saved_config.set_state_from_file(filename)
        config_file_state = ConfigLoader().state

        self.assertEqual(saved_config.state, current_state)
        self.assertEqual(main.get_state(), current_state)
        self.assertEqual(config_file_state, default_state)

        mock_filename.assert_called_with(
            initialdir=current_state['home_directory'],
            title='select .cfg file',
            initialfile='exported_config.cfg',
            defaultextension='.cfg')
        os.remove(filename)