Exemple #1
0
    def test_scaled_proxy_size(self):
        app = common.create_pitivi_mock(default_scaled_proxy_width=123,
                                        default_scaled_proxy_height=456)
        manager = ProjectManager(app)
        project = manager.new_blank_project()
        self.assertFalse(project.has_scaled_proxy_size())
        self.assertEqual(project.scaled_proxy_width, 123)
        self.assertEqual(project.scaled_proxy_height, 456)

        with tempfile.NamedTemporaryFile() as temp_file:
            uri = Gst.filename_to_uri(temp_file.name)
            manager.save_project(uri=uri, backup=False)
            app2 = common.create_pitivi_mock(default_scaled_proxy_width=12,
                                             default_scaled_proxy_height=45)
            project2 = ProjectManager(app2).load_project(uri)
            self.assertFalse(project2.has_scaled_proxy_size())
            self.assertEqual(project2.scaled_proxy_width, 12)
            self.assertEqual(project2.scaled_proxy_height, 45)

        project.scaled_proxy_width = 123
        project.scaled_proxy_height = 456
        self.assertTrue(project.has_scaled_proxy_size())
        self.assertEqual(project.scaled_proxy_width, 123)
        self.assertEqual(project.scaled_proxy_height, 456)

        with tempfile.NamedTemporaryFile() as temp_file:
            manager.save_project(uri=uri, backup=False)
            app2 = common.create_pitivi_mock(default_scaled_proxy_width=1,
                                             default_scaled_proxy_height=4)
            project2 = ProjectManager(app2).load_project(uri)
            self.assertTrue(project2.has_scaled_proxy_size())
            self.assertEqual(project2.scaled_proxy_width, 123)
            self.assertEqual(project2.scaled_proxy_height, 456)
Exemple #2
0
class TestProjectManager(common.TestCase):

    def setUp(self):
        super().setUp()
        self.setup_app()

    def setup_app(self, app=None):
        if not app:
            app = mock.MagicMock()
        self.manager = ProjectManager(app)
        self.listener = ProjectManagerListener(self.manager)
        self.signals = self.listener.signals

    def test_loading_missing_project_file(self):
        """Checks new-project-failed is emitted for unsuitable formatters."""
        project_uri = Gst.filename_to_uri(tempfile.NamedTemporaryFile().name)
        self.manager.load_project(project_uri)

        # loading
        name, args = self.signals[0]
        self.assertEqual(project_uri, args[0].get_uri(), self.signals)

        # failed
        name, args = self.signals[1]
        self.assertEqual("new-project-failed", name)
        signal_uri, unused_message = args
        self.assertEqual(project_uri, signal_uri, self.signals)

    def test_new_blank_project_signals(self):
        self.manager.new_blank_project()

        name, _args = self.signals[0]
        self.assertEqual("new-project-loading", name, self.signals)

        name, _args = self.signals[1]
        self.assertEqual("new-project-created", name, self.signals)

        name, _args = self.signals[2]
        self.assertEqual("new-project-loaded", name, self.signals)

    def test_missing_uri_forwarded(self):
        self.setup_app(app=common.create_pitivi_mock())
        mainloop = common.create_main_loop()

        def missing_uri_cb(self, project, error, clip_asset, result):
            result[0] = True
            mainloop.quit()

        result = [False]
        self.manager.connect("missing-uri", missing_uri_cb, result)

        with common.cloned_sample():
            asset_uri = common.get_sample_uri("missing.png")
            with common.created_project_file(asset_uri) as uri:
                self.assertIsNotNone(self.manager.load_project(uri))
                mainloop.run()
        self.assertTrue(result[0], "missing-uri has not been emitted")

    def test_loaded(self):
        mainloop = common.create_main_loop()

        def new_project_loaded_cb(project_manager, project):
            mainloop.quit()

        self.manager.connect("new-project-loaded", new_project_loaded_cb)

        with common.cloned_sample("flat_colour1_640x480.png"):
            asset_uri = common.get_sample_uri("flat_colour1_640x480.png")
            with common.created_project_file(asset_uri=asset_uri) as uri:
                project = self.manager.load_project(uri)
                self.assertIsNotNone(project)
                mainloop.run()

        self.assertFalse(project.at_least_one_asset_missing)
        self.assertTrue(project.loaded)
        self.assertFalse(project.has_unsaved_modifications())

    def test_close_running_project_no_project(self):
        self.assertTrue(self.manager.close_running_project())
        self.assertFalse(self.signals)

    def test_close_running_project_refuse_from_signal(self):
        def closing_cb(manager, project):
            return False

        self.manager.current_project = mock.Mock()
        self.manager.current_project.uri = "file:///ciao"
        self.manager.connect("closing-project", closing_cb)

        self.assertFalse(self.manager.close_running_project())
        self.assertEqual(1, len(self.signals))
        name, args = self.signals[0]
        self.assertEqual("closing-project", name)
        project = args[0]
        self.assertTrue(project is self.manager.current_project)

    def test_close_running_project(self):
        project = self.manager.new_blank_project()
        self.assertTrue(self.manager.close_running_project())
        self.assertEqual(5, len(self.signals), self.signals)

        name, args = self.signals[-2]
        self.assertEqual("closing-project", name)
        self.assertEqual(args[0], project)

        name, args = self.signals[-1]
        self.assertEqual("project-closed", name)
        self.assertEqual(args[0], project)

        self.assertTrue(self.manager.current_project is None)

    def test_new_blank_project(self):
        self.assertIsNotNone(self.manager.new_blank_project())
        self.assertEqual(3, len(self.signals))

        name, args = self.signals[0]
        self.assertEqual("new-project-loading", name)
        project = args[0]
        self.assertTrue(project.get_uri() is None)

        name, args = self.signals[1]
        self.assertEqual("new-project-created", name)
        project = args[0]
        self.assertEqual(project.get_uri(), project.uri)

        name, args = self.signals[2]
        self.assertEqual("new-project-loaded", name)
        project = args[0]
        self.assertTrue(project is self.manager.current_project)

    def test_marker_container(self):
        project = self.manager.new_blank_project()
        self.assertIsNotNone(project)
        self.assertIsNotNone(project.ges_timeline)
        self.assertIsNotNone(project.ges_timeline.get_marker_list("markers"))

    def test_save_project(self):
        self.manager.new_blank_project()

        unused, path = tempfile.mkstemp(suffix=".xges")
        unused, path2 = tempfile.mkstemp(suffix=".xges")
        try:
            uri = "file://" + os.path.abspath(path)
            uri2 = "file://" + os.path.abspath(path2)

            # Save the project.
            self.assertTrue(self.manager.save_project(uri=uri, backup=False))
            self.assertTrue(os.path.isfile(path))

            # Wait a bit.
            time.sleep(0.1)

            # Save the project at a new location.
            self.assertTrue(self.manager.save_project(uri2, backup=False))
            self.assertTrue(os.path.isfile(path2))

            # Make sure the old path and the new path have different mtimes.
            mtime = os.path.getmtime(path)
            mtime2 = os.path.getmtime(path2)
            self.assertLess(mtime, mtime2)

            # Wait a bit more.
            time.sleep(0.1)

            # Save project again under the new path (by omitting uri arg)
            self.assertTrue(self.manager.save_project(backup=False))

            # regression test for bug 594396
            # make sure we didn't save to the old URI
            self.assertEqual(mtime, os.path.getmtime(path))
            # make sure we did save to the new URI
            self.assertLess(mtime2, os.path.getmtime(path2))
        finally:
            os.remove(path)
            os.remove(path2)

    def test_make_backup_uri(self):
        uri = "file:///tmp/x.xges"
        self.assertEqual(uri + "~", self.manager._make_backup_uri(uri))

    def test_backup_project(self):
        self.manager.new_blank_project()

        # Assign an uri to the project where it's saved by default.
        unused, xges_path = tempfile.mkstemp(suffix=".xges")
        uri = "file://" + os.path.abspath(xges_path)
        self.manager.current_project.uri = uri
        # This is where the automatic backup file is saved.
        backup_uri = self.manager._make_backup_uri(uri)

        # Save the backup
        self.assertTrue(self.manager.save_project(
            self.manager.current_project, backup=True))
        self.assertTrue(os.path.isfile(path_from_uri(backup_uri)))

        self.manager.close_running_project()
        self.assertFalse(os.path.isfile(path_from_uri(backup_uri)),
                         "Backup file not deleted when project closed")