class TestProjectManager(TestCase): def setUp(self): self.manager = ProjectManager(None) self.listener = ProjectManagerListener(self.manager) self.signals = self.listener.signals def testLoadProjectFailedUnknownFormat(self): """ Check that new-project-failed is emitted when we don't have a suitable formatter. """ uri = "file:///Untitled.meh" self.manager.loadProject(uri) # loading name, args = self.signals[0] self.assertEqual(uri, args[0], self.signals) # failed name, args = self.signals[1] self.assertEqual("new-project-failed", name) signalUri, unused_message = args self.assertEqual(uri, signalUri, self.signals) def testLoadProjectClosesCurrent(self): """ Check that new-project-failed is emited if we can't close the current project instance. """ state = {"tried-close": False} def close(): state["tried-close"] = True return False self.manager.closeRunningProject = close uri = "file:///Untitled.xptv" self.manager.current_project = MockProject() self.manager.loadProject(uri) self.assertEqual(0, len(self.signals)) self.assertTrue(state["tried-close"], self.signals) def testLoadProject(self): self.manager.newBlankProject() 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 testMissingUriForwarded(self): def quit(mainloop): mainloop.quit() def missingUriCb(self, project, error, clip_asset, mainloop, result): print(project, error, clip_asset, mainloop, result) result[0] = True mainloop.quit() self.mainloop = GLib.MainLoop() result = [False] self.manager.connect("missing-uri", missingUriCb, self.mainloop, result) # Load a project with a missing asset. unused, xges_path = tempfile.mkstemp() with open(xges_path, "w") as xges: xges.write("""<ges version='0.1'> <project> <ressources> <asset id='file:///icantpossiblyexist.png' extractable-type-name='GESUriClip' /> </ressources> <timeline> <track caps='video/x-raw' track-type='4' track-id='0' /> <layer priority='0'> <clip id='0' asset-id='file:///icantpossiblyexist.png' type-name='GESUriClip' layer-priority='0' track-types='4' start='0' duration='2590000000' inpoint='0' rate='0' /> </layer> </timeline> </project> </ges>""") uri = "file://%s" % xges_path try: self.assertTrue(self.manager.loadProject(uri)) GLib.timeout_add_seconds(5, quit, self.mainloop) self.mainloop.run() self.assertTrue(result[0], "missing not missing") finally: os.remove(xges_path) def testCloseRunningProjectNoProject(self): self.assertTrue(self.manager.closeRunningProject()) self.assertFalse(self.signals) def testCloseRunningProjectRefuseFromSignal(self): def closing(manager, project): return False self.manager.current_project = MockProject() self.manager.current_project.uri = "file:///ciao" self.manager.connect("closing-project", closing) self.assertFalse(self.manager.closeRunningProject()) 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 testCloseRunningProject(self): current = self.manager.current_project = MockProject() self.assertTrue(self.manager.closeRunningProject()) self.assertEqual(2, len(self.signals)) name, args = self.signals[0] self.assertEqual("closing-project", name) project = args[0] self.assertTrue(project is current) name, args = self.signals[1] self.assertEqual("project-closed", name) project = args[0] self.assertTrue(project is current) self.assertTrue(self.manager.current_project is None) def testNewBlankProjectCantCloseCurrent(self): def closing(manager, project): return False self.manager.current_project = MockProject() self.manager.current_project.uri = "file:///ciao" self.manager.connect("closing-project", closing) self.assertFalse(self.manager.newBlankProject()) self.assertEqual(1, len(self.signals)) signal, args = self.signals[0] self.assertEqual("closing-project", signal) def testNewBlankProject(self): self.assertTrue(self.manager.newBlankProject()) self.assertEqual(3, len(self.signals)) name, args = self.signals[0] self.assertEqual("new-project-loading", name) uri = args[0] self.assertTrue(uri is None) name, args = self.signals[1] self.assertEqual("new-project-created", name) project = args[0] self.assertEqual(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 testSaveProject(self): self.assertTrue(self.manager.newBlankProject()) 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.saveProject(uri=uri, backup=False)) self.assertTrue(uri_is_reachable(uri)) # Wait a bit. time.sleep(0.1) # Save the project at a new location. self.assertTrue(self.manager.saveProject(uri2, backup=False)) self.assertTrue(uri_is_reachable(uri2)) # 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.saveProject(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 testMakeBackupUri(self): uri = "file:///tmp/x.xges" self.assertEqual(uri + "~", self.manager._makeBackupURI(uri)) def testBackupProject(self): self.manager.newBlankProject() # 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._makeBackupURI(uri) # Save the backup self.assertTrue( self.manager.saveProject(self.manager.current_project, backup=True)) self.assertTrue(uri_is_reachable(backup_uri)) self.manager.closeRunningProject() self.assertFalse(uri_is_reachable(backup_uri), "Backup file not deleted when project closed")
class TestProjectManager(TestCase): def setUp(self): self.manager = ProjectManager(None) self.listener = ProjectManagerListener(self.manager) self.signals = self.listener.signals def testLoadProjectFailedUnknownFormat(self): """ Check that new-project-failed is emitted when we don't have a suitable formatter. """ uri = "file:///Untitled.meh" self.manager.loadProject(uri) # loading name, args = self.signals[0] self.assertEqual(uri, args[0], self.signals) # failed name, args = self.signals[1] self.assertEqual("new-project-failed", name) signalUri, unused_message = args self.assertEqual(uri, signalUri, self.signals) def testLoadProjectClosesCurrent(self): """ Check that new-project-failed is emited if we can't close the current project instance. """ state = {"tried-close": False} def close(): state["tried-close"] = True return False self.manager.closeRunningProject = close uri = "file:///Untitled.xptv" self.manager.current_project = MockProject() self.manager.loadProject(uri) self.assertEqual(0, len(self.signals)) self.assertTrue(state["tried-close"], self.signals) def testLoadProject(self): self.manager.newBlankProject() 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 testMissingUriForwarded(self): def quit(mainloop): mainloop.quit() def missingUriCb(self, project, error, clip_asset, mainloop, result): print(project, error, clip_asset, mainloop, result) result[0] = True mainloop.quit() self.mainloop = GLib.MainLoop() result = [False] self.manager.connect( "missing-uri", missingUriCb, self.mainloop, result) # Load a project with a missing asset. unused, xges_path = tempfile.mkstemp() with open(xges_path, "w") as xges: xges.write("""<ges version='0.1'> <project> <ressources> <asset id='file:///icantpossiblyexist.png' extractable-type-name='GESUriClip' /> </ressources> <timeline> <track caps='video/x-raw' track-type='4' track-id='0' /> <layer priority='0'> <clip id='0' asset-id='file:///icantpossiblyexist.png' type-name='GESUriClip' layer-priority='0' track-types='4' start='0' duration='2590000000' inpoint='0' rate='0' /> </layer> </timeline> </project> </ges>""") uri = "file://%s" % xges_path try: self.assertTrue(self.manager.loadProject(uri)) GLib.timeout_add_seconds(5, quit, self.mainloop) self.mainloop.run() self.assertTrue(result[0], "missing not missing") finally: os.remove(xges_path) def testCloseRunningProjectNoProject(self): self.assertTrue(self.manager.closeRunningProject()) self.assertFalse(self.signals) def testCloseRunningProjectRefuseFromSignal(self): def closing(manager, project): return False self.manager.current_project = MockProject() self.manager.current_project.uri = "file:///ciao" self.manager.connect("closing-project", closing) self.assertFalse(self.manager.closeRunningProject()) 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 testCloseRunningProject(self): current = self.manager.current_project = MockProject() self.assertTrue(self.manager.closeRunningProject()) self.assertEqual(2, len(self.signals)) name, args = self.signals[0] self.assertEqual("closing-project", name) project = args[0] self.assertTrue(project is current) name, args = self.signals[1] self.assertEqual("project-closed", name) project = args[0] self.assertTrue(project is current) self.assertTrue(self.manager.current_project is None) def testNewBlankProjectCantCloseCurrent(self): def closing(manager, project): return False self.manager.current_project = MockProject() self.manager.current_project.uri = "file:///ciao" self.manager.connect("closing-project", closing) self.assertFalse(self.manager.newBlankProject()) self.assertEqual(1, len(self.signals)) signal, args = self.signals[0] self.assertEqual("closing-project", signal) def testNewBlankProject(self): self.assertTrue(self.manager.newBlankProject()) self.assertEqual(3, len(self.signals)) name, args = self.signals[0] self.assertEqual("new-project-loading", name) uri = args[0] self.assertTrue(uri is None) name, args = self.signals[1] self.assertEqual("new-project-created", name) project = args[0] self.assertEqual(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 testSaveProject(self): self.assertTrue(self.manager.newBlankProject()) 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.saveProject(uri=uri, backup=False)) self.assertTrue(uri_is_reachable(uri)) # Wait a bit. time.sleep(0.1) # Save the project at a new location. self.assertTrue(self.manager.saveProject(uri2, backup=False)) self.assertTrue(uri_is_reachable(uri2)) # 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.saveProject(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 testMakeBackupUri(self): uri = "file:///tmp/x.xges" self.assertEqual(uri + "~", self.manager._makeBackupURI(uri)) def testBackupProject(self): self.manager.newBlankProject() # 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._makeBackupURI(uri) # Save the backup self.assertTrue(self.manager.saveProject( self.manager.current_project, backup=True)) self.assertTrue(uri_is_reachable(backup_uri)) self.manager.closeRunningProject() self.assertFalse(uri_is_reachable(backup_uri), "Backup file not deleted when project closed")
class TestProjectManager(common.TestCase): def setUp(self): super(TestProjectManager, self).setUp() self.setupApp() def setupApp(self, app=None): if not app: app = mock.MagicMock() self.manager = ProjectManager(app) self.listener = ProjectManagerListener(self.manager) self.signals = self.listener.signals def testLoadProjectFailedUnknownFormat(self): """Checks new-project-failed is emitted for unsuitable formatters.""" uri = "file:///Untitled.meh" self.manager.load_project(uri) # loading name, args = self.signals[0] self.assertEqual(uri, args[0].get_uri(), self.signals) # failed name, args = self.signals[1] self.assertEqual("new-project-failed", name) signalUri, unused_message = args self.assertEqual(uri, signalUri, self.signals) def testLoadProject(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 testMissingUriForwarded(self): self.setupApp(app=common.create_pitivi_mock()) mainloop = common.create_main_loop() def missingUriCb(self, project, error, clip_asset, result): result[0] = True mainloop.quit() result = [False] self.manager.connect("missing-uri", missingUriCb, 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 testLoaded(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.hasUnsavedModifications()) def testCloseRunningProjectNoProject(self): self.assertTrue(self.manager.closeRunningProject()) self.assertFalse(self.signals) def testCloseRunningProjectRefuseFromSignal(self): def closing(manager, project): return False self.manager.current_project = mock.Mock() self.manager.current_project.uri = "file:///ciao" self.manager.connect("closing-project", closing) self.assertFalse(self.manager.closeRunningProject()) 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 testCloseRunningProject(self): current = mock.Mock() current.uri = None self.manager.current_project = current self.assertTrue(self.manager.closeRunningProject()) self.assertEqual(2, len(self.signals)) name, args = self.signals[0] self.assertEqual("closing-project", name) project = args[0] self.assertTrue(project is current) name, args = self.signals[1] self.assertEqual("project-closed", name) project = args[0] self.assertTrue(project is current) self.assertTrue(self.manager.current_project is None) def testNewBlankProject(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 testSaveProject(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.saveProject(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.saveProject(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.saveProject(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 testMakeBackupUri(self): uri = "file:///tmp/x.xges" self.assertEqual(uri + "~", self.manager._makeBackupURI(uri)) def testBackupProject(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._makeBackupURI(uri) # Save the backup self.assertTrue( self.manager.saveProject(self.manager.current_project, backup=True)) self.assertTrue(os.path.isfile(path_from_uri(backup_uri))) self.manager.closeRunningProject() self.assertFalse(os.path.isfile(path_from_uri(backup_uri)), "Backup file not deleted when project closed")
class TestProjectManager(common.TestCase): def setUp(self): super(TestProjectManager, self).setUp() self.setupApp() def setupApp(self, app=None): if not app: app = mock.MagicMock() self.manager = ProjectManager(app) self.listener = ProjectManagerListener(self.manager) self.signals = self.listener.signals def testLoadProjectFailedUnknownFormat(self): """Checks new-project-failed is emitted for unsuitable formatters.""" uri = "file:///Untitled.meh" self.manager.load_project(uri) # loading name, args = self.signals[0] self.assertEqual(uri, args[0].get_uri(), self.signals) # failed name, args = self.signals[1] self.assertEqual("new-project-failed", name) signalUri, unused_message = args self.assertEqual(uri, signalUri, self.signals) def testLoadProject(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 testMissingUriForwarded(self): self.setupApp(app=common.create_pitivi_mock()) mainloop = common.create_main_loop() def missingUriCb(self, project, error, clip_asset, result): result[0] = True mainloop.quit() result = [False] self.manager.connect("missing-uri", missingUriCb, 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 testLoaded(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.hasUnsavedModifications()) def testCloseRunningProjectNoProject(self): self.assertTrue(self.manager.closeRunningProject()) self.assertFalse(self.signals) def testCloseRunningProjectRefuseFromSignal(self): def closing(manager, project): return False self.manager.current_project = mock.Mock() self.manager.current_project.uri = "file:///ciao" self.manager.connect("closing-project", closing) self.assertFalse(self.manager.closeRunningProject()) 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 testCloseRunningProject(self): current = mock.Mock() current.uri = None self.manager.current_project = current self.assertTrue(self.manager.closeRunningProject()) self.assertEqual(2, len(self.signals)) name, args = self.signals[0] self.assertEqual("closing-project", name) project = args[0] self.assertTrue(project is current) name, args = self.signals[1] self.assertEqual("project-closed", name) project = args[0] self.assertTrue(project is current) self.assertTrue(self.manager.current_project is None) def testNewBlankProject(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 testSaveProject(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.saveProject(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.saveProject(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.saveProject(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 testMakeBackupUri(self): uri = "file:///tmp/x.xges" self.assertEqual(uri + "~", self.manager._makeBackupURI(uri)) def testBackupProject(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._makeBackupURI(uri) # Save the backup self.assertTrue(self.manager.saveProject( self.manager.current_project, backup=True)) self.assertTrue(os.path.isfile(path_from_uri(backup_uri))) self.manager.closeRunningProject() self.assertFalse(os.path.isfile(path_from_uri(backup_uri)), "Backup file not deleted when project closed")