def setUpClass(cls): # Run in tmp cls.tmpdir = tempfile.TemporaryDirectory(prefix="vimiv-tests-") os.environ["XDG_DATA_HOME"] = cls.tmpdir.name cls.trash_manager = trash_manager.TrashManager() cls.files_directory = os.path.join(get_user_data_dir(), "Trash/files") cls.info_directory = os.path.join(get_user_data_dir(), "Trash/info") cls.testfile = "" cls.basename = ""
def __init__(self, app): """Create the necessary objects and settings. Args: app: The main vimiv application to interact with. """ datadir = os.path.join(get_user_data_dir(), "vimiv") os.makedirs(datadir, exist_ok=True) self._filename = os.path.join(datadir, "vimiv.log") self._terminal = sys.stderr # Redirect stderr in debug mode so it is written to the log file as well if app.debug: sys.stderr = self # Create a new log file at startup with open(self._filename, "w") as f: f.write("Vimiv log written to " + self._filename.replace(os.getenv("HOME"), "~") + "\n") self._write_separator() # Header containing version and Gtk version self.write_message("Version", app["information"].get_version()) self.write_message("Python", sys.version.split()[0]) gtk_version = str(Gtk.get_major_version()) + "." \ + str(Gtk.get_minor_version()) + "." \ + str(Gtk.get_micro_version()) self.write_message("GTK", gtk_version) self._write_separator() # Start time self.write_message("Started", "time")
def test_empty_directory(self): """Move in and out of an empty directory.""" tmpdir = tempfile.TemporaryDirectory(dir=get_user_data_dir()) self.lib.move_up(tmpdir.name) self.assertEqual(os.getcwd(), tmpdir.name) self.check_statusbar("WARNING: Directory is empty") # Check if exception is caught properly self.lib.scroll("l") self.check_statusbar("ERROR: No file to select") self.lib.scroll("h") self.assertEqual(os.getcwd(), os.path.dirname(tmpdir.name)) tmpdir.cleanup()
def __init__(self, app): """Create the necessary objects and settings. Args: app: The main vimiv application to interact with. """ super(CommandLine, self).__init__() self._app = app self.commands = None # Command line self.connect("activate", self._on_activate) self.connect("key_press_event", self._app["eventhandler"].on_key_press, "COMMAND") self.connect("changed", self._on_text_changed) self.set_hexpand(True) # Initialize search self.search = Search(self) # Cmd history from file datadir = os.path.join(get_user_data_dir(), "vimiv") os.makedirs(datadir, exist_ok=True) # If there is a history file in the old location move it and inform the # user # TODO remove this in a new version, assigned for 0.10 old_histfile = os.path.expanduser("~/.vimiv/history") new_histfile = os.path.join(datadir, "history") if os.path.isfile(old_histfile): if os.path.isfile(new_histfile): message = "There is a history file in the deprecated location" \ " %s and the new location %s. Using the new one. If you " \ "want the history from the old file you will have to " \ "merge it manually." % (old_histfile, new_histfile) error_message(message, running_tests=self._app.running_tests) else: os.rename(old_histfile, new_histfile) message = "Moved the old history file %s " \ "to the new location %s." % (old_histfile, new_histfile) error_message(message, running_tests=self._app.running_tests) self._history = read_file(os.path.join(datadir, "history")) # Defaults self._matching_history = [] self._last_index = 0 self._pos = 0 self.running_processes = [] self._last_widget = ""
def test_path(self): """Enter a path in the commandline.""" # Pass a directory expected_dir = os.path.abspath("./vimiv/testimages") self.run_command("./vimiv/testimages") dir_after = os.getcwd() self.assertEqual(expected_dir, dir_after) # Pass an image expected_image = os.path.abspath("arch-logo.png") self.run_command("./arch-logo.png") refresh_gui() self.assertEqual(self.vimiv.get_path(), expected_image) # Pass an image in another directory testimage = tempfile.NamedTemporaryFile(dir=get_user_data_dir()) shutil.copyfile(expected_image, testimage.name) self.run_command(testimage.name) refresh_gui() self.assertEqual(self.vimiv.get_path(), testimage.name) self.assertEqual(os.getcwd(), os.path.dirname(testimage.name))
def __init__(self): """Create a new TrashManager.""" self.files_directory = os.path.join(get_user_data_dir(), "Trash/files") self.info_directory = os.path.join(get_user_data_dir(), "Trash/info") os.makedirs(self.files_directory, exist_ok=True) os.makedirs(self.info_directory, exist_ok=True)
def setUpClass(cls): cls.init_test(cls) cls.tagdir = os.path.join(get_user_data_dir(), "vimiv", "Tags")
def write_history(self): """Write commandline history to file.""" histfile = os.path.join(get_user_data_dir(), "vimiv", "history") with open(histfile, "w") as f: for cmd in self._history: f.write(cmd + "\n")
def setUpClass(cls): cls.init_test(cls, debug=True) cls.logfile = os.path.join(get_user_data_dir(), "vimiv", "vimiv.log")