[pitivi] preset: Clarify where default_path and user_path come from



commit f57b9c40df2f3830bdfc5c873a3e5c7357ca604c
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Fri May 29 05:22:12 2015 +0200

    preset: Clarify where default_path and user_path come from
    
    Differential Revision: https://phabricator.freedesktop.org/D358
    Reviewed-by: Thibault Saunier <tsaunier gnome org>

 pitivi/preset.py              |   25 +++++++++++++++++--------
 tests/test_preset.py          |   15 +++++----------
 tests/test_projectsettings.py |    2 +-
 3 files changed, 23 insertions(+), 19 deletions(-)
---
diff --git a/pitivi/preset.py b/pitivi/preset.py
index dc90196..718472d 100644
--- a/pitivi/preset.py
+++ b/pitivi/preset.py
@@ -65,7 +65,10 @@ class PresetManager(object):
     @type widget_map: dict
     """
 
-    def __init__(self):
+    def __init__(self, default_path, user_path):
+        self.default_path = default_path
+        self.user_path = user_path
+
         self.presets = {}
         self.widget_map = {}
         self.ordered = Gtk.ListStore(str, object)
@@ -277,7 +280,7 @@ class PresetManager(object):
             return self._isCurrentPresetChanged()
 
     def isRemoveButtonSensitive(self):
-        """Check if Remove buttons should be sensitive"""
+        """Check if the Remove button should be sensitive"""
         if not self.cur_preset:
             return False
         try:
@@ -321,8 +324,10 @@ class PresetManager(object):
 
 class VideoPresetManager(PresetManager):
 
-    default_path = get_videopresets_dir()
-    user_path = os.path.join(xdg_data_home(), 'video_presets')
+    def __init__(self):
+        default_path = get_videopresets_dir()
+        user_path = os.path.join(xdg_data_home(), 'video_presets')
+        PresetManager.__init__(self, default_path, user_path)
 
     def _loadSection(self, filepath):
         with open(filepath) as section:
@@ -371,8 +376,10 @@ class VideoPresetManager(PresetManager):
 
 class AudioPresetManager(PresetManager):
 
-    default_path = get_audiopresets_dir()
-    user_path = os.path.join(xdg_data_home(), 'audio_presets')
+    def __init__(self):
+        default_path = get_audiopresets_dir()
+        user_path = os.path.join(xdg_data_home(), 'audio_presets')
+        PresetManager.__init__(self, default_path, user_path)
 
     def _loadSection(self, filepath):
         with open(filepath) as section:
@@ -405,8 +412,10 @@ class AudioPresetManager(PresetManager):
 
 class RenderPresetManager(PresetManager):
 
-    default_path = get_renderpresets_dir()
-    user_path = os.path.join(xdg_data_home(), 'render_presets')
+    def __init__(self):
+        default_path = get_renderpresets_dir()
+        user_path = os.path.join(xdg_data_home(), 'render_presets')
+        PresetManager.__init__(self, default_path, user_path)
 
     def _loadSection(self, filepath):
         with open(filepath) as section:
diff --git a/tests/test_preset.py b/tests/test_preset.py
index b4e89f2..e41a6d6 100644
--- a/tests/test_preset.py
+++ b/tests/test_preset.py
@@ -28,7 +28,6 @@ import shutil
 import tempfile
 from unittest import TestCase
 
-from pitivi.configure import get_audiopresets_dir
 from pitivi.preset import DuplicatePresetNameException, \
     PresetManager, \
     AudioPresetManager
@@ -36,15 +35,13 @@ from pitivi.preset import DuplicatePresetNameException, \
 
 class FakePresetManager(PresetManager):
 
+    def __init__(self, default_path):
+        PresetManager.__init__(self, default_path, tempfile.mkdtemp())
+
     def _saveSection(self, fout, section):
         pass
 
 
-def setPresetManagerPaths(preset_manager, default_path):
-    preset_manager.default_path = default_path
-    preset_manager.user_path = tempfile.mkdtemp()
-
-
 def clearPresetManagerPaths(preset_manager):
     shutil.rmtree(preset_manager.user_path)
 
@@ -66,8 +63,7 @@ def countUserPresets(preset_manager):
 class TestPresetBasics(TestCase):
 
     def setUp(self):
-        self.manager = FakePresetManager()
-        setPresetManagerPaths(self.manager, None)
+        self.manager = FakePresetManager(None)
 
     def tearDown(self):
         clearPresetManagerPaths(self.manager)
@@ -126,14 +122,13 @@ class TestAudioPresetsIO(TestCase):
 
     def setUp(self):
         self.manager = AudioPresetManager()
-        setPresetManagerPaths(self.manager, get_audiopresets_dir())
+        self.manager.user_path = tempfile.mkdtemp()
 
     def tearDown(self):
         clearPresetManagerPaths(self.manager)
 
     def createOtherManager(self):
         other_manager = AudioPresetManager()
-        other_manager.default_path = self.manager.default_path
         other_manager.user_path = self.manager.user_path
         return other_manager
 
diff --git a/tests/test_projectsettings.py b/tests/test_projectsettings.py
index fafe376..6ae6a6c 100644
--- a/tests/test_projectsettings.py
+++ b/tests/test_projectsettings.py
@@ -29,7 +29,7 @@ from pitivi.project import ProjectSettingsDialog
 class TestProjectSettingsDialog(TestCase):
 
     def testGetUniquePresetName(self):
-        preset_manager = PresetManager()
+        preset_manager = PresetManager(None, None)
         name = ProjectSettingsDialog._getUniquePresetName(preset_manager)
         self.assertEqual('New preset', name)
 


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