Skip to content

Commit

Permalink
Added basic test setup for creating storage mechanisms.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmerickel committed Mar 12, 2012
1 parent 95bfcf4 commit 8299468
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion anykeystore/exceptions.py
@@ -1,4 +1,4 @@
class ConfigurationError(object):
class ConfigurationError(Exception):
""" Raised when configuration fails on a backend."""

def __init__(self, message, exc=None):
Expand Down
8 changes: 6 additions & 2 deletions anykeystore/store.py
@@ -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:
Expand Down Expand Up @@ -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')
Expand Down
25 changes: 25 additions & 0 deletions anykeystore/tests/test_store.py
@@ -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))
6 changes: 6 additions & 0 deletions setup.cfg
@@ -0,0 +1,6 @@
[nosetests]
match=^test
where=anykeystore
nocapture=1
cover-package=anykeystore
cover-erase=1
4 changes: 3 additions & 1 deletion setup.py
Expand Up @@ -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',
Expand All @@ -33,6 +34,7 @@
include_package_data=True,
zip_safe=False,
install_requires=requires,
test_suite="anykeystore.tests",
entry_points="""\
""",
)
22 changes: 22 additions & 0 deletions 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.