Esempio n. 1
0
 def test_zoom(self):
     """Zoom in thumbnail mode."""
     # Zoom to the value of 128
     while self.thumb.get_zoom_level()[0] > 128:
         self._zoom_wrapper(False)
     while self.thumb.get_zoom_level()[0] < 128:
         self._zoom_wrapper(True)
     self.assertEqual(self.thumb.get_zoom_level(), (128, 128))
     # Zoom in and check thumbnail size and pixbuf
     self._zoom_wrapper(True)
     self.assertEqual(self.thumb.get_zoom_level(), (256, 256))
     # Zoom in twice should end at (512, 512)
     self._zoom_wrapper(True)
     refresh_gui()
     self._zoom_wrapper(True)
     self.assertEqual(self.thumb.get_zoom_level(), (512, 512))
     # We check the pixbuf here as well
     scale = self._get_pixbuf_scale()
     # This might take a while, repeat until it works setting a limit
     count = 0
     while scale != 512:
         if count > 10:
             self.fail("Pixbuf not updated")
         scale = self._get_pixbuf_scale()
         refresh_gui(0.1)
         count += 1
     # Zoom out
     self._zoom_wrapper(False)
     self._zoom_wrapper(False)
     self.assertEqual(self.thumb.get_zoom_level(), (128, 128))
     # Zoom directly with the window implementation of zoom
     self.vimiv["window"].zoom(True)
     self.assertEqual(self.thumb.get_zoom_level(), (256, 256))
     self.vimiv["window"].zoom(False)
     self.assertEqual(self.thumb.get_zoom_level(), (128, 128))
Esempio n. 2
0
 def test_auto_rezoom_on_changes(self):
     """Automatically rezoom the image when different widgets are shown."""
     # Definitely show statusbar
     self.settings.override("display_bar", "true")
     # Zoom to fit vertically so something happens
     refresh_gui()
     self.image.zoom_to(0, "vertical")
     before = self.image.zoom_percent
     # Hide statusbar -> larger image
     self.settings.override("display_bar", "false")
     after = self.image.zoom_percent
     self.assertGreater(after, before)
     # Show statusbar -> image back to size before
     self.settings.override("display_bar", "true")
     after = self.image.zoom_percent
     self.assertEqual(after, before)
     # Zoom to fit horizontally so something happens
     self.image.zoom_to(0, "horizontal")
     before = self.image.zoom_percent
     # Show library -> smaller image
     self.vimiv["library"].toggle()
     after = self.image.zoom_percent
     self.assertLess(after, before)
     # Hide library again -> image back to size before
     self.vimiv["library"].toggle()
     after = self.image.zoom_percent
     self.assertEqual(after, before)
Esempio n. 3
0
 def test_zoom(self):
     """Zoom in thumbnail mode."""
     # Zoom to the value of 128
     while self.thumb.get_zoom_level()[0] > 128:
         self.thumb.zoom(False)
     while self.thumb.get_zoom_level()[0] < 128:
         self.thumb.zoom(True)
     self.assertEqual(self.thumb.get_zoom_level(), (128, 128))
     # Zoom in and check thumbnail size and pixbuf
     self.thumb.zoom(True)
     refresh_gui()
     self.assertEqual(self.thumb.get_zoom_level(), (256, 256))
     pixbuf = self.thumb.liststore[0][0]
     width = pixbuf.get_width()
     height = pixbuf.get_height()
     scale = max(width, height)
     self.assertEqual(scale, 256)
     # Zoom in twice should end at (512, 512)
     self.thumb.zoom(True)
     self.thumb.zoom(True)
     self.assertEqual(self.thumb.get_zoom_level(), (512, 512))
     # Zoom out
     self.thumb.zoom(False)
     self.thumb.zoom(False)
     self.assertEqual(self.thumb.get_zoom_level(), (128, 128))
     # Zoom directly with the window implementation of zoom
     self.vimiv["window"].zoom(True)
     self.assertEqual(self.thumb.get_zoom_level(), (256, 256))
     self.vimiv["window"].zoom(False)
     self.assertEqual(self.thumb.get_zoom_level(), (128, 128))
Esempio n. 4
0
    def test_scroll(self):
        """Scroll an image."""
        def there_and_back(there, back):
            """Scroll in direction and back to the beginning.

            Args:
                there: Direction to scroll in.
                back: Direction to scroll back in.
            Return:
                Position after scrolling.
            """
            if there in "lL":
                adj = self.window.get_hadjustment()
            else:
                adj = self.window.get_vadjustment()
            self.window.scroll(there)
            new_pos = adj.get_value()
            self.assertGreater(adj.get_value(), 0)
            self.window.scroll(back)
            self.assertFalse(adj.get_value())
            return new_pos

        refresh_gui()
        # First zoom so something can happen
        size = self.window.get_allocation()
        w_scale = \
            size.width / self.vimiv["image"].get_pixbuf_original().get_width()
        h_scale = \
            size.height / self.vimiv["image"].get_pixbuf_original().get_height()
        needed_scale = max(w_scale, h_scale) * 1.5
        self.vimiv["image"].zoom_to(needed_scale)
        refresh_gui()
        # Adjustments should be at 0
        h_adj = self.window.get_hadjustment()
        v_adj = self.window.get_vadjustment()
        self.assertFalse(h_adj.get_value())
        self.assertFalse(v_adj.get_value())
        # Right and back left
        there_and_back("l", "h")
        # Down and back up
        there_and_back("j", "k")
        # Far right and back
        right_end = there_and_back("L", "H")
        self.assertEqual(right_end,
                         h_adj.get_upper() - h_adj.get_lower() - size.width)
        # Bottom and back
        bottom = there_and_back("J", "K")
        self.assertEqual(bottom,
                         v_adj.get_upper() - v_adj.get_lower() - size.height)
        # Center
        self.window.center_window()
        h_adj = self.window.get_hadjustment()
        v_adj = self.window.get_vadjustment()
        h_middle = \
            (h_adj.get_upper() - h_adj.get_lower() - size.width) / 2
        v_middle = \
            (v_adj.get_upper() - v_adj.get_lower() - size.height) / 2
        self.assertEqual(h_adj.get_value(), h_middle)
        self.assertEqual(v_adj.get_value(), v_middle)
Esempio n. 5
0
 def test_fail_pipe(self):
     """Run invalid pipes."""
     self.run_command("!echo |")
     refresh_gui()
     self.check_statusbar("INFO: No input from pipe")
     self.run_command("!find . -type f -maxdepth 1 |")
     refresh_gui()
     self.check_statusbar("INFO: No image found")
Esempio n. 6
0
 def setUpClass(cls):
     if os.path.isdir("vimiv/testimages_man"):
         shutil.rmtree("vimiv/testimages_man")
     shutil.copytree("vimiv/testimages", "vimiv/testimages_man")
     cls.init_test(cls, ["vimiv/testimages_man/arch-logo.png"])
     cls.manipulate = cls.vimiv["manipulate"]
     # Wait for image as this is used in manipulate
     while not cls.vimiv["image"].get_pixbuf():
         refresh_gui(0.1)
Esempio n. 7
0
    def test_scroll(self):
        """Scroll an image."""
        def there_and_back(there, back):
            """Scroll in direction and back to the beginning.

            Args:
                there: Direction to scroll in.
                back: Direction to scroll back in.
            Return:
                Position after scrolling.
            """
            if there in "lL":
                adj = Gtk.Scrollable.get_hadjustment(self.image.viewport)
            else:
                adj = Gtk.Scrollable.get_vadjustment(self.image.viewport)
            self.image.scroll(there)
            new_pos = adj.get_value()
            self.assertGreater(adj.get_value(), 0)
            self.image.scroll(back)
            self.assertFalse(adj.get_value())
            return new_pos

        refresh_gui()
        # First zoom so something can happen
        self.image.zoom_to(1)
        refresh_gui()
        # Adjustments should be at 0
        h_adj = Gtk.Scrollable.get_hadjustment(self.image.viewport)
        v_adj = Gtk.Scrollable.get_vadjustment(self.image.viewport)
        self.assertFalse(h_adj.get_value())
        self.assertFalse(v_adj.get_value())
        # Right and back left
        there_and_back("l", "h")
        # Down and back up
        there_and_back("j", "k")
        # Far right and back
        right_end = there_and_back("L", "H")
        self.assertEqual(
            right_end,
            h_adj.get_upper() - h_adj.get_lower() - self.image.imsize[0])
        # Bottom and back
        # off by 1?
        bottom = there_and_back("J", "K")
        self.assertEqual(
            bottom,
            v_adj.get_upper() - v_adj.get_lower() - self.image.imsize[1])
        # Center
        self.image.center_window()
        h_adj = Gtk.Scrollable.get_hadjustment(self.image.viewport)
        v_adj = Gtk.Scrollable.get_vadjustment(self.image.viewport)
        h_middle = \
            (h_adj.get_upper() - h_adj.get_lower() - self.image.imsize[0]) / 2
        v_middle = \
            (v_adj.get_upper() - v_adj.get_lower() - self.image.imsize[1]) / 2
        self.assertEqual(h_adj.get_value(), h_middle)
        self.assertEqual(v_adj.get_value(), v_middle)
Esempio n. 8
0
 def test_message(self):
     """Show a message."""
     self.statusbar.message("Test error", "error")
     self.check_statusbar("ERROR: Test error")
     self.statusbar.message("Test warning", "warning")
     self.check_statusbar("WARNING: Test warning")
     self.statusbar.message("Test info", "info", timeout=0.01)
     self.check_statusbar("INFO: Test info")
     # Remove error message
     refresh_gui(0.015)
     self.assertNotEqual(self.statusbar.get_message(), "INFO: Test info")
Esempio n. 9
0
 def test_quit_with_running_threads(self):
     """Quit vimiv with external threads running."""
     self.run_command("!sleep 0.2")
     self.vimiv.quit_wrapper()
     self.check_statusbar(
         "WARNING: Running external processes: sleep 0.2. Add ! to force.")
     p = self.vimiv["commandline"].running_processes[0]
     # Kill the subprocess
     self.assertFalse(p.poll())
     self.vimiv.quit_wrapper(force=True)
     refresh_gui()
     self.assertEqual(p.poll(), -9)
Esempio n. 10
0
 def test_fullscreen(self):
     """Toggle fullscreen."""
     # Start without fullscreen
     self.assertFalse(self.vimiv["window"].is_fullscreen)
     # Fullscreen
     self.vimiv["window"].toggle_fullscreen()
     refresh_gui(0.05)
     self.assertTrue(self.vimiv["window"].is_fullscreen)
     # Unfullscreen
     self.vimiv["window"].toggle_fullscreen()
     refresh_gui(0.05)
     self.assertFalse(self.vimiv["window"].is_fullscreen)
     self.vimiv["window"].fullscreen()
Esempio n. 11
0
 def test_overzoom(self):
     """Test overzoom at opening and fit afterwards."""
     # Finish other image loading threads
     refresh_gui(0.01)
     # Move to a small image
     self.image.move_pos()
     refresh_gui(0.01)
     # Overzoom is respected
     self.assertEqual(self.image.get_zoom_percent(), 100)
     # But not for a direct call to fit
     self.image.zoom_to(0, "fit")
     self.assertGreater(self.image.get_zoom_percent(), 100)
     self.image.move_pos(forward=False)
Esempio n. 12
0
 def test_quit_with_edited_image(self):
     """Quit vimiv with an edited image."""
     # Fake a manipulation
     self.vimiv["manipulate"].manipulations = {}
     self.vimiv.quit_wrapper()
     self.check_statusbar("WARNING: Image has been edited, add ! to force")
     # Force quit
     self.vimiv.quit_wrapper(force=True)
     self.assertEqual(self.vimiv["manipulate"].manipulations, {
         "bri": 1,
         "con": 1,
         "sha": 1
     })
     refresh_gui()
Esempio n. 13
0
 def test_fullscreen(self):
     """Toggle fullscreen."""
     # Start without fullscreen
     self.assertFalse(self.vimiv["window"].is_fullscreen)
     # Fullscreen
     self.vimiv["window"].toggle_fullscreen()
     refresh_gui(0.05)
     # Still not reliable
     # self.assertTrue(self.vimiv["window"].is_fullscreen)
     # Unfullscreen
     self.vimiv["window"].toggle_fullscreen()
     refresh_gui(0.05)
     # self.assertFalse(self.vimiv["window"].is_fullscreen)
     self.vimiv["window"].fullscreen()
Esempio n. 14
0
 def test_touch(self):
     """Touch event."""
     self.vimiv["library"].file_select(None, Gtk.TreePath(1), None, True)
     image_before = self.vimiv.get_path()
     event = Gdk.Event().new(Gdk.EventType.TOUCH_BEGIN)
     # Twice to check for exception
     self.vimiv["window"].emit("touch-event", event)
     self.vimiv["window"].emit("touch-event", event)
     image_after = self.vimiv.get_path()
     self.assertEqual(image_before, image_after)  # Touch only disables
     self.vimiv["library"].toggle()
     self.assertTrue(self.vimiv["library"].is_focus())
     refresh_gui()
     # Test again to see if it was re-activated properly
     self.test_button_click()
Esempio n. 15
0
 def test_run_external(self):
     """Run an external command and test failures."""
     # Run command
     self.run_command("!touch tmp_foo", True)
     files = os.listdir()
     self.assertTrue("tmp_foo" in files)
     os.remove("tmp_foo")
     # Try to run a non-existent command
     fail_command = "foo_bar_baz"
     p = Popen(fail_command, stdout=PIPE, stderr=PIPE, shell=True)
     _, err_message = p.communicate()
     err_message = err_message.decode()
     self.run_command("!foo_bar_baz", True)
     refresh_gui()  # Needed because of GLib.idle_add in command thread
     self.check_statusbar("ERROR: Command exited with status 127\n" +
                          err_message)
Esempio n. 16
0
 def test_toggle_animation(self):
     """Pause and play an animated gif."""
     self._update_gif(True)
     # Frames should be updated
     first_pb = self.image.get_pixbuf_original()
     refresh_gui(0.1)
     second_pb = self.image.get_pixbuf_original()
     self.assertFalse(compare_pixbufs(first_pb, second_pb))
     # Frames should no longer be updated
     self._update_gif(False)
     first_pb = self.image.get_pixbuf_original()
     refresh_gui(0.1)
     second_pb = self.image.get_pixbuf_original()
     self.assertTrue(compare_pixbufs(first_pb, second_pb))
     # Back to standard state
     self._update_gif(True)
Esempio n. 17
0
 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))
Esempio n. 18
0
 def test_pipe(self):
     """Pipe a command to vimiv."""
     # Internal command
     before_command = self.vimiv["image"].overzoom
     self.vimiv["commandline"].entry.set_text(":!echo set overzoom! |")
     self.vimiv["commandline"].handler(self.vimiv["commandline"].entry)
     self.vimiv["commandline"].running_threads[0].join()
     refresh_gui(0.001)
     after_command = self.vimiv["image"].overzoom
     self.assertNotEqual(before_command, after_command)
     # Directory
     expected_dir = os.path.abspath("./vimiv/testimages/")
     self.vimiv["commandline"].entry.set_text(":!echo vimiv/testimages |")
     self.vimiv["commandline"].handler(self.vimiv["commandline"].entry)
     self.vimiv["commandline"].running_threads[0].join()
     refresh_gui(0.001)
     dir_after = os.getcwd()
     self.assertEqual(expected_dir, dir_after)
     # Image
     expected_image = os.path.abspath("arch-logo.png")
     self.vimiv["commandline"].entry.set_text(":!echo arch-logo.png |")
     self.vimiv["commandline"].handler(self.vimiv["commandline"].entry)
     self.vimiv["commandline"].running_threads[0].join()
     refresh_gui()
     self.assertEqual(self.vimiv.paths[0], expected_image)
Esempio n. 19
0
 def test_pipe(self):
     """Pipe a command to vimiv."""
     # Internal command
     before_command = self.vimiv["image"].overzoom
     self.run_command("!echo set overzoom! |", True)
     refresh_gui(0.001)
     after_command = self.vimiv["image"].overzoom
     self.assertNotEqual(before_command, after_command)
     # Directory
     expected_dir = os.path.abspath("./vimiv/testimages/")
     self.run_command("!echo vimiv/testimages |", True)
     refresh_gui(0.001)
     dir_after = os.getcwd()
     self.assertEqual(expected_dir, dir_after)
     # Image
     expected_image = os.path.abspath("arch_001.jpg")
     self.run_command("!echo arch_001.jpg |", True)
     refresh_gui()
     self.assertEqual(self.vimiv.paths[0], expected_image)
Esempio n. 20
0
 def test_pipe(self):
     """Pipe a command to vimiv."""
     # Internal command
     before_command = self.settings["show_hidden"].get_value()
     self.run_command("!echo set show_hidden! |", True)
     refresh_gui()
     after_command = self.settings["show_hidden"].get_value()
     self.assertNotEqual(before_command, after_command)
     # Directory
     expected_dir = os.path.abspath("./vimiv/testimages/")
     self.run_command("!echo vimiv/testimages |", True)
     refresh_gui()
     dir_after = os.getcwd()
     self.assertEqual(expected_dir, dir_after)
     # Image
     expected_image = os.path.abspath("arch_001.jpg")
     self.run_command("!echo arch_001.jpg |", True)
     refresh_gui()
     self.assertEqual(self.vimiv.get_path(), expected_image)
Esempio n. 21
0
 def _zoom_wrapper(self, zoom_in):
     self.thumb.zoom(zoom_in)
     refresh_gui()
Esempio n. 22
0
 def _update_gif(self, assertion):
     self.run_command("set play_animations %s" % (str(assertion)))
     refresh_gui(0.1)
     self.assertEqual(self.settings["play_animations"].get_value(),
                      assertion)
Esempio n. 23
0
 def setUp(self):
     """Set up by opening manipulate. Test half of toggling."""
     self.manipulate.toggle()
     refresh_gui()
     self.assertTrue(self.manipulate.is_visible())
     self.assertTrue(self.manipulate.sliders["bri"].is_focus())
Esempio n. 24
0
 def test_check_resize(self):
     """Resize window and check winsize."""
     self.assertEqual(self.vimiv["window"].winsize, (800, 600))
     self.vimiv["window"].resize(400, 300)
     refresh_gui()
     self.assertEqual(self.vimiv["window"].winsize, (400, 300))