Modified:
branches/unhork/grassyknoll/collection/Collection.py
branches/unhork/grassyknoll/collection/backends/sql/SqlCollection.py
branches/unhork/grassyknoll/collection/backends/sql/SqliteCollection.py
branches/unhork/grassyknoll/tests/test_backends/test_SqliteCollection.py
Log:
Issue #161: Fixed SQLite :memory: support, added tests, uncommented other
performance tests (since they now run in 7 seconds instead of 43).
Modified: branches/unhork/grassyknoll/collection/Collection.py
==============================================================================
--- branches/unhork/grassyknoll/collection/Collection.py (original)
+++ branches/unhork/grassyknoll/collection/Collection.py Mon Dec 29
20:00:58 2008
@@ -373,7 +373,7 @@
@classmethod
def _allocate(cls, location):
dirpath = os.path.dirname(location.path)
- if not os.path.exists(dirpath):
+ if dirpath and not os.path.exists(dirpath):
os.makedirs(dirpath)
super(FileBased, cls)._allocate(location)
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 20:00:58 2008
@@ -65,11 +65,14 @@
@classmethod
def _allocate(cls, location):
super(SqlCollection, cls)._allocate(location)
- assert isinstance(location.table, TableMaker.Table)
connection = cls.connect(location)
- location.table.create(connection.cursor())
- connection.commit()
+ cls.createTable(connection, location.table)
return connection
+
+ @classmethod
+ def createTable(cls, connection, table):
+ table.create(connection.cursor())
+ connection.commit()
@classmethod
def _deallocate(cls, location):
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 20:00:58 2008
@@ -101,6 +101,8 @@
"""
super(SqliteCollection, self).__init__(location)
self.connection = self.connect(self.location, cached_statements)
+ if location.path == ':memory:':
+ self.createTable(self.connection, location.table)
if synchronous_writes is not None:
self.pragma(self.connection, 'synchronous', synchronous_writes)
if cache_size is not None:
Modified:
branches/unhork/grassyknoll/tests/test_backends/test_SqliteCollection.py
==============================================================================
---
branches/unhork/grassyknoll/tests/test_backends/test_SqliteCollection.py
(original)
+++
branches/unhork/grassyknoll/tests/test_backends/test_SqliteCollection.py
Mon Dec 29 20:00:58 2008
@@ -5,10 +5,12 @@
from grassyknoll.collection.backends.sql.SqliteCollection import
SqliteCollection
makeTestClasses(SqliteCollection, globals(), path=TestFilenameFactory)
-# Commented out for speed concerns; it doubles the time it takes to run
these tests. Uncomment
-# to get better test coverage.
-## makeTestClasses(SqliteCollection, globals(), path=TestFilenameFactory,
-## __init_kwargs__={'synchronous_writes': False,
-## 'cache_size': 1024},
-## __allocate_kwargs__={'page_size': 1024},
-## test_class_name_suffix='TweakedKwargs')
+
+makeTestClasses(SqliteCollection, globals(), path=':memory:',
+ test_class_name_suffix='Memory')
+
+makeTestClasses(SqliteCollection, globals(), path=':memory:',
+ __init_kwargs__={'synchronous_writes': False,
+ 'cache_size': 1024},
+ __allocate_kwargs__={'page_size': 1024},
+ test_class_name_suffix='TweakedKwargs')