From a7cc7f9ce160a7d657f6c237c4e5bacc7f4abbd3 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Mon, 26 May 2008 09:28:31 +0000 Subject: Imported Upstream version 0.8.1 --- diff --git a/.gitignore b/.gitignore deleted file mode 100644 index cbe4746..0000000 --- a/.gitignore +++ /dev/null @@ -1,31 +0,0 @@ -# Generic - -*.pyc -*~ -*.deps -*.libs -*.la -*.lo -*.loT -*.service - -# Absolute -Makefile -Makefile.in -aclocal.m4 -autom4te.cache -compile -config.guess -config.log -config.status -config.sub -configure -depcomp -install-sh -libtool -ltmain.sh -missing -mkinstalldirs -py-compile -stamp-h1 - diff --git a/autogen.sh b/autogen.sh deleted file mode 100755 index 9bd6fd0..0000000 --- a/autogen.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -autoreconf -i -./configure "$@" diff --git a/bin/sample-client.py b/bin/sample-client.py deleted file mode 100755 index 12c5514..0000000 --- a/bin/sample-client.py +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env python -import dbus -import os - -def main(): - bus = dbus.SessionBus() - datastore = bus.get_object("org.laptop.sugar.DataStore", - "/org/laptop/sugar/DataStore") - - uid = datastore.create(dict(title="from dbus", author="Benjamin"), os.path.abspath('tests/test.pdf')) - print "created uid", uid, "with binary content" - - datastore.complete_indexing() - - res, count = datastore.find(dict(fulltext="peek")) - assert count == 1, "failed to index content" - assert res[0]['uid'] == uid, "returned incorrect results" - print "found inside binary file :: PDF" - - assert datastore.find(dict(fulltext="kfdshaksjd"))[1] == 0 - print "successfully ignored bad searches" - - # try the other mimetypes - datastore.update(uid, dict(title="updated title", - mime_type="application/msword"), - os.path.abspath('tests/test.doc')) - - datastore.complete_indexing() - - assert datastore.find(dict(fulltext="inside"))[0][0]['uid'] == uid - print "found in binary file :: WORD" - - datastore.update(uid, dict(title="another updated title", - mime_type="application/vnd.oasis.opendocument.text"), - os.path.abspath('tests/test.odt')) - datastore.complete_indexing() - - assert datastore.find(dict(fulltext="amazed"))[0][0]['uid'] == uid - print "found in binary file :: ODT" - - datastore.get_properties(uid) - - assert datastore.find(dict(title="another"))[0][0]['uid'] == uid - print "found title using dict params", - - assert datastore.find("another")[0][0]['uid'] == uid - print "found title in search of all fields (as text)" - - - assert datastore.find('title:"another"')[0][0]['uid'] == uid - print "field in query field:'value' " - - datastore.delete(uid) - datastore.complete_indexing() - - print "deleted", uid - try: datastore.get_properties(uid) - except: pass - else: - print "Found deleted value... oops" - raise KeyError(uid) - - - uid2 = datastore.create(dict(title="cows", - mime_type="application/vnd.oasis.opendocument.text"), - os.path.abspath('tests/funkyabi.odt')) - - datastore.complete_indexing() - - assert datastore.find(dict(fulltext="vaca"))[0][0]['uid'] == uid2 - print "found in binary file :: ODT" - - datastore.delete(uid2) - datastore.complete_indexing() - - print "ALL GOOD" - -if __name__ == '__main__': - #from ore.main import Application - #a = Application("client", main) - #a.plugins.append('ore.main.profile_support.ProfileSupport') - #a() - main() diff --git a/bin/test-indexprop.py b/bin/test-indexprop.py deleted file mode 100755 index bf75e46..0000000 --- a/bin/test-indexprop.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env python -import dbus -import os - -def main(): - bus = dbus.SessionBus() - ds = bus.get_object("org.laptop.sugar.DataStore", - "/org/laptop/sugar/DataStore") - datastore = dbus.Interface(ds, dbus_interface='org.laptop.sugar.DataStore') - - props = {'title': 'test activity', - 'title_set_by_user': '0', - 'buddies': '', - 'keep': '0', - 'icon-color': '#40011d,#79079a', - 'activity': 'org.laptop.WebActivity', - 'mime_type': ''} - - uid = datastore.create(props, '') - print "created uid", uid - datastore.complete_indexing() - props = {'title': 'test activity title changed', - 'title_set_by_user': '1', - 'buddies': '', - 'keep': '0', - 'icon-color': '#40011d,#79079a', - 'activity': 'org.laptop.WebActivity', - 'mime_type': 'text/plain'} - - datastore.update(uid, props, os.path.abspath('tests/web_data.json')) - print "updated uid", uid - datastore.complete_indexing() - - - result, count = datastore.find(dict(title='test')) - print result - assert result[0]['uid'] == uid - for k, v in result[0].items(): - print "\t", k, v - print open(datastore.get_filename(uid), 'r').read() - print "OK" - - datastore.delete(uid) - -if __name__ == '__main__': - #a = Application("client", main) - #a.plugins.append('ore.main.profile_support.ProfileSupport') - #a() - main() diff --git a/bin/test-inplace.py b/bin/test-inplace.py deleted file mode 100755 index 2d0b1af..0000000 --- a/bin/test-inplace.py +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/python - -import dbus -import dbus.glib -import os -import time - -import tempfile - -def tmpData(data): - """Put data into a temporary file returning the filename """ - fd, fn = tempfile.mkstemp() - os.write(fd, data) - os.close(fd) - return fn - - - -DS_DBUS_SERVICE = "org.laptop.sugar.DataStore" -DS_DBUS_INTERFACE = "org.laptop.sugar.DataStore" -DS_DBUS_PATH = "/org/laptop/sugar/DataStore" - - -# clean up any old tests -assert os.system('rm -rf /tmp/store1') == 0 - -_bus = dbus.SessionBus() -_data_store = dbus.Interface(_bus.get_object(DS_DBUS_SERVICE, DS_DBUS_PATH), DS_DBUS_INTERFACE) - -mount_id = _data_store.mount('inplace:/tmp/store1', dict(title='pen drive')) - -props = {'activity_id': dbus.String(u'461c7467f9ef6478b205a687579843fc36a98e7a'), - 'title_set_by_user': '0', - 'ctime': '2007-07-28T11:57:57.909689', - 'title': 'Google News', - 'mtime': '2007-07-28T11:58:22.460331', - 'keep': '0', - 'icon-color': '#00EA11,#00588C', - 'activity': 'org.laptop.WebActivity', - 'mime_type': 'text/plain'} - -jsonData = '''{"history":[{"url":"http://www.google.com/","title":"Google"}, - {"url":"http://news.google.com/nwshp?tab=wn","title":"Google News"}]}''' - -uid = _data_store.create(props, '') -file_name = os.path.join('/tmp', str(time.time())) -fn = tmpData(jsonData) - -_data_store.update(uid, props, fn) - - - - -props = _data_store.get_properties(uid) -file_name = _data_store.get_filename(uid) -props['mountpoint'] = mount_id -# suggest a filename -props['filename'] = "history.json" -uid2 = _data_store.create(props, file_name) - -# the file name related to the new copy. -fn2 = _data_store.get_filename(uid2) - -assert fn2 - -contents = open(fn2, 'r').read() -assert contents == jsonData - -# Now unmount the store, remount it and read the file - -_data_store.unmount(mount_id) - - -mount_id = _data_store.mount('inplace:/tmp/store1', dict(title='pen drive')) - -fn2 = _data_store.get_filename(uid2) - -assert fn2 - -contents = open(fn2, 'r').read() -assert contents == jsonData - -print "ALL GOOD" - -print "Trying with Abidoc" - -props = {'mountpoint' : mount_id, - 'title' : 'Abidoc', - - } - -uid = _data_store.create(props, '') -# now update it with the document -fn = os.path.abspath("tests/test.odt") -abidoc = open(fn, 'r').read() - - -props['filename'] = 'test.odt' -_data_store.update(uid, props, fn) - -fn2 = _data_store.get_filename(uid) - -contents = open(fn2, 'r').read() -assert contents == abidoc - -print "Abiword ok" diff --git a/docs/Makefile b/docs/Makefile deleted file mode 100644 index d0b6ed4..0000000 --- a/docs/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -###################################################################### -## Different doc packages need different things. Some have to -## import the source, others just need to parse it. The hacks in -## this file attempt to make this happen for some of the common doc -## systems. -###################################################################### -export PYTHON=python -export PRODUCT_DIR=${CURDIR}/../ -export PYTHONPATH=`${PYTHON} ./getbuildpath.py` - -# If you have epydoc installed feel free -#DOC_TARGETS += epydoc_pdf -DOC_TARGETS += pydoc - -all: doc - -epydoc_html: - @epydoc -qq --html -o ${PRODUCT_DIR}/docs ${PYTHONPATH}/${PROJECTNAME} - -epydoc_pdf: - @epydoc -qq --pdf -o ${PRODUCT_DIR}/docs ${PYTHONPATH}/${PROJECTNAME} - -pydoc: - @${PYTHON} ./writedocs.py ${PRODUCT_DIR} - - -doc: ${DOC_TARGETS} - -clean: - @find . -name "*.pyc" -exec rm {} \; - @find . -name "*~" -exec rm {} \; - @find . -name "${PROJECTNAME}*.html" -exec rm {} \; - @rm -rf index.html epydoc.css public private - @rm -rf api.* *.aux *.tex - - - diff --git a/docs/getbuildpath.py b/docs/getbuildpath.py deleted file mode 100644 index d6e594a..0000000 --- a/docs/getbuildpath.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/python2.4 -import os, sys - -# 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 -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 -print test_lib - diff --git a/docs/writedocs.py b/docs/writedocs.py deleted file mode 100644 index 132ef4f..0000000 --- a/docs/writedocs.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/python -import pydoc -import sys, os - - -# 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 -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 - -sys.path.insert(0, sys.argv[1]) - -import olpc.datastore - -pydoc.writedocs(olpc.datastore.__path__[0], "%s." % olpc.datastore.__name__) diff --git a/etc/.gitignore b/etc/.gitignore deleted file mode 100644 index c0ede5e..0000000 --- a/etc/.gitignore +++ /dev/null @@ -1 +0,0 @@ -org.laptop.sugar.DataStore.service diff --git a/maint-helper.py b/maint-helper.py deleted file mode 100755 index 8c64ca2..0000000 --- a/maint-helper.py +++ /dev/null @@ -1,221 +0,0 @@ -#!/usr/bin/env python - -# Copyright (C) 2007, Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -import os -import sys -import re -import datetime -import subprocess - -source_exts = [ '.py', '.c', '.h', '.cpp' ] - -def is_source(path): - for ext in source_exts: - if path.endswith(ext): - return True - -def get_name_and_version(): - f = open('configure.ac', 'r') - config = f.read() - f.close() - - exp = 'AC_INIT\(\[[^\]]+\],\[([^\]]+)\],\[\],\[([^\]]+)\]' - match = re.search(exp, config) - if not match: - print 'Cannot find the package name and version.' - sys.exit(0) - - return [ match.group(2), match.group(1) ] - -def cmd_help(): - print 'Usage: \n\ -maint-helper.py build-snapshot - build a source snapshot \n\ -maint-helper.py fix-copyright [path] - fix the copyright year \n\ -maint-helper.py check-licenses - check licenses in the source' - -def cmd_build_snapshot(): - [ name, version ] = get_name_and_version() - - print 'Update git...' - - retcode = subprocess.call(['git', 'pull']) - if retcode: - print 'ERROR - cannot pull from git' - - cmd = 'git-show-ref --hash=10 refs/heads/master' - alphatag = os.popen(cmd).readline().strip() - - tarball = '%s-%s-git%s.tar.bz2' % (name, version, alphatag) - - print 'Build %s...' % tarball - - os.spawnlp(os.P_WAIT, 'make', 'make', 'distcheck') - - os.rename('%s-%s.tar.bz2' % (name, version), tarball) - - print 'Update NEWS.sugar...' - - if os.environ.has_key('SUGAR_NEWS'): - sugar_news_path = os.environ['SUGAR_NEWS'] - if os.path.isfile(sugar_news_path): - f = open(sugar_news_path, 'r') - sugar_news = f.read() - f.close() - else: - sugar_news = '' - - [ name, version ] = get_name_and_version() - sugar_news += '%s - %s - %s\n\n' % (name, version, alphatag) - - f = open('NEWS', 'r') - for line in f.readlines(): - if len(line.strip()) > 0: - sugar_news += line - else: - break - f.close() - - f = open(sugar_news_path, 'w') - f.write(sugar_news) - f.close() - - print 'Update NEWS...' - - f = open('NEWS', 'r') - news = f.read() - f.close() - - news = 'Snapshot %s\n\n' % alphatag + news - - f = open('NEWS', 'w') - f.write(news) - f.close() - - print 'Committing to git...' - - changelog = 'Snapshot %s.' % alphatag - retcode = subprocess.call(['git', 'commit', '-a', '-m % s' % changelog]) - if retcode: - print 'ERROR - cannot commit to git' - - retcode = subprocess.call(['git', 'push']) - if retcode: - print 'ERROR - cannot push to git' - - print 'Done.' - -def check_licenses(path, license, missing): - matchers = { 'LGPL' : 'GNU Lesser General Public', - 'GPL' : 'GNU General Public License' } - - license_file = os.path.join(path, '.license') - if os.path.isfile(license_file): - f = open(license_file, 'r') - license = f.readline().strip() - f.close() - - for item in os.listdir(path): - full_path = os.path.join(path, item) - - if os.path.isdir(full_path): - check_licenses(full_path, license, missing) - else: - check_source = is_source(item) - - # Special cases. - if item.find('marshal') > 0 or \ - item.startswith('egg') > 0: - check_source = False - - if check_source: - f = open(full_path, 'r') - source = f.read() - f.close() - - miss_license = True - if source.find(matchers[license]) > 0: - miss_license = False - - # Special cases. - if source.find('THIS FILE IS GENERATED') > 0: - miss_license = False - - if miss_license: - if not missing.has_key(license): - missing[license] = [] - missing[license].append(full_path) - -def cmd_check_licenses(): - missing = {} - check_licenses(os.getcwd(), 'GPL', missing) - - for item in missing.keys(): - print '%s:\n' % item - for path in missing[item]: - print path - print '\n' - -COPYRIGHT = 'Copyright (C) ' - -def fix_copyright(path): - for item in os.listdir(path): - full_path = os.path.join(path, item) - - if os.path.isdir(full_path): - fix_copyright(full_path) - elif is_source(item): - f = open(full_path, 'r') - source = f.read() - f.close() - - year_start = -1 - year_end = -1 - - i1 = source.find(COPYRIGHT) - if i1 != -1: - i1 += len(COPYRIGHT) - i2 = i1 + source[i1:].find(' ') - if i1 > 0: - try: - year_start = int(source[i1:i1 + 4]) - year_end = int(source[i1 + 6: i1 + 10]) - except ValueError: - pass - - if year_start > 0 and year_end < 0: - year_end = year_start - - year = datetime.date.today().year - if year_end < year: - result = '%s%d-%d%s' % (source[:i1], year_start, - year, source[i2:]) - f = open(full_path, 'w') - f.write(result) - f.close() - -def cmd_fix_copyright(path): - fix_copyright(path) - -if len(sys.argv) < 2: - cmd_help() -elif sys.argv[1] == 'build-snapshot': - cmd_build_snapshot() -elif sys.argv[1] == 'check-licenses': - cmd_check_licenses() -elif sys.argv[1] == 'fix-copyright' and len(sys.argv) > 2: - cmd_fix_copyright(sys.argv[2]) diff --git a/tests/Makefile b/tests/Makefile deleted file mode 100644 index c2581cb..0000000 --- a/tests/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -# howto inherit this properly from above? -# its not an option to configure -PYTHON=python - -all: clean test - -test: - @${PYTHON} runalltests.py - -valgrind: - @echo "Profiling the process. Run kcachegrind on the output" - valgrind --tool=callgrind --suppressions=valgrind-python.supp ${PYTHON} runalltests.py - -profile: - @find . -name "hotspot*" -exec rm {} \; - @${PYTHON} ./profilealltests.py - -clean: - @${PYTHON} ./cleaner.py - @find . -name "*.pyc" -exec rm {} \; - @find . -name "*~" -exec rm {} \; - @find . -name "hotspot*" -exec rm {} \; - @find . -name "callgrind.out*" -exec rm {} \; - -tags: - - diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index 6f73726..0000000 --- a/tests/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# testing package - - diff --git a/tests/cleaner.py b/tests/cleaner.py deleted file mode 100755 index cfa15bf..0000000 --- a/tests/cleaner.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/python -import os -import re -from ore.main import Application - -filepattern = re.compile("(\w{8})\-(\w{4})\-(\w{4})\-(\w{4})\-(\w{12})") -tmppattern = re.compile("tmp\S{6}") -onepattern = re.compile("one.*\.txt") - -staticdirs = re.compile('test_ds|store\d') - -filepatterns = [filepattern, tmppattern, onepattern] -dirpatterns = [staticdirs] - -class Cleaner(Application): - def manage_options(self): - self.parser.add_option("--base", dest="base_dir", - action="store", default='/tmp', - help="""Where to clean (/tmp)""") - - def main(self): - """clean up files left from testing in /tmp""" - # this is done using patterned names - for root, dirs, files in os.walk(self.options.base_dir): - for filename in files: - for pat in filepatterns: - if pat.match(filename): - fn = os.path.join(root, filename) - os.remove(fn) - break - for dirname in dirs: - for pat in dirpatterns: - if pat.match(dirname): - dn = os.path.join(root, dirname) - os.system('rm -rf %s' % dn) - -if __name__ == "__main__": - Cleaner("cleaner")() - - diff --git a/tests/dateranges.txt b/tests/dateranges.txt deleted file mode 100644 index 886e7d2..0000000 --- a/tests/dateranges.txt +++ /dev/null @@ -1,42 +0,0 @@ -Test that date -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 ->>> ds = DataStore() ->>> ds.registerBackend(backingstore.FileBackingStore) - ->>> assert ds.mount("/tmp/test_ds") - ->>> t1 = datetime.datetime(1995, 1, 1) ->>> t2 = datetime.datetime(2000, 1, 1) ->>> t3 = datetime.datetime(2005, 1, 1) - ->>> a = ds.create(dict(title="Content A", author="Bob", ctime=t1.isoformat()), '') ->>> b = ds.create(dict(title="Content B", author="Alice", ctime=t2.isoformat()), '') ->>> c = ds.create(dict(title="Content V", author="Clare", ctime=t3.isoformat()), '') - ->>> ds.complete_indexing() - - -Scan for ranges - ->>> result, count = ds.find({'ctime' : {'start' : t1.isoformat(), 'end' : t3.isoformat() }}) ->>> assert count == 3 - - ->>> result, count = ds.find({'ctime' : {'start' : t1.isoformat(), 'end' : t2.isoformat() }}) ->>> assert count == 2 - ->>> result, count = ds.find({'ctime' : {'start' : t2.isoformat(), 'end' : t3.isoformat() }}) ->>> assert count == 2 - ->>> result, count = ds.find({'ctime' : {'start' : t1.isoformat(), 'end' : t1.isoformat() }}) ->>> assert count == 1 - - ->>> ds.stop() ->>> del ds ->>> assert os.system('rm -rf /tmp/test_ds/') == 0 diff --git a/tests/funkyabi.odt b/tests/funkyabi.odt deleted file mode 100644 index 1850b47..0000000 --- a/tests/funkyabi.odt +++ /dev/null Binary files differ diff --git a/tests/milestone_1.txt b/tests/milestone_1.txt deleted file mode 100644 index 35e8fb6..0000000 --- a/tests/milestone_1.txt +++ /dev/null @@ -1,89 +0,0 @@ -The initial requirements are as follows: - -* Get the unique ids of all the objects in the store. -* Get an object from the store given his uid. -* Get the object metadata. -* Get the object file. -* Push the changes made to the file back to the store. -* Update the metadata of an object. - -Below I enumerate each point showing how this is performed on a local -datastore. - - -First, create and connect the store. ->>> import os ->>> assert os.system('rm -rf /tmp/test_ds') == 0 - - ->>> from olpc.datastore import DataStore ->>> from olpc.datastore import backingstore ->>> ds = DataStore() ->>> ds.registerBackend(backingstore.FileBackingStore) ->>> assert ds.mount("/tmp/test_ds") - -Because there is newly created we are going to quickly populate the -datastore with some content. - ->>> from testutils import tmpData - ->>> assert ds.create(dict(title="Document 1"), tmpData("""this is the first document""")) ->>> assert ds.create(dict(title="Document 2"), tmpData("""this is the second document""")) - -We can also create an object w/o any associated file data ->>> assert ds.create(dict(title="Web Session", url="http://google.com")) - -Note that we retain no reference to the created documents. - -Now we should be able to test the first requirement. -* Get the unique ids of all the objects in the store. - ->>> ds.complete_indexing() - ->>> results, count = ds.find() - -A find command with out any parameters will return everything in the store. - -* Get an object from the store given its uid. - -Here we manually cycle through the results looking for the title we -want. ->>> for item in results: -... if item['title'] == 'Document 1': -... first_uid = item['uid'] -... break ->>> c1 = ds.get(first_uid) - -* Get the object metadata. ->>> c1.properties -{...} - -* Get the object file. ->>> c1.filename -'/tmp/...' - ->>> c1.contents -'this is the first document' ->>> c1.file - - - - -Now we can modify that file and then -* Push the changes made to the file back to the store. -* Update the metadata of an object. - ->>> fn = c1.filename ->>> fp = open(fn, 'a') ->>> print >>fp, "more content" ->>> fp.close() ->>> ds.update(first_uid, dict(title="Newish Content"), fn) - - -We can also remove the file from the repository. ->>> ds.delete(first_uid) - -This is the basis of milestone 1. - ->>> ds.stop() ->>> assert os.system('rm -rf /tmp/test_ds') == 0 diff --git a/tests/milestone_2.txt b/tests/milestone_2.txt deleted file mode 100644 index 551e1e3..0000000 --- a/tests/milestone_2.txt +++ /dev/null @@ -1,42 +0,0 @@ -Once the datastore is running its important to be able to sort the -results along the lines of various criteria. Lets create a sample -datastore. - -First clean up from any other tests. ->>> import os ->>> assert os.system('rm -rf /tmp/test_ds/') == 0 - ->>> from olpc.datastore import DataStore ->>> from olpc.datastore import backingstore, model ->>> ds = DataStore() ->>> ds.registerBackend(backingstore.FileBackingStore) - ->>> assert ds.mount("/tmp/test_ds") - ->>> a = ds.create({'title':"Content A", 'author':"Bob", 'year:int':"1999", 'month':"Jan"}, '') ->>> b = ds.create({'title':"Content B", 'author':"Alice", 'year:int':"2000", 'month':"Jan"}, '') - -Find should return both ->>> def find2uids(results): return [i['uid'] for i in results[0]] - ->>> ds.complete_indexing() - ->>> assert set(find2uids(ds.find())) == set([a,b]) - - -But what if we want the results ordered? ->>> assert find2uids(ds.find(order_by=['title'])) == [a, b] ->>> assert find2uids(ds.find(order_by=['author'])) == [b, a] - -By more than one key? - ->>> assert find2uids(ds.find(order_by=['month', 'year'])) == [a, b] - -and if we want to reverse order it? - ->>> assert find2uids(ds.find(order_by=['-title'])) == [b, a] ->>> assert find2uids(ds.find(order_by=['-author'])) == [a, b] - ->>> ds.stop() ->>> del ds ->>> assert os.system('rm -rf /tmp/test_ds/') == 0 diff --git a/tests/mountpoints.txt b/tests/mountpoints.txt deleted file mode 100644 index 695e7d2..0000000 --- a/tests/mountpoints.txt +++ /dev/null @@ -1,217 +0,0 @@ -Mountpoints are very much like traditional *NIX filesystem mounts. The -intention is to allow more than one backingstore (stable storage -device) to become part of a datastore at runtime. This is done by -mounting a backingstore on the datastore. - -(clean up) ->>> import os ->>> assert os.system('rm -rf /tmp/store1/') == 0 ->>> assert os.system('rm -rf /tmp/store2/') == 0 ->>> assert os.system('rm -rf /tmp/store3/') == 0 - - ->>> from olpc.datastore import DataStore ->>> from olpc.datastore import backingstore ->>> from testutils import tmpData ->>> import dbus - - -Here we create a datastore, and mount a backingstore on tmp. By -default this will create a new directory in /tmp which will then be -used for storage. - ->>> ds = DataStore() ->>> ds.registerBackend(backingstore.FileBackingStore) ->>> mp1 = ds.mount("/tmp/store1", dict(title="Primary Storage")) - -This will list all the mount points. It returns a list of dicts with -the minumum keyset of 'id', 'uri', and 'title'. Title is the Human -readable name of the mount. 'Id' is the most important property this -can be used to control the storage target or to filter results. - ->>> mps = ds.mounts() ->>> mountpoint = mps[0]['id'] - - -Now lets create some content - ->>> u1 = ds.create(dict(title="Document 1", filename="one.txt"), tmpData("""document one""")) ->>> u2 = ds.create(dict(title="Document 2", mime_type="text/plain"), tmpData("""document two""")) - -We can now, if we wish verify which mount point this content came -from. - ->>> ds.complete_indexing() - ->>> c1 = ds.get(u1) ->>> assert c1.backingstore.id == mountpoint - -However this interface isn't available over DBus and objects are -normally located and inspected using the find() method. - ->>> c1a = ds.find(dict(title="Document 1"))[0][0] ->>> assert c1a['mountpoint'] == mountpoint - -We can see that the mountpoint property was mapped on the object and -refers to the proper storage. - -Now lets add another mount point. - ->>> mp2 = ds.mount("/tmp/store2", dict(title="Secondary Storage")) - -Now lets create a new content item. ->>> u3 = ds.create(dict(title="Document 3", mountpoint=mp2), tmpData("""document three""")) - ->>> ds.complete_indexing() - -We explictly passed a mount point here. Lets examine the properties of -the object and verify this. ->>> c3 = ds.find(dict(title="Document 3"))[0][0] ->>> assert c3['mountpoint'] == mp2 - -Now lets filter a find call to only selected mountpoints. - ->>> results, count = ds.find(dict(mountpoints=[mp1])) ->>> assert count == 2 - ->>> results, count = ds.find(dict(mountpoints=[mp2])) ->>> assert count == 1 - ->>> results, count = ds.find({}) ->>> assert count == 3 - -We can see that filtering by mount point works as expected. - -Now we are going to create an inplace mount. This is designed around -USB keys and the like. In this case we want to leave files in place, -there will be no working copies. - -First lets create some inplace data that we expect to get imported and -indexed. - ->>> os.makedirs("/tmp/store3/nested") ->>> fp = open("/tmp/store3/doc4.txt", "w") ->>> fp.write("This is document four") ->>> fp.close() - ->>> fp = open("/tmp/store3/nested/doc5.txt", "w") ->>> fp.write("This is document five") ->>> fp.close() - -Register the filesystem type ->>> ds.registerBackend(backingstore.InplaceFileBackingStore) - ->>> mp3 = ds.mount("inplace:/tmp/store3", dict(title="Fake USB")) - -If that worked it should have imported content on load(). - ->>> ds.complete_indexing() - ->>> result, count = ds.find(dict(fulltext="four")) ->>> assert count == 1 ->>> assert result[0]['mountpoint'] == mp3 - - -Let's unmount 'Fake USB' and then remount it with some options passed -as DBus data. - ->>> ds.unmount(mp3) - ->>> mp3 = ds.mount("inplace:/tmp/store3", dict(title=dbus.String("Fake USB again"), -... sync_mount=True)) - ->>> ds.complete_indexing() - - ->>> result, count = ds.find(dict(fulltext="four")) ->>> assert count == 1 ->>> assert result[0]['mountpoint'] == mp3 - ->>> mp = ds.mountpoints[mp3] - -Check for the new value in the descriptor - ->>> assert mp.descriptor()['title'] == 'Fake USB again' - -Verify that we can get the properties of objects on the inplace -stores. - ->>> uid = result[0]['uid'] ->>> props = ds.get_properties(uid) ->>> assert props['title'] == "doc4" - - -Currently sugar defines doing a copy as zeroing out the uid and -changing the mountpoint. Lets copy an object from mp3 to mp1, the -primary store. ->>> props['mountpoint'] = mountpoint ->>> fn = ds.get_filename(uid) - ->>> copyuid = ds.create(props, fn) - ->>> ds.complete_indexing() - - ->>> result, count = ds.find(dict(fulltext="four")) ->>> assert count == 2 - -We also need to test that we can copy from a normal store to an -inplace one. Lets move the object with u1 to mp3 - ->>> props = ds.get_properties(u1) ->>> props['mountpoint'] = mp3 ->>> pen_copy = ds.create(props, ds.get_filename(u1)) - ->>> ds.complete_indexing() - ->>> result, count = ds.find(dict(mountpoints=[mp3], filename="one.txt")) ->>> assert count == 1 ->>> assert result[0]['uid'] == pen_copy - -The file was properly created in the expected place. - ->>> assert os.path.exists('/tmp/store3/one.txt') - -Now let's update that file. - ->>> fn = ds.get_filename(u1) ->>> fp = open(fn, 'w') ->>> print >>fp, "This is new content" ->>> fp.close() - ->>> ds.update(pen_copy, props, fn) ->>> ds.complete_indexing() - -and verify it worked. - ->>> result, count = ds.find(dict(query="new content")) ->>> assert count == 1 ->>> assert result[0]['uid'] == pen_copy - - - -We also need to be sure that delete commands work on inplace -mounts. We will delete the object from the datastore and then verify -that the file is missing. - ->>> ds.delete(pen_copy) ->>> ds.complete_indexing() - ->>> os.path.exists('/tmp/store3/one.txt') -False - - -Now a tricky case where we corrupt the metadata on a mount and want to -verify that we can still remount the store. - ->>> ds.unmount(mp3) ->>> fp = open('/tmp/store3/.olpc.store/metainfo', 'w') ->>> fp.seek(0) ->>> fp.write('broken') ->>> fp.close() - ->>> mp3 = ds.mount("inplace:/tmp/store3", dict(title="Fake USB from broken")) ->>> mp = ds.mountpoints[mp3] ->>> assert mp.descriptor()['title'] == 'Fake USB from broken' - ->>> ds.stop(); del ds diff --git a/tests/plugger.pdf b/tests/plugger.pdf deleted file mode 100644 index 737dab2..0000000 --- a/tests/plugger.pdf +++ /dev/null Binary files differ diff --git a/tests/properties.txt b/tests/properties.txt deleted file mode 100644 index 6c3c91b..0000000 --- a/tests/properties.txt +++ /dev/null @@ -1,47 +0,0 @@ -This document shows off the range of features available for attaching -properties to content and managing them. - -(clean up) ->>> import os ->>> assert os.system('rm -rf /tmp/store1/') == 0 ->>> assert os.system('rm -rf /tmp/store2/') == 0 - - ->>> from olpc.datastore import DataStore ->>> from olpc.datastore import backingstore, model ->>> from testutils import tmpData ->>> import dbus - -Set up two mount points. - ->>> ds = DataStore() ->>> ds.registerBackend(backingstore.FileBackingStore) - -Extend the model to retain a 'year' property used below. - -Mount a couple of stores. - ->>> mp1 = ds.mount("/tmp/store1", {'title' : "Primary Storage",}) ->>> mp2 = ds.mount("/tmp/store2", {'title' : "Secondary Storage"}) - -Create some content on each. - ->>> u1 = ds.create({'title' : "Alpha doc", 'author' : "Ben", 'year:int' : 2000}, tmpData("""Document 1""")) ->>> u2 = ds.create({'title' : "Beta doc", 'author' : "Ben", 'year:int' : 2001} , tmpData("""Document 2""")) - ->>> u3 = ds.create({'title' : "Delta doc", 'author' :"HAL", 'year:int' : 2000, 'mountpoint' : mp2}, tmpData("""Document 3""")) ->>> u4 = ds.create({'title' : "Gamma doc", 'author' : "HAL", 'year:int' : 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. - ->>> assert set(ds.get_uniquevaluesfor('year')) == set([2000, 2001]) - - - ->>> ds.stop(); del ds diff --git a/tests/runalltests.py b/tests/runalltests.py deleted file mode 100644 index 8fee87e..0000000 --- a/tests/runalltests.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/python -# -# Runs all tests in the current directory -# -# 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 logging - -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"), - -] - -doctest_options = doctest.ELLIPSIS -#doctest_options |= doctest.REPORT_ONLY_FIRST_FAILURE - - -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)) - - 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()) - return suite - - -if __name__ == "__main__": - runner = unittest.TextTestRunner(verbosity=1) - suite = test_suite() - runner.run(suite) - diff --git a/tests/sugar_demo_may17.txt b/tests/sugar_demo_may17.txt deleted file mode 100644 index 64d49e5..0000000 --- a/tests/sugar_demo_may17.txt +++ /dev/null @@ -1,72 +0,0 @@ -How Sugar will interact with the DS for the May 17th demo in Argentina: - ->>> from olpc.datastore import DataStore ->>> from olpc.datastore import backingstore ->>> ds = DataStore() ->>> ds.registerBackend(backingstore.FileBackingStore) ->>> assert ds.mount("/tmp/test_ds") - - -Create an entry without data: ->>> uid = ds.create(dict(title="New entry"), '') ->>> ds.complete_indexing() - ->>> ds.get_filename(uid) -'' - -Update an entry without data: ->>> ds.update(uid, dict(title="New entry still without content"), '') - ->>> ds.complete_indexing() - ->>> ds.get_filename(uid) -'' - -Add some data to the same entry: ->>> fp = open('/tmp/sugar_ds_test', 'w') ->>> print >>fp, "some content" ->>> fp.close() ->>> ds.update(uid, dict(title="Same entry now with some content"), fp.name) ->>> ds.complete_indexing() - -Retrieve that data: ->>> fn = ds.get_filename(uid) ->>> fp = open(fn, 'r') ->>> fp.read() -'some content\n' ->>> fp.close() - -Update again: ->>> fp = open('/tmp/sugar_ds_test2', 'w') ->>> print >>fp, "some other content" ->>> fp.close() ->>> ds.update(uid, dict(title="Same entry with some other content"), fp.name) ->>> ds.complete_indexing() - -And retrieve again: ->>> fn = ds.get_filename(uid) ->>> fp = open(fn, 'r') ->>> fp.read() -'some other content\n' ->>> fp.close() - -Get all entries (only have one): ->>> results, count = ds.find({}) ->>> results[0]['title'] -'Same entry with some other content' - -Check content: ->>> fn = ds.get_filename(uid) ->>> fp = open(fn, 'r') ->>> fp.read() -'some other content\n' ->>> fp.close() - -Set content as pdf: ->>> ds.update(uid, dict(title="Same entry with some content in pdf"), 'test.pdf') ->>> ds.update(uid, dict(title="Same entry with some content in doc"), 'test.doc') ->>> ds.update(uid, dict(title="Same entry with some content in odt"), 'test.odt') ->>> ds.complete_indexing() - ->>> ds.stop() ->>> del ds diff --git a/tests/test.doc b/tests/test.doc deleted file mode 100644 index 354e2ab..0000000 --- a/tests/test.doc +++ /dev/null Binary files differ diff --git a/tests/test.jpg b/tests/test.jpg deleted file mode 100644 index d7f330b..0000000 --- a/tests/test.jpg +++ /dev/null Binary files differ diff --git a/tests/test.odt b/tests/test.odt deleted file mode 100644 index a8594a4..0000000 --- a/tests/test.odt +++ /dev/null Binary files differ diff --git a/tests/test.pdf b/tests/test.pdf deleted file mode 100644 index 3478a64..0000000 --- a/tests/test.pdf +++ /dev/null Binary files differ diff --git a/tests/test_backingstore.py b/tests/test_backingstore.py deleted file mode 100644 index 4138219..0000000 --- a/tests/test_backingstore.py +++ /dev/null @@ -1,61 +0,0 @@ -import unittest -from testutils import tmpData - -from olpc.datastore import backingstore -import os - -DEFAULT_STORE = '/tmp/_bs_test' - -class Test(unittest.TestCase): - def setUp(self): - if os.path.exists(DEFAULT_STORE): - os.system("rm -rf %s" % DEFAULT_STORE) - - def tearDown(self): - if os.path.exists(DEFAULT_STORE): - os.system("rm -rf %s" % DEFAULT_STORE) - - def test_fsstore(self): - bs = backingstore.FileBackingStore(DEFAULT_STORE) - bs.initialize_and_load() - bs.create_descriptor() - desc = bs.descriptor() - assert 'id' in desc - assert 'uri' in desc - assert 'title' in desc - assert desc['title'] is not None - - d = """This is a test""" - d2 = "Different" - - uid = bs.create(dict(title="A"), tmpData(d)) - - bs.complete_indexing() - - obj = bs.get(uid) - - assert obj.get_property('title') == "A" - got = obj.file.read() - assert got == d - - bs.update(uid, dict(title="B"), tmpData(d2)) - - bs.complete_indexing() - - obj = bs.get(uid) - assert obj.get_property('title') == "B" - got = obj.file.read() - assert got == d2 - - bs.delete(uid) - bs.complete_indexing() - self.failUnlessRaises(KeyError, bs.get, uid) - -def test_suite(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(Test)) - return suite - -if __name__ == "__main__": - unittest.main() - diff --git a/tests/test_conversion.py b/tests/test_conversion.py deleted file mode 100644 index aa6f1a9..0000000 --- a/tests/test_conversion.py +++ /dev/null @@ -1,30 +0,0 @@ -import unittest - -from olpc.datastore.converter import converter -from StringIO import StringIO - -class Test(unittest.TestCase): - - def test_unicode(self): - # read each of the test files in doing conversion, - # there should be no unicode errors - fn_expectations = { - 'test.pdf' : 'Don\'t', - 'test.doc' : 'amazed.', - 'test.odt' : 'amazed.', - 'plugger.pdf' : 'Plugger', - 'funkyabi.odt' : 'vaca' - } - for fn, expect in fn_expectations.iteritems(): - assert expect in converter(fn).read() - - - -def test_suite(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(Test)) - return suite - -if __name__ == "__main__": - unittest.main() - diff --git a/tests/test_model.py b/tests/test_model.py deleted file mode 100644 index 6d171c1..0000000 --- a/tests/test_model.py +++ /dev/null @@ -1,147 +0,0 @@ -import unittest -from testutils import tmpData - -from olpc.datastore import DataStore -from olpc.datastore import model, backingstore -import datetime -import os - - -DEFAULT_STORE = '/tmp/test_ds' - -class Test(unittest.TestCase): - def setUp(self): os.system('rm -rf %s' % DEFAULT_STORE) - def tearDown(self): os.system('rm -rf %s' % DEFAULT_STORE) - - def test_dateproperty(self): - n = datetime.datetime.now() - # we have to kill the microseconds as - # time.strptime which we must use in 2.4 doesn't parse it - n = n.replace(microsecond=0) - p = model.Property('ctime', n.isoformat(), 'date') - assert p.key == "ctime" - assert p.value == n.isoformat() - p.value = p.value - assert p.value == n.isoformat() - - def test_binaryproperty(self): - ds = DataStore() - ds.registerBackend(backingstore.FileBackingStore) - - - ds.mount(DEFAULT_STORE) - n = datetime.datetime.now() - - 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") - # The key types are looked up in the model now - uid = ds.create({'title' : "Document 1", 'thumbnail:binary' : data, 'ctime' : n.isoformat()}, fn) - - ds.complete_indexing() - - c = ds.get(uid) - assert c.get_property('thumbnail') == data - # I don't care about the microsecond issue now, the typelib - # patch later can fix that - assert c.get_property('ctime')[:19] == n.isoformat()[:19] - - ds.stop() - - - def test_intproperty(self): - p = model.Property('keep', 1, 'int') - assert p.value == '1' - - p.value = 0 - assert p.value == '0' - - p.value = '1' - assert p.value == '1' - - p.value = '0' - assert p.value == '0' - - - ds = DataStore() - ds.registerBackend(backingstore.FileBackingStore) - - ds.mount(DEFAULT_STORE) - - uid = ds.create({'title' : "Document 1", 'keep' : 1},) - ds.complete_indexing() - c = ds.get(uid) - assert c.get_property('keep') == 1 - - ds.update(uid, {'title' : "Document 1", 'keep' : 0}) - ds.complete_indexing() - c = ds.get(uid) - assert c.get_property('keep') == 0 - - - ds.update(uid, {'title' : "Document 1", 'keep' : '1'}) - ds.complete_indexing() - c = ds.get(uid) - assert c.get_property('keep') == 1 - - ds.update(uid, {'title' : "Document 1", 'keep' : '0'}) - ds.complete_indexing() - c = ds.get(uid) - assert c.get_property('keep') == 0 - - ds.stop() - - def test_randomproperty(self): - # specifying items not in the model, with and w/o type - # qualifiers - ds = DataStore() - ds.registerBackend(backingstore.FileBackingStore) - - ds.mount(DEFAULT_STORE) - - uid = ds.create({'title' : 'Random Extras', 'foobar' : 'baz', - 'incept:date' : datetime.datetime.now().isoformat()}) - - ds.complete_indexing() - - ds.update(uid, {'title' : 'Random Extras the sequel', - 'foobar' : 'whodofoodo', - 'incept:date' : datetime.datetime.now().isoformat()}) - - ds.complete_indexing() - - # ignored w/o prefix - assert ds.find('whodofoodo')[1] == 0 - # found with it - assert ds.find('foobar:whodofoodo')[1] == 1 - c = ds.get_properties(uid) - assert 'foobar' in c - assert 'title' in c - # maps back w/o the type - assert 'incept' in c - - ds.update(uid, {'title' : 'Random Extras the sequel', - 'foobar' : '', - 'incept:date' : datetime.datetime.now().isoformat()}) - - ds.complete_indexing() - assert ds.find('whodofoodo')[1] == 0 - # found with it - assert ds.find('foobar:whodofoodo')[1] == 0 - c = ds.get_properties(uid) - assert 'title' in c - # maps back w/o the type - assert 'incept' in c - assert c['foobar'] == '' - - - ds.stop() - -def test_suite(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(Test)) - return suite - -if __name__ == "__main__": - unittest.main() - diff --git a/tests/test_xapianindex.py b/tests/test_xapianindex.py deleted file mode 100644 index c455c44..0000000 --- a/tests/test_xapianindex.py +++ /dev/null @@ -1,89 +0,0 @@ -from olpc.datastore.xapianindex import IndexManager -import os -from datetime import datetime - -import time -import unittest -import gnomevfs - -DEFAULT_STORE = '/tmp/_xi_test' - - -def index_file(iconn, filepath): - """Index a file.""" - - mimetype = gnomevfs.get_mime_type(filepath) - main, subtype = mimetype.split('/',1) - - stat = os.stat(filepath) - ctime = datetime.fromtimestamp(stat.st_ctime).isoformat() - mtime = datetime.fromtimestamp(stat.st_mtime).isoformat() - - if main in ['image']: filepath = None - if subtype in ['x-trash', 'x-python-bytecode']: filepath = None - - - - props = {'mime_type' : mimetype, 'mtime' : mtime, 'ctime' : ctime,} - - if filepath: - fn = os.path.split(filepath)[1] - props['filename'] = fn - - iconn.index(props, filepath) - - return 1 - -def index_path(iconn, docpath): - """Index a path.""" - count = 0 - for dirpath, dirnames, filenames in os.walk(docpath): - for filename in filenames: - filepath = os.path.join(dirpath, filename) - index_file(iconn, filepath) - count += 1 - return count - -class Test(unittest.TestCase): - def setUp(self): - if os.path.exists(DEFAULT_STORE): - os.system("rm -rf %s" % DEFAULT_STORE) - - def tearDown(self): - if os.path.exists(DEFAULT_STORE): - os.system("rm -rf %s" % DEFAULT_STORE) - - def test_index(self): - # import a bunch of documents into the store - im = IndexManager() - im.connect(DEFAULT_STORE) - - # test basic index performance - start = time.time() - count = index_path(im, os.getcwd()) - end = time.time() - delta = end - start - - #print "%s in %s %s/sec" % (count, delta, count/delta) - - # wait for indexing to finish - im.complete_indexing() - - # test basic search performance - results = list(im.search('peek')[0]) - - # this indicates that we found text inside binary content that - # we expected - assert 'test.pdf' in set(r.get_property('filename') for r in results) - - assert im.search('mime_type:application/pdf filename:test.pdf peek')[1] == 1 - - -def test_suite(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(Test)) - return suite - -if __name__ == "__main__": - unittest.main() - diff --git a/tests/testutils.py b/tests/testutils.py deleted file mode 100644 index fc667db..0000000 --- a/tests/testutils.py +++ /dev/null @@ -1,10 +0,0 @@ -import tempfile -import os - -def tmpData(data): - """Put data into a temporary file returning the filename """ - fd, fn = tempfile.mkstemp() - os.write(fd, data) - os.close(fd) - return fn - diff --git a/tests/web_data.json b/tests/web_data.json deleted file mode 100644 index bfd983b..0000000 --- a/tests/web_data.json +++ /dev/null @@ -1 +0,0 @@ -{"history":[{"url":"http://www.google.com/","title":"Google"}]} \ No newline at end of file diff --git a/tests/xapianindex.txt b/tests/xapianindex.txt deleted file mode 100644 index 22aa05d..0000000 --- a/tests/xapianindex.txt +++ /dev/null @@ -1,90 +0,0 @@ -The xapian index module can be used directly as follows - -First clean up any old test data. - ->>> index_home = "/tmp/xi" ->>> import os, sys, time, logging ->>> assert os.system('rm -rf %s' % index_home) == 0 - -# >>> logging.basicConfig(level=logging.DEBUG, -# ... format="%(asctime)-15s %(name)s %(levelname)s: %(message)s", -# ... stream=sys.stderr) - - ->>> from olpc.datastore.xapianindex import IndexManager ->>> from olpc.datastore import model ->>> im = IndexManager() ->>> im.connect(index_home) - - -Now add the file to the index. - ->>> props = dict(title="PDF Document", -... mime_type="application/pdf") - - ->>> uid = im.index(props, "test.pdf") - -Let the async indexer do its thing. We ask the indexer if it has work -left, when it has none we expect our content to be indexed and searchable. - ->>> im.complete_indexing() - - -Searching on an property of the content works. ->>> def expect(r, count=None): -... if count: assert r[1] == count -... return list(r[0]) ->>> def expect_single(r): -... assert r[1] == 1 -... return r[0].next() ->>> def expect_none(r): -... assert r[1] == 0 -... assert list(r[0]) == [] - - ->>> assert expect_single(im.search("PDF")).id == uid - -Searching into the binary content of the object works as well. ->>> assert expect_single(im.search("peek")).id == uid - -Specifying a search that demands a document term be found only in the -title works as well. - ->>> assert expect_single(im.search('title:PDF')).id == uid ->>> expect_none(im.search('title:peek')) - -Searching for documents that are PDF works as expected here. Here we -use the dictionary form of the query where each field name is given -and creates a search. ->>> assert expect_single(im.search(dict(mime_type='application/pdf'))).id == uid - -Punctuation is fine. - ->>> assert expect_single(im.search("Don't peek")).id == uid - -As well as quoted strings - ->>> assert expect_single(im.search(r'''"Don't peek"''')).id == uid - - -We can also issue OR styled queries over a given field by submitting -a list of queries to a given field. - ->>> assert expect_single(im.search(dict(mime_type=["text/plain", -... 'application/pdf']))).id == uid - - -But an OR query for missing values still return nothing. - ->>> expect_none(im.search(dict(mime_type=["video/mpg", -... 'audio/ogg']))) - - - - - -Cleanly shut down. ->>> im.stop() - ->>> assert os.system('rm -rf %s' % index_home) == 0 -- cgit v0.9.1