Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBenjamin Saller <bcsaller@objectrealms.net>2007-07-12 23:59:50 (GMT)
committer Benjamin Saller <bcsaller@objectrealms.net>2007-07-12 23:59:50 (GMT)
commitb58ff0c10ce8246d8d62a09d0aa6622c059e4d28 (patch)
tree0445b3752398e7b3b23b791203a9e22e987dc34c /tests
parent7aae48766ae46bd530a3c556cd4e92a0e02f7ad3 (diff)
property/type sync up
better join code on indexer
Diffstat (limited to 'tests')
-rw-r--r--tests/milestone_1.txt2
-rw-r--r--tests/milestone_2.txt16
-rw-r--r--tests/properties.txt9
-rw-r--r--tests/runalltests.py37
-rw-r--r--tests/test_model.py7
-rw-r--r--tests/testutils.py17
6 files changed, 31 insertions, 57 deletions
diff --git a/tests/milestone_1.txt b/tests/milestone_1.txt
index 2472260..48d09bc 100644
--- a/tests/milestone_1.txt
+++ b/tests/milestone_1.txt
@@ -87,6 +87,4 @@ We can also remove the file from the repository.
This is the basis of milestone 1.
>>> ds.stop()
->>> del ds
-
>>> assert os.system('rm -rf /tmp/test_ds') == 0
diff --git a/tests/milestone_2.txt b/tests/milestone_2.txt
index 516d497..35ad9ec 100644
--- a/tests/milestone_2.txt
+++ b/tests/milestone_2.txt
@@ -7,17 +7,22 @@ First clean up from any other tests.
>>> assert os.system('rm -rf /tmp/test_ds/') == 0
>>> from olpc.datastore import DataStore
->>> from olpc.datastore import backingstore
+>>> from olpc.datastore import backingstore, model
>>> ds = DataStore()
>>> ds.registerBackend(backingstore.FileBackingStore)
->>> assert ds.mount("/tmp/test_ds")
+>>> dm = model.defaultModel.addField('year', 'int').addField('month', 'string')
->>> a = ds.create(dict(title="Content A", author="Bob", year=1999, month="Jan"), '')
->>> b = ds.create(dict(title="Content B", author="Alice", year=2000, month="Jan"), '')
+>>> assert ds.mount("/tmp/test_ds", {'indexmanager.model' : dm})
+
+>>> a = ds.create(dict(title="Content A", author="Bob", year="1999", month="Jan"), '')
+>>> b = ds.create(dict(title="Content B", author="Alice", year="2000", month="Jan"), '')
Find should return both
>>> def find2uids(results): return [i['uid'] for i in results[0]]
->>> assert set(find2uids(ds.find({}))) == set([a,b])
+
+>>> ds.complete_indexing()
+
+>>> assert set(find2uids(ds.find())) == set([a,b])
But what if we want the results ordered?
@@ -35,3 +40,4 @@ and if we want to reverse order it?
>>> ds.stop()
>>> del ds
+>>> assert os.system('rm -rf /tmp/test_ds/') == 0
diff --git a/tests/properties.txt b/tests/properties.txt
index dd93b69..6067aac 100644
--- a/tests/properties.txt
+++ b/tests/properties.txt
@@ -19,7 +19,7 @@ Set up two mount points.
Extend the model to retain a 'year' property used below.
->>> dm = model.defaultModel.addField('year', store=True, exact=True, sortable=True, type="float")
+>>> dm = model.defaultModel.addField('year', "int")
Mount a couple of stores.
@@ -35,15 +35,14 @@ Create some content on each.
>>> u4 = ds.create({'title' : "Gamma doc", 'author' : "HAL", 'year:number' : 2001, 'mountpoint' : mp2}, tmpData("""Document 4"""))
Now we should be able to discover things about the system properties.
+>>> ds.complete_indexing()
Here we test that we can extract the unique values for certain properties.
>>> assert set(ds.get_uniquevaluesfor('author')) == set(['Ben', 'HAL'])
-Here we try to gather the values for the property year. We'd expect
-these values to come back as numbers, however in the current
-implementation they are stored as unicode values.
+Here we try to gather the values for the property year.
->>> assert set(ds.get_uniquevaluesfor('year')) == set([u'2000', u'2001'])
+>>> assert set(ds.get_uniquevaluesfor('year')) == set([2000, 2001])
diff --git a/tests/runalltests.py b/tests/runalltests.py
index 28802ec..02034b9 100644
--- a/tests/runalltests.py
+++ b/tests/runalltests.py
@@ -21,7 +21,7 @@ doctests = [
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__, "properties.txt"),
]
@@ -29,40 +29,25 @@ doctest_options = doctest.ELLIPSIS
doctest_options |= doctest.REPORT_ONLY_FIRST_FAILURE
-# IF YOU ARE NOT GETTING THE RESULTS YOU EXPECT WHILE TESTING
-# THIS IS THE LIKELY CAUSE
-# :: Use distutils to modify the pythonpath for inplace testing
-# using the build directory
-from distutils.util import get_platform
-plat_specifier = ".%s-%s" % (get_platform(), sys.version[0:3])
-build_platlib = os.path.join("build", 'lib' + plat_specifier)
-test_lib = os.path.join(os.path.abspath(".."), build_platlib)
-sys.path.insert(0, test_lib)
-# END PATH ADJUSTMENT CODE
-
-
-
-def tearDownDS(test):
- # and remove the test repository used in some tests
- os.system('rm -rf /tmp/test_ds')
-
def test_suite():
+ global doctests
suite = unittest.TestSuite()
if len(sys.argv) > 1:
doctests = sys.argv[1:]
for dt in doctests:
suite.addTest(doctest.DocFileSuite(dt,
- optionflags=doctest_options, tearDown=tearDownDS))
+ optionflags=doctest_options))
- tests = os.listdir(os.curdir)
- tests = [n[:-3] for n in tests if n.startswith('test') and
- n.endswith('.py')]
+ if len(sys.argv) <= 1:
+ tests = os.listdir(os.curdir)
+ tests = [n[:-3] for n in tests if n.startswith('test') and
+ n.endswith('.py')]
- for test in tests:
- m = __import__(test)
- if hasattr(m, 'test_suite'):
- suite.addTest(m.test_suite())
+ for test in tests:
+ m = __import__(test)
+ if hasattr(m, 'test_suite'):
+ suite.addTest(m.test_suite())
return suite
diff --git a/tests/test_model.py b/tests/test_model.py
index d7aea45..2f44b41 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -30,10 +30,8 @@ class Test(unittest.TestCase):
ds.registerBackend(backingstore.FileBackingStore)
#add a custom field to the model
- dm = model.defaultModel.addField('thumbnail',
- store=True,
- exact=False,
- sortable=False)
+ dm = model.defaultModel.addField('thumbnail', 'binary')
+
ds.mount(DEFAULT_STORE, {'indexmanager.model' : dm})
@@ -41,6 +39,7 @@ class Test(unittest.TestCase):
data = open('test.jpg', 'r').read()
# binary data with \0's in it can cause dbus errors here
fn = tmpData("with image\0\0 prop")
+ # XXX: We should be able to remove:binary now
uid = ds.create({'title' : "Document 1", 'thumbnail:binary' : data}, fn)
waitforindex(ds)
diff --git a/tests/testutils.py b/tests/testutils.py
index 48d1060..a4efc0a 100644
--- a/tests/testutils.py
+++ b/tests/testutils.py
@@ -1,9 +1,5 @@
import tempfile
import os
-import time
-
-from olpc.datastore.xapianindex import IndexManager
-from olpc.datastore.datastore import DataStore
def tmpData(data):
"""Put data into a temporary file returning the filename """
@@ -12,16 +8,7 @@ def tmpData(data):
os.close(fd)
return fn
-def waitforindex(obj, interval=0.1):
+def waitforindex(obj):
# wait for any/all index managers associated with object to finish
# indexing so that tests can do there thing
- if isinstance(obj, IndexManager):
- obj.complete_indexing()
- elif isinstance(obj, DataStore):
- for mp in obj.mountpoints.values():
- im = mp.indexmanager
- im.complete_indexing()
- else:
- # backingstore
- obj.indexmanager.complete_indexing()
-
+ obj.complete_indexing()