def test_vdf_parsing(self, file): """Tests that parsing and regenerating a vdf file generates the same contents""" path = os.path.join(vdfs_folder, file) file_contents = open(path, "r").read() shortcuts = ShortcutParser().parse(path) generated_contents = ShortcutGenerator().to_string(shortcuts) self.assertEqual(file_contents.lower(), generated_contents.lower())
def test_vdf_parsing(self, file): """Tests that parsing and regenerating a vdf file generates the same contents""" path = os.path.join(vdfs_folder, file) file_contents = open(path,"r").read() shortcuts = ShortcutParser().parse(path) generated_contents = ShortcutGenerator().to_string(shortcuts) self.assertEqual(file_contents.lower(),generated_contents.lower())
def save_shortcuts(self, path=None, makedirs=True): if path is None: path = self.shortcuts_file() parent_directory = os.path.dirname(path) if not os.path.isdir(parent_directory) and makedirs: try: os.makedirs(parent_directory) except OSError: raise OSError("Cannot write to directory `%s`." % parent_directory) # Write shortcuts to file try: contents = ShortcutGenerator().to_string(self.shortcuts) with open(path, "w") as f: f.write(contents) except IOError: raise IOError("Cannot save file to `%s`. Permission Denied")
def test_file_equality(self): file_contents = open(path,"r").read() shortcuts = ShortcutParser().parse(path) generated_contents = ShortcutGenerator().to_string(shortcuts) self.assertEqual(file_contents.lower(),generated_contents.lower())