[gedit-plugins/sessionsaver] More UT



commit ca9e64d9cb030e26fdba8e28950f0a39ccd2e976
Author: Jordi Mas <jmas softcatala org>
Date:   Thu Jul 4 23:16:24 2019 +0200

    More UT

 .../sessionsaver/store/xmlsessionstore.py          |  5 ++
 plugins/sessionsaver/tests/meson.build             |  1 +
 plugins/sessionsaver/tests/test-saved-sessions.xml | 19 +++++++
 plugins/sessionsaver/tests/testxmlsessionstore.py  | 58 ++++++++++++++++++++++
 4 files changed, 83 insertions(+)
---
diff --git a/plugins/sessionsaver/sessionsaver/store/xmlsessionstore.py 
b/plugins/sessionsaver/sessionsaver/store/xmlsessionstore.py
index 07d96dd..2b824f4 100644
--- a/plugins/sessionsaver/sessionsaver/store/xmlsessionstore.py
+++ b/plugins/sessionsaver/sessionsaver/store/xmlsessionstore.py
@@ -32,6 +32,11 @@ class XMLSessionStore(SessionStore):
         self.filename = os.path.join(GLib.get_user_config_dir(), 'gedit/saved-sessions.xml')
         self.load()
 
+    def __init__(self, filename):
+        super(XMLSessionStore, self).__init__()
+        self.filename = filename
+        self.load()
+
     def _escape(self, string):
         return string.replace('&', '&amp;') \
                      .replace('<', '&lt;')  \
diff --git a/plugins/sessionsaver/tests/meson.build b/plugins/sessionsaver/tests/meson.build
index 3016169..eaf7da6 100644
--- a/plugins/sessionsaver/tests/meson.build
+++ b/plugins/sessionsaver/tests/meson.build
@@ -1,6 +1,7 @@
 sessionsaver_tests = {
   'session': files('testsession.py'),
   'sessionstore': files('testsessionstore.py'),
+  'xmlsessionstore': files('testxmlsessionstore.py'),
 }
 
 sessionsaver_srcdir = join_paths(
diff --git a/plugins/sessionsaver/tests/test-saved-sessions.xml 
b/plugins/sessionsaver/tests/test-saved-sessions.xml
new file mode 100644
index 0000000..4be2aae
--- /dev/null
+++ b/plugins/sessionsaver/tests/test-saved-sessions.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<saved-sessions>
+<session name="files">
+  <file path="file:///xmlsessionstore.py"/>
+</session>
+<session name="gspell">
+  <file path="file:///home/jordi/dev/gedit/gspell/gspell/gspellregion.c"/>
+  <file path="file:///home/jordi/dev/gedit/gspell/gspell/gspell-text-view.c"/>
+  <file path="file:///home/jordi/dev/gedit/gspell/gspell/gspell-text-buffer.c"/>
+  <file path="file:///home/jordi/dev/gedit/gspell/gspell/gspell-navigator.c"/>
+  <file path="file:///home/jordi/dev/gedit/gspell/gspell/gspell-language-chooser.c"/>
+  <file path="file:///home/jordi/dev/gedit/gspell/gspell/gspell-language-chooser-dialog.c"/>
+  <file path="file:///home/jordi/dev/gedit/gspell/gspell/gspell-language-chooser-button.c"/>
+</session>
+<session name="window-activable">
+  <file path="file:///home/jordi/dev/gedit/gedit-plugins/plugins/sessionsaver/meson.build"/>
+  <file 
path="file:///home/jordi/dev/gedit/gedit-plugins/plugins/sessionsaver/sessionsaver/windowactivable.py"/>
+</session>
+</saved-sessions>
diff --git a/plugins/sessionsaver/tests/testxmlsessionstore.py 
b/plugins/sessionsaver/tests/testxmlsessionstore.py
new file mode 100644
index 0000000..48d088f
--- /dev/null
+++ b/plugins/sessionsaver/tests/testxmlsessionstore.py
@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2019 Jordi Mas i Hernandez <jmas softcatala org>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+
+import unittest
+import tempfile
+from store.session import Session
+from store.xmlsessionstore import XMLSessionStore
+from os import path
+
+class TestXmlSessionStore(unittest.TestCase):
+
+    def test_load(self):
+
+        store_file = path.dirname(path.realpath(__file__))
+        store_file += '/test-saved-sessions.xml'
+        print(store_file)
+
+        store = XMLSessionStore(store_file)
+        self.assertEqual(3, len(store))
+        self.assertEqual('files', store[0].name)
+        self.assertEqual('gspell', store[1].name)
+        self.assertEqual('window-activable', store[2].name)
+
+        self.assertEqual(1, len(store[0].files))
+        self.assertEqual("/xmlsessionstore.py", store[0].files[0].get_path())
+
+    def test_save(self):
+        session_name = "session_A"
+        tmpfile = tempfile.NamedTemporaryFile()
+        store = XMLSessionStore(tmpfile.name)
+        session = Session(session_name)
+        store.add(session)
+        store.save()
+
+        store = XMLSessionStore(tmpfile.name)
+        self.assertEqual(1, len(store))
+        self.assertEqual(session_name, store[0].name)
+
+
+if __name__ == '__main__':
+    unittest.main()


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