[pitivi] formatters.etree: Move the context into the class



commit be0dbfd181f77c15791ab6d529310e7980a9eefd
Author: Edward Hervey <bilboed bilboed com>
Date:   Tue Apr 7 21:43:44 2009 +0200

    formatters.etree: Move the context into the class
---
 pitivi/formatters/etree.py |  162 ++++++++++++++++++++++----------------------
 tests/test_formatter.py    |  138 ++++++++++++++++++-------------------
 2 files changed, 149 insertions(+), 151 deletions(-)

diff --git a/pitivi/formatters/etree.py b/pitivi/formatters/etree.py
index 56d7da1..5e043bd 100644
--- a/pitivi/formatters/etree.py
+++ b/pitivi/formatters/etree.py
@@ -65,6 +65,10 @@ class ElementTreeFormatter(Formatter):
     _element_id = 0
     _our_properties = ["id", "type"]
 
+    def __init__(self, *args, **kwargs):
+        Formatter.__init__(self, *args, **kwargs)
+        self._context = ElementTreeFormatterContext()
+
     def _new_element_id(self):
         element_id = self._element_id
         self._element_id += 1
@@ -82,50 +86,50 @@ class ElementTreeFormatter(Formatter):
         # nothing to read here, move along
         return gst.Caps("meh, name=%s" % value)[0]["name"]
 
-    def _saveStream(self, stream, context):
+    def _saveStream(self, stream):
         element = Element("stream")
         element.attrib["id"] = self._new_element_id()
         element.attrib["type"] = qual(stream.__class__)
         element.attrib["caps"] = str(stream.caps)
 
-        context.streams[stream] = element
+        self._context.streams[stream] = element
 
         return element
 
-    def _loadStream(self, element, context):
+    def _loadStream(self, element):
         id_ = element.attrib["id"]
         klass = namedAny(element.attrib["type"])
         caps = gst.Caps(element.attrib["caps"])
 
         stream = klass(caps)
 
-        context.streams[id_] = stream
+        self._context.streams[id_] = stream
 
         return stream
 
-    def _saveStreamRef(self, stream, context):
-        stream_element = context.streams[stream]
+    def _saveStreamRef(self, stream):
+        stream_element = self._context.streams[stream]
         element = Element("stream-ref")
         element.attrib["id"] = stream_element.attrib["id"]
 
         return element
 
-    def _loadStreamRef(self, element, context):
-        return context.streams[element.attrib["id"]]
+    def _loadStreamRef(self, element):
+        return self._context.streams[element.attrib["id"]]
 
-    def _saveSource(self, source, context):
-        element = self._saveObjectFactory(source, context)
+    def _saveSource(self, source):
+        element = self._saveObjectFactory(source)
         if isinstance(source, FileSourceFactory):
-            return self._saveFileSourceFactory(element, source, context)
+            return self._saveFileSourceFactory(element, source)
 
         return element
 
-    def _loadFactory(self, element, context):
+    def _loadFactory(self, element):
         klass = namedAny(element.attrib["type"])
 
-        return self._loadObjectFactory(klass, element, context)
+        return self._loadObjectFactory(klass, element)
 
-    def _saveObjectFactory(self, factory, context):
+    def _saveObjectFactory(self, factory):
         element = Element("source")
         element.attrib["id"] = self._new_element_id()
         element.attrib["type"] = qual(factory.__class__)
@@ -133,20 +137,20 @@ class ElementTreeFormatter(Formatter):
         input_streams_element = SubElement(element, "input-streams")
         input_streams = factory.getInputStreams()
         for stream in input_streams:
-            stream_element = self._saveStream(stream, context)
+            stream_element = self._saveStream(stream)
             input_streams_element.append(stream_element)
 
         output_streams_element = SubElement(element, "output-streams")
         output_streams = factory.getOutputStreams()
         for stream in output_streams:
-            stream_element = self._saveStream(stream, context)
+            stream_element = self._saveStream(stream)
             output_streams_element.append(stream_element)
 
-        context.factories[factory] = element
+        self._context.factories[factory] = element
 
         return element
 
-    def _loadObjectFactory(self, klass, element, context):
+    def _loadObjectFactory(self, klass, element):
         # FIXME
         if isinstance(klass, FileSourceFactory):
             factory = FileSourceFactory(element.attrib["filename"])
@@ -155,43 +159,43 @@ class ElementTreeFormatter(Formatter):
 
         input_streams = element.find("input-streams") or []
         for stream_element in input_streams:
-            stream = self._loadStream(stream_element, context)
+            stream = self._loadStream(stream_element)
             factory.addInputStream(stream)
 
         output_streams = element.find("output-streams")
         for stream_element in output_streams:
-            stream = self._loadStream(stream_element, context)
+            stream = self._loadStream(stream_element)
             factory.addOutputStream(stream)
 
-        context.factories[element.attrib["id"]] = factory
+        self._context.factories[element.attrib["id"]] = factory
 
         return factory
 
-    def _saveFileSourceFactory(self, element, source, context):
+    def _saveFileSourceFactory(self, element, source):
         element.attrib["filename"] = source.filename
 
         return element
 
-    def _saveFactoryRef(self, factory, context):
+    def _saveFactoryRef(self, factory):
         element = Element("factory-ref")
-        element.attrib["id"] = context.factories[factory].attrib["id"]
+        element.attrib["id"] = self._context.factories[factory].attrib["id"]
 
         return element
 
-    def _loadFactoryRef(self, element, context):
-        return context.factories[element.attrib["id"]]
+    def _loadFactoryRef(self, element):
+        return self._context.factories[element.attrib["id"]]
 
-    def _saveFactories(self, factories, context):
+    def _saveFactories(self, factories):
         element = Element("factories")
         sources = SubElement(element, "sources")
         for factory in factories:
             if isinstance(factory, SourceFactory):
-                source_element = self._saveSource(factory, context)
+                source_element = self._saveSource(factory)
                 sources.append(source_element)
 
         return element
 
-    def _saveTrackObject(self, track_object, context):
+    def _saveTrackObject(self, track_object):
         element = Element("track-object")
         element.attrib["id"] = self._new_element_id()
         element.attrib["type"] = qual(track_object.__class__)
@@ -203,24 +207,24 @@ class ElementTreeFormatter(Formatter):
         element.attrib["priority"] = "(int)%s" % track_object.priority
 
         factory_ref = \
-                self._saveFactoryRef(track_object.factory, context)
-        stream_ref = self._saveStreamRef(track_object.stream, context)
+                self._saveFactoryRef(track_object.factory)
+        stream_ref = self._saveStreamRef(track_object.stream)
 
         element.append(factory_ref)
         element.append(stream_ref)
 
-        context.track_objects[track_object] = element
+        self._context.track_objects[track_object] = element
 
         return element
 
-    def _loadTrackObject(self, element, context):
+    def _loadTrackObject(self, element):
         klass = namedAny(element.attrib["type"])
 
         factory_ref = element.find("factory-ref")
-        factory = self._loadFactoryRef(factory_ref, context)
+        factory = self._loadFactoryRef(factory_ref)
 
         stream_ref = element.find("stream-ref")
-        stream = self._loadStreamRef(stream_ref, context)
+        stream = self._loadStreamRef(stream_ref)
 
         track_object = klass(factory, stream)
         for name, value_string in self._filterElementProperties(element):
@@ -229,35 +233,35 @@ class ElementTreeFormatter(Formatter):
 
         return track_object
 
-    def _saveTrackObjectRef(self, track_object, context):
+    def _saveTrackObjectRef(self, track_object):
         element = Element("track-object-ref")
-        element.attrib["id"] = context.track_objects[track_object].attrib["id"]
+        element.attrib["id"] = self._context.track_objects[track_object].attrib["id"]
 
         return element
 
-    def _loadTrackObjectRef(self, element, context):
-        return context.track_objects[element.attrib["id"]]
+    def _loadTrackObjectRef(self, element):
+        return self._context.track_objects[element.attrib["id"]]
 
-    def _saveTrackObjectRefs(self, track_objects, context):
+    def _saveTrackObjectRefs(self, track_objects):
         element = Element("track-object-refs")
 
         for track_object in track_objects:
-            track_object_ref = self._saveTrackObjectRef(track_object, context)
+            track_object_ref = self._saveTrackObjectRef(track_object)
             element.append(track_object_ref)
 
         return element
 
-    def _loadTrackObjectRefs(self, element, context):
+    def _loadTrackObjectRefs(self, element):
         track_objects = []
         for track_object_element in element:
-            track_object = self._loadTrackObjectRef(track_object_element, context)
+            track_object = self._loadTrackObjectRef(track_object_element)
             track_objects.append(track_object)
 
         return track_objects
 
-    def _saveTrack(self, track, context):
+    def _saveTrack(self, track):
         element = Element("track")
-        stream_element = self._saveStream(track.stream, context)
+        stream_element = self._saveStream(track.stream)
         element.append(stream_element)
         track_objects = SubElement(element, "track-objects")
 
@@ -265,102 +269,100 @@ class ElementTreeFormatter(Formatter):
             if track_object is track.default_track_object:
                 continue
 
-            track_object_element = self._saveTrackObject(track_object, context)
+            track_object_element = self._saveTrackObject(track_object)
             track_objects.append(track_object_element)
 
         return element
 
-    def _loadTrack(self, element, context):
+    def _loadTrack(self, element):
         stream_element = element.find("stream")
-        stream = self._loadStream(stream_element, context)
+        stream = self._loadStream(stream_element)
 
         track = Track(stream)
 
         track_objects_element  = element.find("track-objects")
         for track_object_element in track_objects_element:
-            track_object = self._loadTrackObject(track_object_element, context)
+            track_object = self._loadTrackObject(track_object_element)
             track.addTrackObject(track_object)
 
         return track
 
-    def _saveTracks(self, tracks, context):
+    def _saveTracks(self, tracks):
         element = Element("tracks")
         for track in tracks:
-            track_element = self._saveTrack(track, context)
+            track_element = self._saveTrack(track)
             element.append(track_element)
 
         return element
 
-    def _loadTracks(self, element, context):
+    def _loadTracks(self, element):
         tracks = []
         for track_element in element:
-            track = self._loadTrack(track_element, context)
+            track = self._loadTrack(track_element)
             tracks.append(track)
 
         return tracks
 
-    def _saveTimelineObject(self, timeline_object, context):
+    def _saveTimelineObject(self, timeline_object):
         element = Element("timeline-object")
-        factory_ref = self._saveFactoryRef(timeline_object.factory, context)
+        factory_ref = self._saveFactoryRef(timeline_object.factory)
         element.append(factory_ref)
         track_object_refs = \
-                self._saveTrackObjectRefs(timeline_object.track_objects,
-                        context)
+                self._saveTrackObjectRefs(timeline_object.track_objects)
         element.append(track_object_refs)
-        
+
         return element
 
-    def _loadTimelineObject(self, element, context):
+    def _loadTimelineObject(self, element):
         factory_ref = element.find("factory-ref")
-        factory = self._loadFactoryRef(factory_ref, context)
+        factory = self._loadFactoryRef(factory_ref)
 
         timeline_object = TimelineObject(factory)
         track_object_refs_element = element.find("track-object-refs")
         track_objects = \
-                self._loadTrackObjectRefs(track_object_refs_element, context)
+                self._loadTrackObjectRefs(track_object_refs_element)
 
         for track_object in track_objects:
             timeline_object.addTrackObject(track_object)
 
         return timeline_object
 
-    def _saveTimelineObjects(self, timeline_objects, context):
+    def _saveTimelineObjects(self, timeline_objects):
         element = Element("timeline-objects")
         for timeline_object in timeline_objects:
-            timeline_object_element = self._saveTimelineObject(timeline_object,
-                    context)
+            timeline_object_element = self._saveTimelineObject(timeline_object)
             element.append(timeline_object_element)
 
         return element
 
-    def _loadTimelineObjects(self, element, context):
+    def _loadTimelineObjects(self, element):
         timeline_objects = []
         for timeline_object_element in element:
             timeline_object = \
-                    self._loadTimelineObject(timeline_object_element, context)
+                    self._loadTimelineObject(timeline_object_element)
             timeline_objects.append(timeline_object)
 
         return timeline_objects
 
-    def _saveTimeline(self, timeline, context):
+    def _saveTimeline(self, timeline):
         element = Element("timeline")
 
-        tracks = self._saveTracks(timeline.tracks, context)
+        tracks = self._saveTracks(timeline.tracks)
         element.append(tracks)
 
         timeline_objects = \
-                self._saveTimelineObjects(timeline.timeline_objects, context)
+                self._saveTimelineObjects(timeline.timeline_objects)
         element.append(timeline_objects)
 
         return element
 
-    def _loadTimeline(self, element, context):
+    def _loadTimeline(self, element):
         tracks_element = element.find("tracks")
-        tracks = self._loadTracks(tracks_element, context)
+        tracks = self._loadTracks(tracks_element)
 
         timeline_objects_element = element.find("timeline-objects")
         timeline_objects = \
-                self._loadTimelineObjects(timeline_objects_element, context)
+                self._loadTimelineObjects(timeline_objects_element)
 
         timeline = Timeline()
         for track in tracks:
@@ -371,31 +373,31 @@ class ElementTreeFormatter(Formatter):
 
         return timeline
 
-    def _saveMainTag(self, context):
+    def _saveMainTag(self):
         element = Element("pitivi")
         element.attrib["formatter"] = "etree"
         element.attrib["version"] = version
 
         return element
 
-    def _saveProject(self, project, context):
-        root = self._saveMainTag(context)
+    def _saveProject(self, project):
+        root = self._saveMainTag()
 
         factories = project.sources.sources.values()
-        factories_element = self._saveFactories(factories, context)
+        factories_element = self._saveFactories(factories)
         root.append(factories_element)
 
-        timeline_element = self._saveTimeline(project.timeline, context)
+        timeline_element = self._saveTimeline(project.timeline)
         root.append(timeline_element)
 
         return root
 
-    def _loadProject(self, element, context):
+    def _loadProject(self, element):
         factories_element = element.find("factories")
-        factories = self._loadFactories(factories_element, context)
+        factories = self._loadFactories(factories_element)
 
         timeline_element = element.find("timeline")
-        timeline = self._loadTimeline(timeline_element, context)
+        timeline = self._loadTimeline(timeline_element)
 
         project = Project()
         project.timeline = timeline
diff --git a/tests/test_formatter.py b/tests/test_formatter.py
index fef6d46..2ca4ce6 100644
--- a/tests/test_formatter.py
+++ b/tests/test_formatter.py
@@ -44,11 +44,10 @@ def ts(time):
 class TestFormatterSave(TestCase):
     def setUp(self):
         self.formatter = FakeElementTreeFormatter()
-        self.context = ElementTreeFormatterSaveContext()
 
     def testSaveStream(self):
         stream = VideoStream(gst.Caps("video/x-raw-rgb, blah=meh"))
-        element = self.formatter._saveStream(stream, self.context)
+        element = self.formatter._saveStream(stream)
         self.failUnlessEqual(element.tag, "stream")
         self.failUnless("id" in element.attrib)
         self.failUnlessEqual(element.attrib["type"], qual(stream.__class__))
@@ -57,8 +56,8 @@ class TestFormatterSave(TestCase):
     def testSaveStreamRef(self):
         # save a stream so that a mapping is created in the context
         stream = VideoStream(gst.Caps("video/x-raw-rgb, blah=meh"))
-        element = self.formatter._saveStream(stream, self.context)
-        element_ref = self.formatter._saveStreamRef(stream, self.context)
+        element = self.formatter._saveStream(stream)
+        element_ref = self.formatter._saveStreamRef(stream)
         self.failUnlessEqual(element_ref.tag, "stream-ref")
         self.failUnlessEqual(element_ref.attrib["id"], element.attrib["id"])
 
@@ -68,7 +67,7 @@ class TestFormatterSave(TestCase):
         source1 = FileSourceFactory("file1.ogg")
         source1.addOutputStream(video_stream)
         source1.addOutputStream(audio_stream)
-        element = self.formatter._saveSource(source1, self.context)
+        element = self.formatter._saveSource(source1)
         self.failUnlessEqual(element.tag, "source")
         self.failUnlessEqual(element.attrib["type"], qual(source1.__class__))
         self.failUnlessEqual(element.attrib["filename"], "file1.ogg")
@@ -89,7 +88,7 @@ class TestFormatterSave(TestCase):
         source2.addOutputStream(audio_stream)
 
         factories = [source1, source2]
-        element = self.formatter._saveFactories(factories, self.context)
+        element = self.formatter._saveFactories(factories)
         self.failUnlessEqual(element.tag, "factories")
 
         sources = element.find("sources")
@@ -102,9 +101,9 @@ class TestFormatterSave(TestCase):
         source1 = FileSourceFactory("file1.ogg")
         source1.addOutputStream(video_stream)
         source1.addOutputStream(audio_stream)
-        element = self.formatter._saveSource(source1, self.context)
+        element = self.formatter._saveSource(source1)
 
-        element_ref = self.formatter._saveFactoryRef(source1, self.context)
+        element_ref = self.formatter._saveFactoryRef(source1)
         self.failUnlessEqual(element_ref.tag, "factory-ref")
         self.failUnlessEqual(element_ref.attrib["id"], element.attrib["id"])
 
@@ -115,15 +114,15 @@ class TestFormatterSave(TestCase):
 
         # these two calls are needed to populate the context for the -ref
         # elements
-        self.formatter._saveSource(source1, self.context)
-        self.formatter._saveStream(video_stream, self.context)
+        self.formatter._saveSource(source1)
+        self.formatter._saveStream(video_stream)
 
         track_object = SourceTrackObject(source1, video_stream,
                 start=10 * gst.SECOND, duration=20 * gst.SECOND,
                 in_point=5 * gst.SECOND, media_duration=15 * gst.SECOND,
                 priority=10)
 
-        element = self.formatter._saveTrackObject(track_object, self.context)
+        element = self.formatter._saveTrackObject(track_object)
         self.failUnlessEqual(element.tag, "track-object")
         self.failUnlessEqual(element.attrib["type"],
                 qual(track_object.__class__))
@@ -144,17 +143,16 @@ class TestFormatterSave(TestCase):
 
         # these two calls are needed to populate the context for the -ref
         # elements
-        self.formatter._saveSource(source1, self.context)
-        self.formatter._saveStream(video_stream, self.context)
+        self.formatter._saveSource(source1)
+        self.formatter._saveStream(video_stream)
 
         track_object = SourceTrackObject(source1, video_stream,
                 start=10 * gst.SECOND, duration=20 * gst.SECOND,
                 in_point=5 * gst.SECOND, media_duration=15 * gst.SECOND,
                 priority=10)
 
-        element = self.formatter._saveTrackObject(track_object, self.context)
-        element_ref = self.formatter._saveTrackObjectRef(track_object,
-                self.context)
+        element = self.formatter._saveTrackObject(track_object)
+        element_ref = self.formatter._saveTrackObjectRef(track_object)
         self.failUnlessEqual(element_ref.tag, "track-object-ref")
         self.failUnlessEqual(element.attrib["id"], element.attrib["id"])
 
@@ -165,8 +163,8 @@ class TestFormatterSave(TestCase):
 
         # these two calls are needed to populate the context for the -ref
         # elements
-        self.formatter._saveSource(source1, self.context)
-        self.formatter._saveStream(video_stream, self.context)
+        self.formatter._saveSource(source1)
+        self.formatter._saveStream(video_stream)
 
         track_object = SourceTrackObject(source1, video_stream,
                 start=10 * gst.SECOND, duration=20 * gst.SECOND,
@@ -176,7 +174,7 @@ class TestFormatterSave(TestCase):
         track = Track(video_stream)
         track.addTrackObject(track_object)
 
-        element = self.formatter._saveTrack(track, self.context)
+        element = self.formatter._saveTrack(track)
         self.failUnlessEqual(element.tag, "track")
         track_objects_element = element.find("track-objects")
         self.failUnlessEqual(len(track_objects_element), 1)
@@ -188,20 +186,20 @@ class TestFormatterSave(TestCase):
 
         # these two calls are needed to populate the context for the -ref
         # elements
-        self.formatter._saveSource(source1, self.context)
-        self.formatter._saveStream(video_stream, self.context)
+        self.formatter._saveSource(source1)
+        self.formatter._saveStream(video_stream)
 
         track_object = SourceTrackObject(source1, video_stream,
                 start=10 * gst.SECOND, duration=20 * gst.SECOND,
                 in_point=5 * gst.SECOND, media_duration=15 * gst.SECOND,
                 priority=10)
 
-        self.formatter._saveTrackObject(track_object, self.context)
+        self.formatter._saveTrackObject(track_object)
 
         timeline_object = TimelineObject(source1)
         timeline_object.addTrackObject(track_object)
 
-        element = self.formatter._saveTimelineObject(timeline_object, self.context)
+        element = self.formatter._saveTimelineObject(timeline_object)
         self.failUnlessEqual(element.tag, "timeline-object")
         self.failIfEqual(element.find("factory-ref"), None)
         track_object_refs = element.find("track-object-refs")
@@ -214,21 +212,20 @@ class TestFormatterSave(TestCase):
 
         # these two calls are needed to populate the context for the -ref
         # elements
-        self.formatter._saveSource(source1, self.context)
-        self.formatter._saveStream(video_stream, self.context)
+        self.formatter._saveSource(source1)
+        self.formatter._saveStream(video_stream)
 
         track_object = SourceTrackObject(source1, video_stream,
                 start=10 * gst.SECOND, duration=20 * gst.SECOND,
                 in_point=5 * gst.SECOND, media_duration=15 * gst.SECOND,
                 priority=10)
 
-        self.formatter._saveTrackObject(track_object, self.context)
+        self.formatter._saveTrackObject(track_object)
 
         timeline_object = TimelineObject(source1)
         timeline_object.addTrackObject(track_object)
 
-        element = self.formatter._saveTimelineObjects([timeline_object],
-                self.context)
+        element = self.formatter._saveTimelineObjects([timeline_object])
         self.failUnlessEqual(len(element), 1)
 
     def testSaveTimeline(self):
@@ -236,15 +233,15 @@ class TestFormatterSave(TestCase):
         audio_stream = AudioStream(gst.Caps("audio/x-raw-int"))
         source1 = VideoTestSourceFactory()
 
-        self.formatter._saveSource(source1, self.context)
-        self.formatter._saveStream(video_stream, self.context)
+        self.formatter._saveSource(source1)
+        self.formatter._saveStream(video_stream)
 
         track_object = SourceTrackObject(source1, video_stream,
                 start=10 * gst.SECOND, duration=20 * gst.SECOND,
                 in_point=5 * gst.SECOND, media_duration=15 * gst.SECOND,
                 priority=10)
 
-        self.formatter._saveTrackObject(track_object, self.context)
+        self.formatter._saveTrackObject(track_object)
 
         track = Track(video_stream)
         track.addTrackObject(track_object)
@@ -252,18 +249,18 @@ class TestFormatterSave(TestCase):
         timeline_object = TimelineObject(source1)
         timeline_object.addTrackObject(track_object)
 
-        self.formatter._saveTimelineObject(timeline_object, self.context)
+        self.formatter._saveTimelineObject(timeline_object)
 
         timeline = Timeline()
         timeline.addTrack(track)
 
-        element = self.formatter._saveTimeline(timeline, self.context)
+        element = self.formatter._saveTimeline(timeline)
         self.failUnlessEqual(element.tag, "timeline")
         tracks = element.find("tracks")
         self.failUnlessEqual(len(tracks), 1)
 
     def testSaveMainTag(self):
-        element = self.formatter._saveMainTag(self.context)
+        element = self.formatter._saveMainTag()
         self.failUnlessEqual(element.tag, "pitivi")
         self.failUnlessEqual(element.attrib["formatter"], "etree")
         self.failUnlessEqual(element.attrib["version"], version)
@@ -273,15 +270,15 @@ class TestFormatterSave(TestCase):
         audio_stream = AudioStream(gst.Caps("audio/x-raw-int"))
         source1 = VideoTestSourceFactory()
 
-        self.formatter._saveSource(source1, self.context)
-        self.formatter._saveStream(video_stream, self.context)
+        self.formatter._saveSource(source1)
+        self.formatter._saveStream(video_stream)
 
         track_object = SourceTrackObject(source1, video_stream,
                 start=10 * gst.SECOND, duration=20 * gst.SECOND,
                 in_point=5 * gst.SECOND, media_duration=15 * gst.SECOND,
                 priority=10)
 
-        self.formatter._saveTrackObject(track_object, self.context)
+        self.formatter._saveTrackObject(track_object)
 
         track = Track(video_stream)
         track.addTrackObject(track_object)
@@ -289,18 +286,18 @@ class TestFormatterSave(TestCase):
         timeline_object = TimelineObject(source1)
         timeline_object.addTrackObject(track_object)
 
-        self.formatter._saveTimelineObject(timeline_object, self.context)
+        self.formatter._saveTimelineObject(timeline_object)
 
         timeline = Timeline()
         timeline.addTrack(track)
 
-        self.formatter._saveTimeline(timeline, self.context)
+        self.formatter._saveTimeline(timeline)
 
         project = Project()
         project.timeline = timeline
         project.sources.addFactory("meh", source1)
 
-        element = self.formatter._saveProject(project, self.context)
+        element = self.formatter._saveProject(project)
 
         self.failUnlessEqual(element.tag, "pitivi")
         self.failIfEqual(element.find("factories"), None)
@@ -310,7 +307,6 @@ class TestFormatterSave(TestCase):
 class TestFormatterLoad(TestCase):
     def setUp(self):
         self.formatter = FakeElementTreeFormatter()
-        self.context = ElementTreeFormatterLoadContext()
 
     def testLoadStream(self):
         caps = gst.Caps("video/x-raw-yuv")
@@ -319,17 +315,17 @@ class TestFormatterLoad(TestCase):
         element.attrib["type"] = "pitivi.stream.VideoStream"
         element.attrib["caps"] = str(caps)
 
-        stream = self.formatter._loadStream(element, self.context)
+        stream = self.formatter._loadStream(element)
         self.failUnlessEqual(qual(stream.__class__), element.attrib["type"])
         self.failUnlessEqual(str(stream.caps), str(caps))
-        self.failUnlessEqual(stream, self.context.streams["1"])
+        self.failUnlessEqual(stream, self.formatter._context.streams["1"])
 
     def testLoadStreamRef(self):
         stream = VideoStream(gst.Caps("meh"))
-        self.context.streams["1"] = stream
+        self.formatter._context.streams["1"] = stream
         element = Element("stream-ref")
         element.attrib["id"] = "1"
-        stream1 = self.formatter._loadStreamRef(element, self.context)
+        stream1 = self.formatter._loadStreamRef(element)
         self.failUnlessEqual(stream, stream1)
 
     def testLoadFactory(self):
@@ -343,18 +339,18 @@ class TestFormatterLoad(TestCase):
         output_stream.attrib["type"] = "pitivi.stream.VideoStream"
         output_stream.attrib["caps"] = str(caps)
 
-        factory = self.formatter._loadFactory(element, self.context)
+        factory = self.formatter._loadFactory(element)
         self.failUnless(isinstance(factory, VideoTestSourceFactory))
         self.failUnlessEqual(len(factory.output_streams), 2)
 
-        self.failUnlessEqual(self.context.factories["1"], factory)
+        self.failUnlessEqual(self.formatter._context.factories["1"], factory)
 
     def testLoadFactoryRef(self):
         class Tag(object): pass
         tag = Tag()
-        self.context.factories["1"] = tag
+        self.formatter._context.factories["1"] = tag
         element = Element("factory-ref", id="1")
-        ret = self.formatter._loadFactoryRef(element, self.context)
+        ret = self.formatter._loadFactoryRef(element)
         self.failUnless(ret is tag)
 
     def testLoadTrackObject(self):
@@ -364,13 +360,13 @@ class TestFormatterLoad(TestCase):
                 in_point=ts(5 * gst.SECOND),
                 media_duration=ts(15 * gst.SECOND), priority=ts(5))
         factory = VideoTestSourceFactory()
-        self.context.factories["1"] = factory
+        self.formatter._context.factories["1"] = factory
         stream = VideoStream(gst.Caps("meh"))
-        self.context.streams["1"] = stream
+        self.formatter._context.streams["1"] = stream
         factory_ref = SubElement(element, "factory-ref", id="1")
         stream_ref = SubElement(element, "stream-ref", id="1")
 
-        track_object = self.formatter._loadTrackObject(element, self.context)
+        track_object = self.formatter._loadTrackObject(element)
         self.failUnless(isinstance(track_object, SourceTrackObject))
         self.failUnlessEqual(track_object.factory, factory)
         self.failUnlessEqual(track_object.stream, stream)
@@ -385,9 +381,9 @@ class TestFormatterLoad(TestCase):
         class Tag(object):
             pass
         tag = Tag()
-        self.context.track_objects["1"] = tag
+        self.formatter._context.track_objects["1"] = tag
         element = Element("track-object-ref", id="1")
-        ret = self.formatter._loadTrackObjectRef(element, self.context)
+        ret = self.formatter._loadTrackObjectRef(element)
         self.failUnless(ret is tag)
 
     def testLoadTrack(self):
@@ -402,13 +398,13 @@ class TestFormatterLoad(TestCase):
                 in_point=ts(5 * gst.SECOND),
                 media_duration=ts(15 * gst.SECOND), priority=ts(5))
         factory = VideoTestSourceFactory()
-        self.context.factories["1"] = factory
+        self.formatter._context.factories["1"] = factory
         stream = VideoStream(gst.Caps("video/x-raw-rgb"))
-        self.context.streams["1"] = stream
+        self.formatter._context.streams["1"] = stream
         factory_ref = SubElement(track_object, "factory-ref", id="1")
         stream_ref = SubElement(track_object, "stream-ref", id="1")
 
-        track = self.formatter._loadTrack(element, self.context)
+        track = self.formatter._loadTrack(element)
 
         self.failUnlessEqual(len(track.track_objects), 2)
         # FIXME: this is an hack
@@ -417,8 +413,8 @@ class TestFormatterLoad(TestCase):
     def testLoadTimelineObject(self):
         video_stream = VideoStream(gst.Caps("video/x-raw-yuv"))
         source1 = VideoTestSourceFactory()
-        self.context.factories["1"] = source1
-        self.context.track_objects["1"] = SourceTrackObject(source1, video_stream)
+        self.formatter._context.factories["1"] = source1
+        self.formatter._context.track_objects["1"] = SourceTrackObject(source1, video_stream)
 
         element = Element("timeline-object")
         factory_ref = SubElement(element, "factory-ref", id="1")
@@ -428,7 +424,7 @@ class TestFormatterLoad(TestCase):
                 "track-object-ref", id="1")
 
         timeline_object = \
-                self.formatter._loadTimelineObject(element, self.context)
+                self.formatter._loadTimelineObject(element)
 
         self.failUnlessEqual(timeline_object.factory, source1)
         self.failUnlessEqual(len(timeline_object.track_objects), 1)
@@ -447,16 +443,16 @@ class TestFormatterLoad(TestCase):
                 in_point=ts(5 * gst.SECOND),
                 media_duration=ts(15 * gst.SECOND), priority=ts(5))
         factory = VideoTestSourceFactory()
-        self.context.factories["1"] = factory
+        self.formatter._context.factories["1"] = factory
         stream = VideoStream(gst.Caps("video/x-raw-rgb"))
-        self.context.streams["1"] = stream
+        self.formatter._context.streams["1"] = stream
         factory_ref = SubElement(track_object, "factory-ref", id="1")
         stream_ref = SubElement(track_object, "stream-ref", id="1")
 
         video_stream = VideoStream(gst.Caps("video/x-raw-yuv"))
         source1 = VideoTestSourceFactory()
-        self.context.factories["2"] = source1
-        self.context.track_objects["1"] = SourceTrackObject(source1, video_stream)
+        self.formatter._context.factories["2"] = source1
+        self.formatter._context.track_objects["1"] = SourceTrackObject(source1, video_stream)
 
         timeline_objects_element = SubElement(timeline_element,
                 "timeline-objects")
@@ -467,7 +463,7 @@ class TestFormatterLoad(TestCase):
         track_object_refs = SubElement(timeline_object_element, "track-object-refs")
         track_object_ref = SubElement(track_object_refs,
                 "track-object-ref", id="1")
-        timeline = self.formatter._loadTimeline(timeline_element, self.context)
+        timeline = self.formatter._loadTimeline(timeline_element)
         self.failUnlessEqual(len(timeline.tracks), 1)
 
     def testLoadProject(self):
@@ -475,15 +471,15 @@ class TestFormatterLoad(TestCase):
         audio_stream = AudioStream(gst.Caps("audio/x-raw-int"))
         source1 = VideoTestSourceFactory()
 
-        self.formatter._saveSource(source1, self.context)
-        self.formatter._saveStream(video_stream, self.context)
+        self.formatter._saveSource(source1)
+        self.formatter._saveStream(video_stream)
 
         track_object = SourceTrackObject(source1, video_stream,
                 start=10 * gst.SECOND, duration=20 * gst.SECOND,
                 in_point=5 * gst.SECOND, media_duration=15 * gst.SECOND,
                 priority=10)
 
-        self.formatter._saveTrackObject(track_object, self.context)
+        self.formatter._saveTrackObject(track_object)
 
         track = Track(video_stream)
         track.addTrackObject(track_object)
@@ -491,18 +487,18 @@ class TestFormatterLoad(TestCase):
         timeline_object = TimelineObject(source1)
         timeline_object.addTrackObject(track_object)
 
-        self.formatter._saveTimelineObject(timeline_object, self.context)
+        self.formatter._saveTimelineObject(timeline_object)
 
         timeline = Timeline()
         timeline.addTrack(track)
 
-        self.formatter._saveTimeline(timeline, self.context)
+        self.formatter._saveTimeline(timeline)
 
         project = Project()
         project.timeline = timeline
         project.sources.addFactory("meh", source1)
 
-        element = self.formatter._saveProject(project, self.context)
+        element = self.formatter._saveProject(project)
 
         self.failUnlessEqual(element.tag, "pitivi")
         self.failIfEqual(element.find("factories"), None)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]