Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Silbe <sascha@silbe.org>2009-08-11 22:54:53 (GMT)
committer Sascha Silbe <sascha@silbe.org>2009-08-13 22:36:17 (GMT)
commit8c579d402ea671b04aa9929d86c53f4fb0af50b9 (patch)
tree10ad45f9fca3042699c4c45510db83d848d3bb1d
parent9b9ac683b5797c7cfc24d87a14a56e19e1d129e9 (diff)
test via DBus API instead of direct class access, set up (and clean afterwards) a clean directory for testing
-rw-r--r--tests/Makefile8
-rw-r--r--tests/dateranges.txt4
-rw-r--r--tests/properties.txt4
-rwxr-xr-x[-rw-r--r--]tests/runalltests.py84
-rw-r--r--tests/sugar_demo_may17.txt5
5 files changed, 70 insertions, 35 deletions
diff --git a/tests/Makefile b/tests/Makefile
index c2581cb..f296619 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,11 +1,7 @@
-# howto inherit this properly from above?
-# its not an option to configure
-PYTHON=python
-
all: clean test
-test:
- @${PYTHON} runalltests.py
+test:
+ @./runalltests.py
valgrind:
@echo "Profiling the process. Run kcachegrind on the output"
diff --git a/tests/dateranges.txt b/tests/dateranges.txt
index 886e7d2..159a365 100644
--- a/tests/dateranges.txt
+++ b/tests/dateranges.txt
@@ -3,8 +3,8 @@ First clean up from any other tests.
>>> import os, datetime
>>> assert os.system('rm -rf /tmp/test_ds/') == 0
->>> from olpc.datastore import DataStore
->>> from olpc.datastore import backingstore, model
+>>> from carquinyol.datastore import DataStore
+>>> from carquinyol.datastore import backingstore, model
>>> ds = DataStore()
>>> ds.registerBackend(backingstore.FileBackingStore)
diff --git a/tests/properties.txt b/tests/properties.txt
index 6c3c91b..8419866 100644
--- a/tests/properties.txt
+++ b/tests/properties.txt
@@ -7,8 +7,8 @@ properties to content and managing them.
>>> assert os.system('rm -rf /tmp/store2/') == 0
->>> from olpc.datastore import DataStore
->>> from olpc.datastore import backingstore, model
+>>> from carquinyol.datastore import DataStore
+>>> from carquinyol.datastore import backingstore, model
>>> from testutils import tmpData
>>> import dbus
diff --git a/tests/runalltests.py b/tests/runalltests.py
index 8fee87e..4e2db57 100644..100755
--- a/tests/runalltests.py
+++ b/tests/runalltests.py
@@ -5,41 +5,63 @@
# Execute like:
# python runalltests.py
#
-# Alternatively use the testrunner:
-# python /path/to/Zope/utilities/testrunner.py -qa
-#
-import os, sys
-import unittest
import doctest
-from pkg_resources import resource_filename
+import os
+import shutil
+import signal
+import subprocess
+import sys
+import tempfile
+import unittest
+try:
+ from pkg_resources import resource_filename
+except ImportError :
+ def resource_filename(my_name, file_name) :
+ return file_name
+
import logging
+import dbus.mainloop.glib
+
logging.basicConfig(level=logging.WARN,
format="%(asctime)-15s %(name)s %(levelname)s: %(message)s",
stream=sys.stderr)
doctests = [
- resource_filename(__name__, "xapianindex.txt"),
- resource_filename(__name__, "milestone_1.txt"),
- resource_filename(__name__, "sugar_demo_may17.txt"),
- resource_filename(__name__, "milestone_2.txt"),
- resource_filename(__name__, "mountpoints.txt"),
- resource_filename(__name__, "properties.txt"),
- resource_filename(__name__, "dateranges.txt"),
-
+ resource_filename(__name__, "basic_api.txt"),
]
doctest_options = doctest.ELLIPSIS
#doctest_options |= doctest.REPORT_ONLY_FIRST_FAILURE
-def test_suite():
+def setup():
+ """Prepare test environment
+
+ Sets HOME and creates a new process group so we can clean up easily later.
+ """
+ os.environ['HOME'] = tempfile.mkdtemp(prefix='datastore-test')
+ os.setpgid(0, 0)
+ # prevent suicide in cleanup()
+ signal.signal(signal.SIGTERM, signal.SIG_IGN)
+
+
+def cleanup():
+ """Clean up test environment.
+
+ Kills all children and removes home directory.
+ """
+ os.kill(0, signal.SIGTERM)
+ shutil.rmtree(os.environ['HOME'])
+
+
+def test_suite(tests=[]):
global doctests
suite = unittest.TestSuite()
- if len(sys.argv) > 1:
- doctests = sys.argv[1:]
-
+ if tests:
+ doctests = tests
+
for dt in doctests:
suite.addTest(doctest.DocFileSuite(dt,
optionflags=doctest_options))
@@ -56,8 +78,28 @@ def test_suite():
return suite
-if __name__ == "__main__":
+def run_tests(tests):
runner = unittest.TextTestRunner(verbosity=1)
- suite = test_suite()
+ suite = test_suite(tests)
runner.run(suite)
-
+
+def main(my_name, arguments) :
+ if "--have-dbus" not in arguments :
+ setup()
+ try :
+ pipe = subprocess.Popen(['dbus-launch',
+ os.path.abspath(my_name), '--have-dbus']+arguments,
+ cwd=os.environ['HOME'])
+ return pipe.wait()
+
+ finally :
+ cleanup()
+
+ else :
+ run_tests(arguments[1:])
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv[0], sys.argv[1:]))
+
diff --git a/tests/sugar_demo_may17.txt b/tests/sugar_demo_may17.txt
index 64d49e5..53c67e3 100644
--- a/tests/sugar_demo_may17.txt
+++ b/tests/sugar_demo_may17.txt
@@ -1,10 +1,7 @@
How Sugar will interact with the DS for the May 17th demo in Argentina:
->>> from olpc.datastore import DataStore
->>> from olpc.datastore import backingstore
+>>> from carquinyol.datastore import DataStore
>>> ds = DataStore()
->>> ds.registerBackend(backingstore.FileBackingStore)
->>> assert ds.mount("/tmp/test_ds")
Create an entry without data: