[pitivi] Split ExportSettings.factory_settings_cache into three dicts. Simplified the code and added a unitte
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] Split ExportSettings.factory_settings_cache into three dicts. Simplified the code and added a unitte
- Date: Sun, 22 May 2011 21:36:33 +0000 (UTC)
commit 98556422dc3f6ff550203eb7d28706c21423f7f8
Author: Alex BÄ?luÈ? <alexandru balut gmail com>
Date: Thu May 5 10:44:09 2011 +0200
Split ExportSettings.factory_settings_cache into three dicts.
Simplified the code and added a unittest.
pitivi/settings.py | 41 ++++++++++++++++++++++++++++++-----------
tests/test_settings.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+), 11 deletions(-)
---
diff --git a/pitivi/settings.py b/pitivi/settings.py
index 5842fd5..56b6a21 100644
--- a/pitivi/settings.py
+++ b/pitivi/settings.py
@@ -458,8 +458,13 @@ class ExportSettings(Signallable, Loggable):
# TODO : switch to using GstFraction internally where appliable
- # TODO: initialize this cache from the project file?
- factory_settings_cache = {}
+ # The following dependant attributes caches are common to all instances!
+ # A (muxer -> containersettings) map.
+ _containersettings_cache = {}
+ # A (vencoder -> vcodecsettings) map.
+ _vcodecsettings_cache = {}
+ # A (aencoder -> acodecsettings) map.
+ _acodecsettings_cache = {}
muxers, aencoders, vencoders = available_combinations()
@@ -475,9 +480,6 @@ class ExportSettings(Signallable, Loggable):
self.vencoder = "theoraenc"
self.aencoder = "vorbisenc"
self.muxer = "oggmux"
- self.containersettings = self.factory_settings_cache.get(self.muxer, {})
- self.acodecsettings = self.factory_settings_cache.get(self.aencoder, {})
- self.vcodecsettings = self.factory_settings_cache.get(self.vencoder, {})
def copy(self):
ret = ExportSettings()
@@ -572,23 +574,40 @@ class ExportSettings(Signallable, Loggable):
""" Set the video/audio encoder and muxer """
changed = False
if not muxer == "" and not muxer == self.muxer:
- self._updateSettingsCache(self.muxer, muxer, 'containersettings')
self.muxer = muxer
changed = True
if not vencoder == "" and not vencoder == self.vencoder:
- self._updateSettingsCache(self.vencoder, vencoder, 'vcodecsettings')
self.vencoder = vencoder
changed = True
if not aencoder == "" and not aencoder == self.aencoder:
- self._updateSettingsCache(self.aencoder, aencoder, 'acodecsettings')
self.aencoder = aencoder
changed = True
if changed:
self.emit("encoders-changed")
- def _updateSettingsCache(self, current, new, attr):
- self.factory_settings_cache[current] = getattr(self, attr)
- setattr(self, attr, self.factory_settings_cache.get(new, {}))
+ @property
+ def containersettings(self):
+ return self._containersettings_cache.setdefault(self.muxer, {})
+
+ @containersettings.setter
+ def containersettings(self, value):
+ self._containersettings_cache[self.muxer] = value
+
+ @property
+ def vcodecsettings(self):
+ return self._vcodecsettings_cache.setdefault(self.vencoder, {})
+
+ @vcodecsettings.setter
+ def vcodecsettings(self, value):
+ self._vcodecsettings_cache[self.vencoder] = value
+
+ @property
+ def acodecsettings(self):
+ return self._acodecsettings_cache.setdefault(self.aencoder, {})
+
+ @acodecsettings.setter
+ def acodecsettings(self, value):
+ self._acodecsettings_cache[self.aencoder] = value
def getAudioEncoders(self):
""" Returns the list of audio encoders compatible with the current
diff --git a/tests/test_settings.py b/tests/test_settings.py
new file mode 100644
index 0000000..b808bff
--- /dev/null
+++ b/tests/test_settings.py
@@ -0,0 +1,47 @@
+import unittest
+from pitivi.settings import ExportSettings
+
+
+class TestExportSettings(unittest.TestCase):
+ """Test the settings.ExportSettings class."""
+
+ def setUp(self):
+ self.settings = ExportSettings()
+
+ def testMasterAttributes(self):
+ self._testMasterAttribute('muxer', dependant_attr='containersettings')
+ self._testMasterAttribute('vencoder', dependant_attr='vcodecsettings')
+ self._testMasterAttribute('aencoder', dependant_attr='acodecsettings')
+
+ def _testMasterAttribute(self, attr, dependant_attr):
+ """Test changing the specified attr has effect on its dependant attr."""
+ attr_value1 = "%s_value1" % attr
+ attr_value2 = "%s_value2" % attr
+
+ setattr(self.settings, attr, attr_value1)
+ setattr(self.settings, dependant_attr, {})
+ getattr(self.settings, dependant_attr)["key1"] = "v1"
+
+ setattr(self.settings, attr, attr_value2)
+ setattr(self.settings, dependant_attr, {})
+ getattr(self.settings, dependant_attr)["key2"] = "v2"
+
+ setattr(self.settings, attr, attr_value1)
+ self.assertTrue("key1" in getattr(self.settings, dependant_attr))
+ self.assertFalse("key2" in getattr(self.settings, dependant_attr))
+ self.assertEqual("v1", getattr(self.settings, dependant_attr)["key1"])
+ setattr(self.settings, dependant_attr, {})
+
+ setattr(self.settings, attr, attr_value2)
+ self.assertFalse("key1" in getattr(self.settings, dependant_attr))
+ self.assertTrue("key2" in getattr(self.settings, dependant_attr))
+ self.assertEqual("v2", getattr(self.settings, dependant_attr)["key2"])
+ setattr(self.settings, dependant_attr, {})
+
+ setattr(self.settings, attr, attr_value1)
+ self.assertFalse("key1" in getattr(self.settings, dependant_attr))
+ self.assertFalse("key2" in getattr(self.settings, dependant_attr))
+
+ setattr(self.settings, attr, attr_value2)
+ self.assertFalse("key1" in getattr(self.settings, dependant_attr))
+ self.assertFalse("key2" in getattr(self.settings, dependant_attr))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]