[conduit: 1/138] Start sketching out a generic test framework
- From: John Carr <johncarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [conduit: 1/138] Start sketching out a generic test framework
- Date: Thu, 21 May 2009 03:27:02 -0400 (EDT)
commit 94cbf1ce71ad01ec4a5990f146085609712633e5
Author: John Carr <john carr unrouted co uk>
Date: Sun Apr 19 13:52:00 2009 +0100
Start sketching out a generic test framework
---
test/soup/__init__.py | 57 +++++++++++++++++++++++++++++++++++++
test/soup/modules/__init__.py | 39 +++++++++++++++++++++++++
test/soup/modules/folder.py | 12 ++++++++
test/soup/test_dataprovider.py | 21 +++++++++++++
test/soup/test_synchronization.py | 3 ++
5 files changed, 132 insertions(+), 0 deletions(-)
diff --git a/test/soup/__init__.py b/test/soup/__init__.py
new file mode 100644
index 0000000..37c47f4
--- /dev/null
+++ b/test/soup/__init__.py
@@ -0,0 +1,57 @@
+
+import unittest
+
+CHANGE_ADD = 1
+CHANGE_REPLACE = 2
+CHANGE_DELETE = 3
+
+class BaseTest(unittest.TestCase):
+
+ def __init__(self):
+ super(BaseTest, self).__init__()
+
+ #Set up our own mapping DB so we dont pollute the global one
+ dbFile = os.path.join(os.environ['TEST_DIRECTORY'],Utils.random_string()+".db")
+ conduit.GLOBALS.mappingDB = MappingDB.MappingDB(dbFile)
+
+ self.modules = Module.ModuleManager(dirs)
+ conduit.GLOBALS.moduleManager = self.modules
+ self.modules.load_all(whitelist=None, blacklist=None)
+
+ self.type_converter = TypeConverter.TypeConverter(self.modules)
+ conduit.GLOBALS.typeConverter = self.type_converter
+ self.sync_manager = Synchronization.SyncManager(self.type_converter)
+ conduit.GLOBALS.syncManager = self.sync_manager
+
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def get_dataprovider(self, key):
+ wrapper = None
+ for dp in self.model.get_all_modules():
+ if dp.classname == name:
+ wrapper = self.model.get_module_wrapper_with_instance(dp.get_key())
+ assert wrapper != None
+ return wrapper
+
+ def create_syncset(self):
+ return SyncSet.SyncSet(
+ moduleManager=self.modules,
+ syncManager=self.sync_manager
+ )
+
+ def is_online(self):
+ try:
+ return os.environ["CONDUIT_ONLINE"] == "TRUE"
+ except KeyError:
+ return False
+
+ def is_interactive(self):
+ try:
+ return os.environ["CONDUIT_INTERACTIVE"] == "TRUE"
+ except KeyError:
+ return False
+
diff --git a/test/soup/modules/__init__.py b/test/soup/modules/__init__.py
new file mode 100644
index 0000000..0c5b784
--- /dev/null
+++ b/test/soup/modules/__init__.py
@@ -0,0 +1,39 @@
+
+from soup import *
+
+class ModuleWrapper(object):
+
+ def __init__(self, conduit):
+ self.conduit = conduit
+ self.dp = self.create_dataprovider()
+
+ def get_num_items(self):
+ count = 0
+ try:
+ self.dp.module.refresh()
+ count = self.dp.module.get_num_items()
+ finally:
+ self.dp.module.finish()
+ return count
+
+ def get(self, uid):
+ return self.dp.module.get(uid)
+
+ def add(self, obj):
+ self.dp.module.put(obj, False)
+
+ def update(self, uid, obj):
+ self.dp.module.put(obj, True, LUID=uid)
+
+ def delete(self, uid):
+ self.dp.module.delete(uid)
+
+ def apply_changes(self, uid):
+ for t, uid, obj in changes:
+ if t == CHANGE_ADD:
+ self.add(obj)
+ elif t == CHANGE_REPLACE:
+ self.replace(uid, obj)
+ elif t == CHANGE_DELETE:
+ self.delete(uid)
+
diff --git a/test/soup/modules/folder.py b/test/soup/modules/folder.py
new file mode 100644
index 0000000..3f69b0f
--- /dev/null
+++ b/test/soup/modules/folder.py
@@ -0,0 +1,12 @@
+import modules
+
+import conduit.utils as Utils
+
+class FolderWrapper(modules.ModuleWrapper):
+
+ def create_dataprovider(self):
+ dp = self.conduit.get_dataprovider("FolderTwoWay")
+ dp.set_configuration({
+ "source": Utils.new_tempdir(),
+ })
+ return dp
diff --git a/test/soup/test_dataprovider.py b/test/soup/test_dataprovider.py
new file mode 100644
index 0000000..458bf17
--- /dev/null
+++ b/test/soup/test_dataprovider.py
@@ -0,0 +1,21 @@
+
+class TestDataprovider(BaseTest):
+
+ def test_add(self):
+ pass
+
+ def test_replace(self):
+ pass
+
+ def test_delete(self):
+ pass
+
+ def test_refresh(self):
+ pass
+
+ def test_finish(self):
+ pass
+
+ def test_get_num_items(self):
+ pass
+
diff --git a/test/soup/test_synchronization.py b/test/soup/test_synchronization.py
new file mode 100644
index 0000000..81a1f5d
--- /dev/null
+++ b/test/soup/test_synchronization.py
@@ -0,0 +1,3 @@
+
+class TestSynchronization(BaseTest):
+ pass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]