Beispiel #1
0
    def test_change_file_bad_file_by_config(self, mock_error):
        bad_file = os.path.join(DATA_PATH, 'go_time.ico')
        main = MainFrame()
        for count, key in enumerate(
            ('countable_nouns', 'uncountable_nouns', 'verbs')):
            self.assertEqual(mock_error.call_count, count)
            main.revert_to_original()
            save_config({key: bad_file})

            main.load_config()
            message = (
                'LoaderError: Could not read CSV file. ' +
                'If you edited it in MSWord or something similar, it got formatted. Use "notepad"'
            )
            mock_error.assert_called_with('Bad file', message)
            self.assertEqual(mock_error.call_count, count + 1)
Beispiel #2
0
    def test_revert_to_original(self):
        ConfigLoader()  # set up directories

        save_config({'probability_pronoun': 0})
        with open(DEFAULT_CONFIG, 'r') as default:
            with open(CONFIG_FILE, 'r') as current:
                self.assertNotEqual(default.read(), current.read())

        verb_file = os.path.join(APP_FOLDER, VERBS_CSV)
        with open(verb_file, 'w') as f:
            f.write('go')
        main = MainFrame()
        main.revert_to_original()
        with open(DEFAULT_CONFIG, 'r') as default:
            with open(CONFIG_FILE, 'r') as current:
                self.assertEqual(default.read(), current.read())
        with open(os.path.join(DATA_PATH, VERBS_CSV), 'r') as default:
            with open(verb_file, 'r') as current:
                self.assertEqual(default.read(), current.read())
Beispiel #3
0
    def test_change_file_bad_file_showerror_called_on_value_change(
            self, mock_error):

        bad_file = os.path.join(DATA_PATH, 'go_time.ico')
        main = MainFrame()
        files_frame = None
        for child in main.winfo_children():
            if isinstance(child, FileManagement):
                files_frame = child
        for count, key in enumerate(
            ('countable_nouns', 'uncountable_nouns', 'verbs')):
            self.assertEqual(mock_error.call_count, count)
            main.revert_to_original()
            files_frame.set_variable(key, bad_file)

            message = (
                'LoaderError: Could not read CSV file. ' +
                'If you edited it in MSWord or something similar, it got formatted. Use "notepad"'
            )
            mock_error.assert_called_with('Bad file', message)
            self.assertEqual(mock_error.call_count, count + 1)