Permalink
Browse files

Added basic test setup for creating storage mechanisms.

  • Loading branch information...
1 parent 95bfcf4 commit 8299468a35805cb62edcd63c1a6e0c76869e27be @mmerickel mmerickel committed Mar 12, 2012
Showing with 63 additions and 4 deletions.
  1. +1 −1 anykeystore/exceptions.py
  2. +6 −2 anykeystore/store.py
  3. +25 −0 anykeystore/tests/test_store.py
  4. +6 −0 setup.cfg
  5. +3 −1 setup.py
  6. +22 −0 tox.ini
@@ -1,4 +1,4 @@
-class ConfigurationError(object):
+class ConfigurationError(Exception):
""" Raised when configuration fails on a backend."""
def __init__(self, message, exc=None):
View
@@ -1,8 +1,12 @@
+import sys
+
from anykeystore.exceptions import ConfigurationError
def _load_backend(name):
try:
- module = __import__('anykeystore.backends.%s' % name)
+ module_name = 'anykeystore.backends.%s' % name
+ __import__(module_name)
+ module = sys.modules[module_name]
if hasattr(module, 'backend'):
backend = module.backend
else:
@@ -34,7 +38,7 @@ def create_store(name, **kwargs):
def create_store_from_settings(settings, prefix='', **kwargs):
plen = len(prefix)
- for k, v in settings.iteritems():
+ for k, v in settings.items():
if k.startswith(prefix):
kwargs[k[plen:]] = v
name = kwargs.pop('store')
@@ -0,0 +1,25 @@
+import unittest
+
+class TestStore(unittest.TestCase):
+
+ def test_create_store(self):
+ from anykeystore import create_store
+ store = create_store('memory')
+
+ from anykeystore.backends.memory import MemoryStore
+ self.assertTrue(isinstance(store, MemoryStore))
+
+ def test_create_store_from_settings(self):
+ from anykeystore import create_store_from_settings
+ store = create_store_from_settings({'store': 'memory'})
+
+ from anykeystore.backends.memory import MemoryStore
+ self.assertTrue(isinstance(store, MemoryStore))
+
+ def test_create_store_from_settings_with_prefix(self):
+ from anykeystore import create_store_from_settings
+ store = create_store_from_settings(
+ {'any.store': 'memory'}, prefix='any.')
+
+ from anykeystore.backends.memory import MemoryStore
+ self.assertTrue(isinstance(store, MemoryStore))
View
@@ -0,0 +1,6 @@
+[nosetests]
+match=^test
+where=anykeystore
+nocapture=1
+cover-package=anykeystore
+cover-erase=1
View
@@ -17,12 +17,13 @@
long_description=README + '\n\n' + CHANGES,
# Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
+ 'Development Status :: 3 - Alpha',
"Intended Audience :: Developers",
- 'License :: OSI Approved :: MIT License',
"Programming Language :: Python",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
'Topic :: Database',
+ 'License :: OSI Approved :: MIT License',
],
keywords='',
author='Michael Merickel',
@@ -33,6 +34,7 @@
include_package_data=True,
zip_safe=False,
install_requires=requires,
+ test_suite="anykeystore.tests",
entry_points="""\
""",
)
View
22 tox.ini
@@ -0,0 +1,22 @@
+[tox]
+envlist =
+ py26,py27,py32,pypy,cover
+
+[testenv]
+commands =
+ python setup.py test -q
+
+[testenv:cover]
+basepython =
+ python2.6
+commands =
+ python setup.py nosetests --with-xunit --with-xcoverage
+deps =
+ nose
+ coverage
+ nosexcover
+
+# we separate coverage into its own testenv because a) "last run wins" wrt
+# cobertura jenkins reporting and b) pypy and jython can't handle any
+# combination of versions of coverage and nosexcover that i can find.
+# coverage==3.4 is required by nosexcover.

0 comments on commit 8299468

Please sign in to comment.