def write_test_file(file_name='test_dir' + os.sep + 'test.csv'):
        csv_file = CsvFileHandle(file_name)

        # dict1['corrected_guess'] > dict2['corrected_guess']
        dict1 = OrderedDict(spanish='ayudar',english='to help',correct_guesses='3')
        dict2 = OrderedDict(spanish='buscar',english='to search',correct_guesses='1')
        test_list = [dict1,dict2]

        csv_file.write(test_list)
    def test_csvfilehandle_write(self):
        clean_test_dir()
        write_example_csv()
        csv_file = CsvFileHandle('test_dir/example.csv')
        csv_list = csv_file.read()

        clean_test_dir()
        csv_file.write(csv_list)

        with open('test_dir/example.csv', 'r') as f:
            text = f.read()

        expected = 'spanish,english,correct_guesses\nayudar,to help,0\nbuscar,to search,0\n'
        self.assertEqual(expected, text)
    def test_csvfilehandle_read(self):
        clean_test_dir()
        write_example_csv()
        dict1 = OrderedDict(spanish='ayudar',
                            english='to help',
                            correct_guesses='0')
        dict2 = OrderedDict(spanish='buscar',
                            english='to search',
                            correct_guesses='0')
        expected_list = [dict1, dict2]

        csv_file = CsvFileHandle('test_dir/example.csv')
        csv_list = csv_file.read()
        self.assertListEqual(expected_list, csv_list)
    def test_write_word_list(self):
        clean_test_dir()
        write_test_file()

        loop = vocabulario.SpanishCmd('test_dir' + os.sep + 'test.csv')
        loop.word_list[0]['correct_guesses'] = 8
        loop.write_word_list()

        csv_file = CsvFileHandle('test_dir' + os.sep + 'test.csv')

        dict1 = OrderedDict(spanish='ayudar',english='to help',correct_guesses='8')
        dict2 = OrderedDict(spanish='buscar',english='to search',correct_guesses='1')
        expected = [dict1,dict2]

        self.assertListEqual(expected, csv_file.read())
Esempio n. 5
0
 def __init__(self, file_name='words'+ os.sep+ 'countedwords.csv'):
     super().__init__()
     self.file_name=file_name
     csv_file = CsvFileHandle(file_name=file_name)
     self.word_list= csv_file.read()
Esempio n. 6
0
 def write_word_list(self):
     """ write self.word_list info to a file """
     file_name = self.file_name
     csv_file = CsvFileHandle(file_name)
     csv_file.write(self.word_list)
Esempio n. 7
0
 def load_word_list(self):
     """ allow for loading an alternate word list """
     file_name = self.file_name
     csv_file = CsvFileHandle(file_name)
     self.word_list = csv_file.read()