Modified:
branches/unhork/attic/metakit/MetakitCollection.py
branches/unhork/grassyknoll/client/ClientCollection.py
branches/unhork/grassyknoll/collection/Collection.py
branches/unhork/grassyknoll/collection/ThreadCollection.py
branches/unhork/grassyknoll/collection/backends/dictionary/DictCollection.py
branches/unhork/grassyknoll/collection/backends/gdbm/GdbmCollection.py
branches/unhork/grassyknoll/collection/backends/lucene/LuceneCollection.py
branches/unhork/grassyknoll/collection/backends/memcached/MemcachedCollection.py
branches/unhork/grassyknoll/collection/backends/sql/SqlCollection.py
branches/unhork/grassyknoll/collection/backends/sql/SqliteCollection.py
branches/unhork/grassyknoll/tests/fixtures/load_nsf.py
branches/unhork/grassyknoll/tests/test_Collection_Objects.py
branches/unhork/grassyknoll/tests/test_backends/FixtureCollectionTests.py
branches/unhork/grassyknoll/tests/test_backends/GenericCollectionTests.py
branches/unhork/grassyknoll/tests/test_backends/SimpleCollectionTests.py
branches/unhork/grassyknoll/tests/test_backends/SqlCollectionTests.py
branches/unhork/grassyknoll/tests/test_memcached_backend.py
branches/unhork/grassyknoll/web/lib/CherrypyResources.py
Log:
Issue #162: Mass renaming of Collection.py classes.
Modified: branches/unhork/attic/metakit/MetakitCollection.py
==============================================================================
--- branches/unhork/attic/metakit/MetakitCollection.py (original)
+++ branches/unhork/attic/metakit/MetakitCollection.py Mon Dec 29 12:54:50
2008
@@ -51,7 +51,7 @@
getter = attrgetter(*fields)
rows = (map(self._mk2py, getter(row)) for row in rows)
rows = (dict(zip(fields, row)) for row in rows)
- return
Collection.CollectionDocumentList(map(Collection.CollectionDocument, rows))
+ return Collection.DocumentList(map(Collection.Collection.Document,
rows))
def retrieve(self, ids, fields=None):
ids = set(ids)
Modified: branches/unhork/grassyknoll/client/ClientCollection.py
==============================================================================
--- branches/unhork/grassyknoll/client/ClientCollection.py (original)
+++ branches/unhork/grassyknoll/client/ClientCollection.py Mon Dec 29
12:54:50 2008
@@ -1,6 +1,6 @@
from itertools import imap
-from grassyknoll.collection import Collection
+import grassyknoll.collection.Collection as Collection
from grassyknoll.serial import JsonSerial
import RestClient
@@ -52,15 +52,15 @@
raise ClientError(response, content)
obj = JsonSerial.loads(content)
- return Collection.CollectionDocumentList.fromIds(obj['ids'],
-
metadata=obj['metadata'])
+ return Collection.DocumentList.fromIds(obj['ids'],
+ metadata=obj['metadata'])
# ??? Why do we need to remove the __url__? Anyway, this code only
makes one
# pass over the results, rather than two, so it should be
significantly
# faster, especially with large result sets.
@staticmethod
def makeResult(r):
- cr = Collection.CollectionDocument(r)
+ cr = Collection.Document(r)
cr.pop('__url__', None)
return cr
@@ -70,9 +70,9 @@
if response.status != 200: raise ClientError(response, content)
obj = JsonSerial.loads(content)
- results =
Collection.CollectionDocumentList(items=imap(self.makeResult,
-
obj['results']),
- metadata=obj['metadata'])
+ results = Collection.DocumentList(items=imap(self.makeResult,
+ obj['results']),
+ metadata=obj['metadata'])
return results
def sync(self):
@@ -108,7 +108,7 @@
raise ClientError(response, content)
obj = JsonSerial.loads(content)
- results =
Collection.CollectionDocumentList(items=imap(self.makeResult,
-
obj['results']),
- metadata=obj['metadata'])
+ results = Collection.DocumentList(items=imap(self.makeResult,
+ obj['results']),
+ metadata=obj['metadata'])
return results
Modified: branches/unhork/grassyknoll/collection/Collection.py
==============================================================================
--- branches/unhork/grassyknoll/collection/Collection.py (original)
+++ branches/unhork/grassyknoll/collection/Collection.py Mon Dec 29
12:54:50 2008
@@ -9,9 +9,9 @@
from Factory import FactoryMixin, Bunch
from grassyknoll.lib.util import normalizePath, all_slots
-__all__ = ['CollectionDocument', 'CollectionDocumentList',
- 'Collection', 'FileBasedCollection', 'DirBasedCollection',
- 'MemoryBasedCollection']
+__all__ = ['Collection.Document', 'Collection.DocumentList',
+ 'Collection.Collection', 'FileBased', 'DirBased',
+ 'MemoryBased']
class _ListLike(list):
"""base class for things that inherit from L{list}
@@ -95,7 +95,7 @@
except KeyError:
raise AttributeError(name)
-class CollectionDocument(_DictLike):
+class Document(_DictLike):
"""An item that may be I{added} to a L{Collection}
the C{id} attribute / C{__id__} value should probably be
@@ -111,7 +111,7 @@
__slots__ = ['norman']
def __init__(self, fields=None, norman=None, **kwargs):
- super(CollectionDocument, self).__init__(fields or [], **kwargs)
+ super(Document, self).__init__(fields or [], **kwargs)
assert norman is None or type(norman) is str
self.norman = norman
@@ -124,7 +124,7 @@
@classmethod
def fromFields(cls, d, keys):
- """build a CollectionDocument from (a subset) of d's items.
+ """build a Document from (a subset) of d's items.
C{__id__} will always be included, regardless of its presence in
keys.
@@ -134,7 +134,7 @@
@arg keys: keys to keep. If None, keep all keys
@type keys: set/tuple/list/dict
- @rtype: CollectionDocument
+ @rtype: Document
@raises KeyError: if C{__id__ not in d}
"""
@@ -150,15 +150,15 @@
return cls(ret)
-class CollectionDocumentList(_ListLike):
- """a set of L{CollectionDocument}s"""
+class DocumentList(_ListLike):
+ """a set of L{Document}s"""
__slots__ = []
def dump(self):
"""
@returns: a representation consisting of soleley builtin types.
- Includes: metadata=>dict & results=>list of L{CollectionDocument}s
+ Includes: metadata=>dict & results=>list of L{Document}s
@rtype: dict
"""
return {'metadata': self.metadata.copy(),
@@ -166,7 +166,7 @@
@classmethod
def fromIds(cls, ids, metadata=None):
- return cls((CollectionDocument(__id__=id) for id in ids),
metadata=metadata)
+ return cls((Document(__id__=id) for id in ids), metadata=metadata)
class Collection(FactoryMixin): #pragma: no cover
@@ -175,8 +175,8 @@
Items in a collection are uniquely identified by a C{id}.
Implementations are responsible for maintaining this constraint.
- Items are I{added} as instances of L{CollectionDocument} and
I{retrieved}
- as instances of L{CollectionDocument}.
+ Items are I{added} as instances of L{Document} and I{retrieved}
+ as instances of L{Document}.
Implementations are free to interpret various methods however is
reasonable. They may also choose not to implement methods if they are
not
@@ -184,7 +184,7 @@
Implementations may also provide query methods, named like I{foo}Query.
These methods may take whatever keyword arguments desired. They should
- return the results of the query as a L{CollectionDocumentList}.
+ return the results of the query as a L{DocumentList}.
L{location} defines how to find/access a Collection. Attributes are
backend-specific, but disk-based Collections have a C{path} attribute
@@ -214,7 +214,7 @@
def create(self, docs):
"""
@arg docs: several new docs to be added to the collection
- @type docs: list of L{CollectionDocument}s
+ @type docs: list of L{Document}s
@returns: None
@rtype: None
@@ -222,7 +222,7 @@
raise NotImplementedError
def delete(self, ids):
- """delete several L{CollectionDocument}s by id
+ """delete several L{Document}s by id
@arg ids: the ids to delete
@type ids: list of string
@@ -234,13 +234,13 @@
def list(self):
"""
- @returns: A list of CollectionDocuments having only their __id__
field, for each document in the collection.
- @rtype: L{CollectionDocumentList}
+ @returns: A list of Documents having only their __id__ field, for
each document in the collection.
+ @rtype: L{DocumentList}
"""
raise NotImplementedError
def retrieve(self, ids, fields=None):
- """retrieve several L{CollectionDocument}s by id
+ """retrieve several L{Document}s by id
@arg ids: the ids of the results
@type ids: list of string
@@ -251,7 +251,7 @@
@type fields: tuple or list
@returns: the results
- @rtype: L{CollectionDocumentList}
+ @rtype: L{DocumentList}
"""
raise NotImplementedError
@@ -358,7 +358,7 @@
"""
pass #pragma: no cover -- need to pass for cooperative super calls.
-class FileBasedCollection(Collection):
+class FileBased(Collection):
"""A convenience subclass of Collection which provides reasonable
classmethods for
collections which are based on files: _allocate ensure the directory
the file
is supposed to be created in exists, and _deallocate removes the file.
@@ -375,14 +375,14 @@
dirpath = os.path.dirname(location.path)
if not os.path.exists(dirpath):
os.makedirs(dirpath)
- super(FileBasedCollection, cls)._allocate(location)
+ super(FileBased, cls)._allocate(location)
@classmethod
def _deallocate(cls, location):
os.remove(location.path)
- super(FileBasedCollection, cls)._deallocate(location)
+ super(FileBased, cls)._deallocate(location)
-class DirBasedCollection(Collection):
+class DirBased(Collection):
"""A convenience subclass of Collection which provides reasonable
classmethods for
collections based on directories; _allocate ensures the directory
exists, and
_deallocate removes the directory.
@@ -390,7 +390,7 @@
@classmethod
def _allocate(cls, location, **kwargs):
os.makedirs(location.path)
- super(DirBasedCollection, cls)._allocate(location)
+ super(DirBased, cls)._allocate(location)
@classmethod
def exists(cls, location):
@@ -399,9 +399,9 @@
@classmethod
def _deallocate(cls, location):
shutil.rmtree(location.path)
- super(DirBasedCollection, cls)._deallocate(location)
+ super(DirBased, cls)._deallocate(location)
-class MemoryBasedCollection(Collection):
+class MemoryBased(Collection):
"""A convenience subclass of Collection which provides reasonable
classmethod stubs
for collections based on memory, since exists/_allocate/_deallocate
don't really
apply to memory-based collections.
@@ -412,8 +412,8 @@
@classmethod
def _allocate(cls, location):
- super(MemoryBasedCollection, cls)._allocate(location)
+ super(MemoryBased, cls)._allocate(location)
@classmethod
def _deallocate(cls, location):
- super(MemoryBasedCollection, cls)._deallocate(location)
+ super(MemoryBased, cls)._deallocate(location)
Modified: branches/unhork/grassyknoll/collection/ThreadCollection.py
==============================================================================
--- branches/unhork/grassyknoll/collection/ThreadCollection.py (original)
+++ branches/unhork/grassyknoll/collection/ThreadCollection.py Mon Dec 29
12:54:50 2008
@@ -1,6 +1,6 @@
"""contains L{ThreadCollection}"""
-from Collection import Collection
+import grassyknoll.collection.Collection as Collection
from grassyknoll.concurrent.ThreadPool import ThreadPool
from grassyknoll.concurrent.lib import chat
from grassyknoll.concurrent.Wrappers import (objectMessenger,
errorMessenger,
@@ -9,7 +9,7 @@
from grassyknoll.lib.util import ensureName
-class ThreadCollection(Collection):
+class ThreadCollection(Collection.Collection):
def __init__(self, factory, name=None, pool_factory=ThreadPool):
name = self.name = ensureName(name)
Modified:
branches/unhork/grassyknoll/collection/backends/dictionary/DictCollection.py
==============================================================================
---
branches/unhork/grassyknoll/collection/backends/dictionary/DictCollection.py
(original)
+++
branches/unhork/grassyknoll/collection/backends/dictionary/DictCollection.py
Mon Dec 29 12:54:50 2008
@@ -2,9 +2,9 @@
import cPickle as pickle
import os.path
-from grassyknoll.collection.Collection import *
+import grassyknoll.collection.Collection as Collection
-class BaseDictCollection(Collection):
+class BaseDictCollection(Collection.Collection):
"""base class for dict-based collections"""
def __init__(self, location):
@@ -15,7 +15,7 @@
return len(self.data)
def list(self):
- return CollectionDocumentList.fromIds(self.data)
+ return Collection.DocumentList.fromIds(self.data)
def create(self, docs):
for doc in docs:
@@ -27,14 +27,14 @@
def retrieve(self, ids, fields=None):
fields = self.normalizeFields(fields)
- return CollectionDocumentList(CollectionDocument.fromFields(doc,
fields) for doc in
+ return Collection.DocumentList(Collection.Document.fromFields(doc,
fields) for doc in
(self.data.get(i) for i in ids) if doc
is not None)
-class DictCollection(BaseDictCollection, MemoryBasedCollection):
+class DictCollection(BaseDictCollection, Collection.MemoryBased):
"""in-memory collection"""
pass
-class PersistentDictCollection(BaseDictCollection, FileBasedCollection):
+class PersistentDictCollection(BaseDictCollection, Collection.FileBased):
"""a L{DictCollection} that saves to a pickle"""
def __init__(self, location):
super(PersistentDictCollection, self).__init__(location)
Modified:
branches/unhork/grassyknoll/collection/backends/gdbm/GdbmCollection.py
==============================================================================
--- branches/unhork/grassyknoll/collection/backends/gdbm/GdbmCollection.py
(original)
+++ branches/unhork/grassyknoll/collection/backends/gdbm/GdbmCollection.py
Mon Dec 29 12:54:50 2008
@@ -5,11 +5,11 @@
import gdbm
import cPickle as pickle
-from grassyknoll.collection.Collection import *
+import grassyknoll.collection.Collection as Collection
# XXX I need love
# ??? Just the docstring, or something else? Most parts seem in-place...
-class GdbmCollection(FileBasedCollection):
+class GdbmCollection(Collection.FileBased):
"""a gdbm collection"""
def __init__(self, location):
"""
@@ -44,7 +44,7 @@
self.gdbm.reorganize()
def list(self):
- return CollectionDocumentList.fromIds(self.gdbm.keys())
+ return Collection.DocumentList.fromIds(self.gdbm.keys())
def create(self, docs):
for doc in docs:
@@ -59,14 +59,14 @@
def retrieve(self, ids, fields=None):
fields = self.normalizeFields(fields)
- results = CollectionDocumentList()
+ results = Collection.DocumentList()
for uid in ids:
try:
s = self.gdbm[uid]
except KeyError:
pass
else:
- results.append(CollectionDocument.fromFields(self.load(s),
fields))
+
results.append(Collection.Document.fromFields(self.load(s), fields))
return results
def flush(self):
Modified:
branches/unhork/grassyknoll/collection/backends/lucene/LuceneCollection.py
==============================================================================
---
branches/unhork/grassyknoll/collection/backends/lucene/LuceneCollection.py
(original)
+++
branches/unhork/grassyknoll/collection/backends/lucene/LuceneCollection.py
Mon Dec 29 12:54:50 2008
@@ -16,7 +16,7 @@
from HitsWrapper import HitsWrapper
from LuceneConstants import Constants
from grassyknoll.lib import Norman
-from grassyknoll.collection.Collection import *
+import grassyknoll.collection.Collection as Collection
# TODO: see http://wiki.apache.org/solr/StandardRequestHandler for more
things
# to stuff in metadata
@@ -28,15 +28,15 @@
query_parser.setDefaultOperator(self.operator)
return query_parser
-class LuceneCollection(Collection):
+class LuceneCollection(Collection.Collection):
"""a L{Collection.Collection} with L{Smarts}
This class implements all of the L{Collection.Collection} methods.
- L{Collection.CollectionDocument}s returned include a C{__score__}
field, a
+ L{Collection.Document}s returned include a C{__score__} field, a
measure of relevance.
- L{Collection.CollectionDocumentList}s returned include as metadata:
+ L{Collection.DocumentList}s returned include as metadata:
- C{count}: a count of the total number of matches
@ivar analyzer: a Lucene analyzer
@@ -241,8 +241,8 @@
hits = self._search(self.__manyIdQuery(ids))
assert len(hits) <= len(ids)
fields = self.normalizeFields(fields)
- results = (CollectionDocument(hit.fields(fields)) for hit in hits)
- return CollectionDocumentList(results)
+ results = (Collection.Document(hit.fields(fields)) for hit in hits)
+ return Collection.DocumentList(results)
def create(self, docs):
## delete docs:
@@ -275,7 +275,7 @@
@type fields: set
@returns: the results, or None if not found
- @rtype: L{CollectionDocumentList}
+ @rtype: L{Collection.DocumentList}
"""
if isinstance(q, basestring):
q = self.query_parser.parse(q)
@@ -283,26 +283,26 @@
hits = self._search(q)
def result(hit):
hit.fields()['__score__'] = hit.score()
- return CollectionDocument.fromFields(hit.fields(), fields)
+ return Collection.Document.fromFields(hit.fields(), fields)
results = (result(h) for h in hits[start:stop])
## TODO: it'd be nice to return addt'l metadata - maxScore comes
to mind.
## That would require using a different search method.
## Whatever returns a TopDocs() instead of a Hits().
- return CollectionDocumentList(results, {'count':len(hits)})
+ return Collection.DocumentList(results, {'count':len(hits)})
def list(self):
- return
CollectionDocumentList.fromIds(TermIterator.termIterator(self.reader,
+ return
Collection.DocumentList.fromIds(TermIterator.termIterator(self.reader,
'__id__'))
def buildSmartDoc(self, doc):
"""
- @type doc: L{Collection.CollectionDocument}
+ @type doc: L{Collection.Document}
@rtype: L{Smarts.SmartDoc}
"""
- assert isinstance(doc, CollectionDocument)
+ assert isinstance(doc, Collection.Document)
norman = getattr(doc, 'norman', None)
norman = self.storage_normans[norman]
return Smarts.SmartDoc(norman(doc))
Modified:
branches/unhork/grassyknoll/collection/backends/memcached/MemcachedCollection.py
==============================================================================
---
branches/unhork/grassyknoll/collection/backends/memcached/MemcachedCollection.py
(original)
+++
branches/unhork/grassyknoll/collection/backends/memcached/MemcachedCollection.py
Mon Dec 29 12:54:50 2008
@@ -6,11 +6,11 @@
import memcache
-from grassyknoll.collection.Collection import *
+import grassyknoll.collection.Collection as Collection
## should we allow for an expire time on set_multi?
-class MemcachedCollection(Collection):
+class MemcachedCollection(Collection.Collection):
def __init__(self, location, compress_threshold=0, debug=False):
"""
@param location: Determines the location of the memcached
collection. Expects
@@ -35,7 +35,7 @@
def create(self, docs):
# XXX inner dict here should get clobbered but python can't pickle
- # CollectionDocuments ATM due to slots
+ # Collection.Documents ATM due to slots
notstored = self.mc.set_multi(dict((doc.id, dict(doc)) for doc in
docs),
min_compress_len=self.compress_threshold,
key_prefix=self.location.key_prefix)
@@ -49,7 +49,7 @@
def retrieve(self, ids, fields=None):
fields = self.normalizeFields(fields)
- return CollectionDocumentList(CollectionDocument.fromFields(doc,
fields)
+ return Collection.DocumentList(Collection.Document.fromFields(doc,
fields)
for i, doc in
self.mc.get_multi(ids,
key_prefix=self.location.key_prefix).iteritems())
Modified:
branches/unhork/grassyknoll/collection/backends/sql/SqlCollection.py
==============================================================================
--- branches/unhork/grassyknoll/collection/backends/sql/SqlCollection.py
(original)
+++ branches/unhork/grassyknoll/collection/backends/sql/SqlCollection.py
Mon Dec 29 12:54:50 2008
@@ -3,7 +3,7 @@
import TableMaker
-from grassyknoll.collection.Collection import *
+import grassyknoll.collection.Collection as Collection
__all__ = ['rollback', 'tryCommit', 'SqlCollection']
@@ -41,13 +41,13 @@
return dict(izip((d[0] for d in description), row))
def build_result_set(cursor):
- """make a L{CollectionDocumentList} from a cursor"""
- return CollectionDocumentList(CollectionDocument(dictify(r,
cursor.description))
+ """make a L{Collection.DocumentList} from a cursor"""
+ return Collection.DocumentList(Collection.Document(dictify(r,
cursor.description))
for r in cursor)
## the good stuff
-class SqlCollection(Collection):
+class SqlCollection(Collection.Collection):
placeholder = '?' # Other dbapi unnamed quoting schemes use %s, etc.
def __init__(self, location, **kwargs):
@@ -112,7 +112,7 @@
@rollback
def list(self):
sql = 'SELECT __id__ FROM %s' % self.location.table.name
- return CollectionDocumentList.fromIds(r[0] for r in
self.execute(sql))
+ return Collection.DocumentList.fromIds(r[0] for r in
self.execute(sql))
@rollback
def _sqlQuery(self, where, *args, **kwargs):
@@ -174,7 +174,7 @@
@tryCommit
def create(self, docs):
if not docs:
- return CollectionDocumentList()
+ return Collection.DocumentList()
self._delete([doc.id for doc in docs])
for doc in docs:
(names, values) = undictify(doc)
Modified:
branches/unhork/grassyknoll/collection/backends/sql/SqliteCollection.py
==============================================================================
--- branches/unhork/grassyknoll/collection/backends/sql/SqliteCollection.py
(original)
+++ branches/unhork/grassyknoll/collection/backends/sql/SqliteCollection.py
Mon Dec 29 12:54:50 2008
@@ -5,7 +5,7 @@
from SqlCollection import SqlCollection, tryCommit
import grassyknoll.collection.backends.sql.TableMaker as TableMaker
-from grassyknoll.collection.Collection import FileBasedCollection
+import grassyknoll.collection.Collection as Collection
def __register_adapters_and_converters():
"""register some better adapters & converters.
@@ -85,7 +85,7 @@
__register_adapters_and_converters()
-class SqliteCollection(SqlCollection, FileBasedCollection):
+class SqliteCollection(SqlCollection, Collection.FileBased):
def __init__(self, location, cache_size=None,
synchronous_writes=None, cached_statements=100):
"""
Modified: branches/unhork/grassyknoll/tests/fixtures/load_nsf.py
==============================================================================
--- branches/unhork/grassyknoll/tests/fixtures/load_nsf.py (original)
+++ branches/unhork/grassyknoll/tests/fixtures/load_nsf.py Mon Dec 29
12:54:50 2008
@@ -17,5 +17,5 @@
fname = os.path.join(os.path.dirname(__file__), 'nsf_ra')
for fname, obj in loadFixtures(fname):
- doc = Collection.CollectionDocument(dict(obj), __id__=fname)
+ doc = Collection.Document(dict(obj), __id__=fname)
coll.create([doc])
Modified: branches/unhork/grassyknoll/tests/test_Collection_Objects.py
==============================================================================
--- branches/unhork/grassyknoll/tests/test_Collection_Objects.py (original)
+++ branches/unhork/grassyknoll/tests/test_Collection_Objects.py Mon Dec 29
12:54:50 2008
@@ -6,14 +6,14 @@
from nose.tools import *
from grassyknoll.tests import *
-from grassyknoll.collection.Collection import *
+import grassyknoll.collection.Collection as Collection
from Factory import Bunch
def test_repr():
- assert_does_not_raise(repr, CollectionDocumentList)
+ assert_does_not_raise(repr, Collection.DocumentList)
def test_query():
- class MyCollection(Collection):
+ class MyCollection(Collection.Collection):
def fooQuery(self, bar=1):
return bar
def barQuery(self, baz=2):
@@ -33,11 +33,11 @@
yield __test_ids, 100
def __test_ids(num):
- ids = CollectionDocumentList.fromIds(imap(unicode, xrange(num)),
+ ids = Collection.DocumentList.fromIds(imap(unicode, xrange(num)),
metadata={'pants': 34})
assert len(ids) == num
for i, uid in enumerate(ids):
- assert isinstance(uid, CollectionDocument)
+ assert isinstance(uid, Collection.Document)
assert unicode(i) == uid['__id__']
assert hasattr(ids, 'metadata')
@@ -45,7 +45,7 @@
ids2 = copy.copy(ids)
- assert isinstance(ids2, CollectionDocumentList)
+ assert isinstance(ids2, Collection.DocumentList)
assert ids is not ids2
assert ids == ids2
assert ids.metadata is not ids2.metadata
@@ -59,7 +59,7 @@
def test_result():
- result=CollectionDocument(pants=42, shirt=36, __id__=u'clothes')
+ result=Collection.Document(pants=42, shirt=36, __id__=u'clothes')
result2=copy.copy(result)
assert result is not result2
@@ -96,7 +96,7 @@
assert dump == result
def test_document():
- doc = CollectionDocument(pants=42, shirt=36, norman='viking')
+ doc = Collection.Document(pants=42, shirt=36, norman='viking')
doc2 = copy.copy(doc)
assert doc is not doc2
@@ -137,13 +137,13 @@
def test_result_set():
yield __test_result_set, ()
- yield __test_result_set, [CollectionDocument(height=42, width=34,
color='blue', __id__=u'pants')]
- yield __test_result_set, [CollectionDocument(height=42, width=34,
color='blue', __id__=u'pants'),
- CollectionDocument(height=56, width=101,
color='pink', __id__=u'shirt')]
+ yield __test_result_set, [Collection.Document(height=42, width=34,
color='blue', __id__=u'pants')]
+ yield __test_result_set, [Collection.Document(height=42, width=34,
color='blue', __id__=u'pants'),
+ Collection.Document(height=56, width=101,
color='pink', __id__=u'shirt')]
def __test_result_set(items):
- rset = CollectionDocumentList(items)
+ rset = Collection.DocumentList(items)
assert len(rset) == len(items)
for r1, r2 in zip(items, rset):
assert r1 is r2
@@ -151,7 +151,7 @@
assert hasattr(rset, 'metadata')
rset2 = copy.copy(rset)
- assert isinstance(rset2, CollectionDocumentList)
+ assert isinstance(rset2, Collection.DocumentList)
assert rset2 is not rset
assert rset2 == rset
assert rset2.metadata is not rset.metadata
@@ -164,53 +164,53 @@
assert dump['results'] == rset
def test_collection():
- my_collection = Collection(Bunch(path='pants'))
+ my_collection = Collection.Collection(Bunch(path='pants'))
# verify that repr() doesn't fail
repr(my_collection)
def test_fromFields():
d = {'foo': 1, 'bar': 2, '__id__':'pants'}
- assert isinstance(CollectionDocument.fromFields(d, None),
CollectionDocument)
- assert CollectionDocument.fromFields(d, None) == d
- assert CollectionDocument.fromFields(d, None) is not d
- assert CollectionDocument.fromFields(d, ()) == {'__id__':'pants'}
- assert CollectionDocument.fromFields(d, ['baz']) == {'__id__':'pants'}
- assert CollectionDocument.fromFields(d, ['bar']) == {'bar':
2, '__id__':'pants'}
- assert CollectionDocument.fromFields(d, ['foo', 'bar']) == d
- assert CollectionDocument.fromFields(d, ['foo', 'bar', '__id__']) == d
- assert CollectionDocument.fromFields(d, ['foo', 'bar', 'baz']) == d
+ assert isinstance(Collection.Document.fromFields(d, None),
Collection.Document)
+ assert Collection.Document.fromFields(d, None) == d
+ assert Collection.Document.fromFields(d, None) is not d
+ assert Collection.Document.fromFields(d, ()) == {'__id__':'pants'}
+ assert Collection.Document.fromFields(d, ['baz']) == {'__id__':'pants'}
+ assert Collection.Document.fromFields(d, ['bar']) == {'bar':
2, '__id__':'pants'}
+ assert Collection.Document.fromFields(d, ['foo', 'bar']) == d
+ assert Collection.Document.fromFields(d, ['foo', 'bar', '__id__']) == d
+ assert Collection.Document.fromFields(d, ['foo', 'bar', 'baz']) == d
-def test_FileBasedCollection():
+def test_FileBased():
basedir = '/tmp/fbc%s' % os.getpid()
dir = os.path.join(basedir, 'foo/bar')
filename = os.path.join(dir, 'baz')
location = Bunch(path=filename)
assert not os.path.exists(dir)
- assert not FileBasedCollection.exists(location)
- FileBasedCollection.allocate(location)
+ assert not Collection.FileBased.exists(location)
+ Collection.FileBased.allocate(location)
assert os.path.exists(dir)
assert os.path.isdir(dir)
assert_len(os.listdir(dir), 0)
file(filename, 'w').close()
- assert FileBasedCollection.exists(location)
- FileBasedCollection.deallocate(location)
+ assert Collection.FileBased.exists(location)
+ Collection.FileBased.deallocate(location)
assert not os.path.exists(filename)
shutil.rmtree(basedir)
-def test_DirBasedCollection():
+def test_DirBased():
basedir = '/tmp/dbc%s' % os.getpid()
dir = os.path.join(basedir, 'foo/bar')
location = Bunch(path=dir)
assert not os.path.exists(dir)
- assert not DirBasedCollection.exists(location)
- DirBasedCollection.allocate(location)
- assert DirBasedCollection.exists(location)
+ assert not Collection.DirBased.exists(location)
+ Collection.DirBased.allocate(location)
+ assert Collection.DirBased.exists(location)
assert os.path.exists(dir)
assert os.path.isdir(dir)
assert_len(os.listdir(dir), 0)
- DirBasedCollection.deallocate(location)
+ Collection.DirBased.deallocate(location)
assert not os.path.exists(dir)
shutil.rmtree(basedir)
Modified:
branches/unhork/grassyknoll/tests/test_backends/FixtureCollectionTests.py
==============================================================================
---
branches/unhork/grassyknoll/tests/test_backends/FixtureCollectionTests.py
(original)
+++
branches/unhork/grassyknoll/tests/test_backends/FixtureCollectionTests.py
Mon Dec 29 12:54:50 2008
@@ -61,7 +61,7 @@
id, exc_info=True)
bad += 1
else:
- doc = Collection.CollectionDocument(doc, __id__=id)
+ doc = Collection.Document(doc, __id__=id)
self.collection.create([doc])
if not good or bad/float(good) > 0.5:
raise ValueError('%s/%s docs docs errored' % (bad, total))
Modified:
branches/unhork/grassyknoll/tests/test_backends/GenericCollectionTests.py
==============================================================================
---
branches/unhork/grassyknoll/tests/test_backends/GenericCollectionTests.py
(original)
+++
branches/unhork/grassyknoll/tests/test_backends/GenericCollectionTests.py
Mon Dec 29 12:54:50 2008
@@ -15,7 +15,7 @@
import grassyknoll
from grassyknoll.tests import *
-from grassyknoll.collection.Collection import Collection
+import grassyknoll.collection.Collection as Collection
from grassyknoll.client.ClientCollection import ClientCollection
from grassyknoll.lib import Norman
from Factory import Factory
@@ -217,7 +217,7 @@
"""
if not test_base_classes:
raise ValueError('test_base_classes must be a non-empty list.')
- if not issubclass(collectionClass, Collection):
+ if not issubclass(collectionClass, Collection.Collection):
raise ValueError('collectionClass must be a subclass of
Collection.')
kwargs['collectionClass'] = collectionClass
kwargs['location'] = location
Modified:
branches/unhork/grassyknoll/tests/test_backends/SimpleCollectionTests.py
==============================================================================
---
branches/unhork/grassyknoll/tests/test_backends/SimpleCollectionTests.py
(original)
+++
branches/unhork/grassyknoll/tests/test_backends/SimpleCollectionTests.py
Mon Dec 29 12:54:50 2008
@@ -2,12 +2,12 @@
import grassyknoll.tests.test_backends.GenericCollectionTests \
as GenericCollectionTests
-from grassyknoll.collection.Collection import *
+import grassyknoll.collection.Collection as Collection
__all__ = ['makeTestClasses', 'SimpleLoadBase', 'testdocs']
def make_doc(uid, size, color):
- return uid, CollectionDocument({u'__id__':uid,
+ return uid, Collection.Document({u'__id__':uid,
u'size':size,
u'color':color})
@@ -24,18 +24,18 @@
def test_list(self):
uids = self.collection.list()
- assert isinstance(uids, CollectionDocumentList)
+ assert isinstance(uids, Collection.DocumentList)
assert_len(uids, 0)
def test_retrieve(self):
results = self.collection.retrieve(['pants', 'shirts'])
- assert isinstance(results, CollectionDocumentList)
+ assert isinstance(results, Collection.DocumentList)
assert_len(results, 0)
def test_retrieve_fields(self):
results = self.collection.retrieve(['pants', 'shirts'],
fields=['size', 'color'])
- assert isinstance(results, CollectionDocumentList)
+ assert isinstance(results, Collection.DocumentList)
assert_len(results, 0)
def test_delete(self):
@@ -65,18 +65,18 @@
def test_list(self):
uids = self.collection.list()
- assert isinstance(uids, CollectionDocumentList)
+ assert isinstance(uids, Collection.DocumentList)
assert_len(uids, len(testuids))
assert_sorted_equals((cd['__id__'] for cd in uids), testuids)
def test_retrieve(self):
for uid in testuids:
results = self.collection.retrieve([uid])
- assert isinstance(results, CollectionDocumentList)
+ assert isinstance(results, Collection.DocumentList)
assert_len(results, 1)
result = results[0]
- assert isinstance(result, CollectionDocument)
+ assert isinstance(result, Collection.Document)
assert_equals(result, self.getTestDocs()[uid])
del results
@@ -86,18 +86,18 @@
fields = (u'size', u'color')
for uid in testuids:
results = self.collection.retrieve([uid], fields=fields)
- assert isinstance(results, CollectionDocumentList)
+ assert isinstance(results, Collection.DocumentList)
assert_len(results, 1)
result = results[0]
- assert isinstance(result, CollectionDocument)
+ assert isinstance(result, Collection.Document)
assert_sorted_equals(fields + ('__id__',), result.iterkeys())
for f in fields:
assert_equals(result[f], self.getTestDocs()[uid][f])
def test_retrieve_nonesuch(self):
results = self.collection.retrieve([u'hat'])
- assert isinstance(results, CollectionDocumentList)
+ assert isinstance(results, Collection.DocumentList)
assert_len(results, 0)
def test_delete(self):
Modified:
branches/unhork/grassyknoll/tests/test_backends/SqlCollectionTests.py
==============================================================================
--- branches/unhork/grassyknoll/tests/test_backends/SqlCollectionTests.py
(original)
+++ branches/unhork/grassyknoll/tests/test_backends/SqlCollectionTests.py
Mon Dec 29 12:54:50 2008
@@ -2,7 +2,7 @@
from Factory import ObjectTemplate
-from grassyknoll.collection.Collection import *
+import grassyknoll.collection.Collection as Collection
from grassyknoll.collection.backends.sql import TableMaker
@@ -92,7 +92,7 @@
def test_create(self):
assert_len(self.collection.create([]), 0)
assert_raises(Exception, self.collection.create,
- [CollectionDocument(**{'__id__': u'foo',
+ [Collection.Document(**{'__id__': u'foo',
'invalid column name': 1})])
def test_basic_query_fields(self):
Modified: branches/unhork/grassyknoll/tests/test_memcached_backend.py
==============================================================================
--- branches/unhork/grassyknoll/tests/test_memcached_backend.py (original)
+++ branches/unhork/grassyknoll/tests/test_memcached_backend.py Mon Dec 29
12:54:50 2008
@@ -3,7 +3,7 @@
### the Memcached backend.
from grassyknoll.collection.backends.memcached.MemcachedCollection import
MemcachedCollection
-from grassyknoll.collection.Collection import *
+import grassyknoll.collection.Collection as Collection
from Factory import Bunch
from nose.exc import SkipTest
@@ -42,10 +42,10 @@
assert len(docs) == len(uids)
for uid in uids:
results = collection.retrieve([uid])
- assert isinstance(results, CollectionDocumentList)
+ assert isinstance(results, Collection.DocumentList)
assert len(results) == 1
result = results[0]
- assert isinstance(result, CollectionDocument)
+ assert isinstance(result, Collection.Document)
for f in SimpleCollectionTests.testdocs[uid]:
assert result[f] == SimpleCollectionTests.testdocs[uid][f]
Modified: branches/unhork/grassyknoll/web/lib/CherrypyResources.py
==============================================================================
--- branches/unhork/grassyknoll/web/lib/CherrypyResources.py (original)
+++ branches/unhork/grassyknoll/web/lib/CherrypyResources.py Mon Dec 29
12:54:50 2008
@@ -2,7 +2,7 @@
CherryPy resources related to GrassyKnoll -- handle actual web serving
functionality.
"""
-from grassyknoll.collection.Collection import Collection,
CollectionDocument
+import grassyknoll.collection.Collection as Collection
from grassyknoll.lib import Norman
from grassyknoll.lib.util import str_unique_id
from grassyknoll.web.lib.FlexibleIO import jsonIO
@@ -14,7 +14,7 @@
called in bin/cherryknoll.
"""
def setup(self, collection, model):
- assert isinstance(collection, Collection)
+ assert isinstance(collection, Collection.Collection)
assert isinstance(model, Norman.Norman)
self.collection = collection
@@ -54,7 +54,7 @@
@jsonIO()
def PUT(self, jsonDocument, documentId):
- collectionDocument =
CollectionDocument(fields=grassyKnollObjects.model(jsonDocument))
+ collectionDocument =
Collection.Document(fields=grassyKnollObjects.model(jsonDocument))
collectionDocument.id = documentId
grassyKnollObjects.collection.create([collectionDocument])
@@ -68,7 +68,7 @@
def POST(self, jsonDocuments):
assert isinstance(jsonDocuments, list)
- colletionDocuments =
[CollectionDocument(fields=grassyKnollObjects.model(f)) for f in
jsonDocuments]
+ colletionDocuments =
[Collection.Document(fields=grassyKnollObjects.model(f)) for f in
jsonDocuments]
for doc in colletionDocuments:
if not hasattr(doc, 'id'): doc.id = str_unique_id()