def test_write_lines(self):
        lines = 'Hello world'
        path = 'test.txt'
        FileHandler.write_lines(path, lines)

        with open(path, mode='r') as test_file:
            data = test_file.read()
            self.assertIsNotNone(data)
Example #2
0
 def query_definition(self, word):
     word = word.lower()
     found = self.dict.get(word)
     if found is None:
         close_matches = difflib.get_close_matches(word, self.dict.keys())
         return f'Match not Found.\nInstead try: {close_matches}'
     else:
         found_str = Dictionary.get_as_str(found)
         FileHandler.write_lines('Queries.txt',
                                 word + ': ' + found_str + '\n')
         return found_str
Example #3
0
 def query_definition(self, key):
     """
     Searches for key in dictionary and returns it's definition(s) if found
     :param key: search term
     :return: definition of search term or "key not found" if not found
     """
     search_key = key.lower()
     for dict_key in self._dictionary.keys():
         if str(dict_key).lower() == search_key:
             print("Key found")
             FileHandler.write_lines(self._out_path,
                                     [dict_key, self._dictionary[dict_key]])
             return self._dictionary[dict_key]
     print("Key not found")
     return "Key not found"
Example #4
0
 def test_init(self):
     path = "/Users/Iangs/Desktop/UnitTestOutput.txt"
     text = ["test", "success"]
     FileHandler.write_lines(path, text)
     file_exists = Path(path).is_file()
     self.assertEqual(file_exists, True)