Commit fa5ca1ec authored by Eliot Berriot's avatar Eliot Berriot

Added tox and refactored tests

parent 3c100135
from registries import Registry, meta_registry
from .registries import Registry, meta_registry
__version__ = "0.2.0"
\ No newline at end of file
from test_registries import awesome_people
print(inexisting_var)
\ No newline at end of file
import os
from setuptools import setup, find_packages
import persisting_theory
import persisting_theory as package
README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
......@@ -9,11 +9,11 @@ os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
setup(
name='persisting-theory',
version=persisting_theory.__version__,
version=package.__version__,
packages=find_packages(),
include_package_data=True,
license='BSD', # example license
description='A python package to build registries that can autodiscover values accross your project components',
description='Registries that can autodiscover values accross your project apps',
long_description=README,
url='http://code.eliotberriot.com/eliotberriot/persisting-theory',
author='Eliot Berriot',
......
import os, sys
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
BASE_DIR = os.path.dirname(TEST_DIR)
sys.path.append(BASE_DIR)
\ No newline at end of file
from test_registries import awesome_people
from ..test_registries import awesome_people
@awesome_people.register
class AlainDamasio:
......
from test_registries import vegetable_registry
from ..test_registries import vegetable_registry
@vegetable_registry.register
class Potato:
......
from test_registries import awesome_people
from ..test_registries import awesome_people
@awesome_people.register
class FrederikPeeters:
......
from test_registries import vegetable_registry
from ..test_registries import vegetable_registry
@vegetable_registry.register
class Ketchup:
......
from ..test_registries import awesome_people
print(inexisting_var)
\ No newline at end of file
from registries import Registry, meta_registry
from persisting_theory import Registry, meta_registry
class AwesomePeopleRegistry(Registry):
look_into = "awesome_people"
......
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
import unittest
import test_registries
import registries
from . import test_registries
import persisting_theory
registries.meta_registry.look_into = "test_registries"
persisting_theory.meta_registry.look_into = "test_registries"
TEST_APPS = (
"app1",
"app2",
"tests.app1",
"tests.app2",
)
class RegistryTest(unittest.TestCase):
def test_can_infer_name_from_class_function_and_instance(self):
registry = registries.Registry()
registry = persisting_theory.Registry()
def something():
pass
......@@ -31,7 +30,7 @@ class RegistryTest(unittest.TestCase):
def test_can_register_data_to_registry(self):
data = "something"
registry = registries.Registry()
registry = persisting_theory.Registry()
registry.register(data, name="key")
self.assertEqual(len(registry), 1)
......@@ -39,7 +38,7 @@ class RegistryTest(unittest.TestCase):
def test_can_restric_registered_data(self):
class RestrictedRegistry(registries.Registry):
class RestrictedRegistry(persisting_theory.Registry):
def validate(self, obj):
"""Only accept integer values"""
return isinstance(obj, int)
......@@ -52,7 +51,7 @@ class RegistryTest(unittest.TestCase):
def test_can_register_class_and_function_via_decorator(self):
registry = registries.Registry()
registry = persisting_theory.Registry()
@registry.register
class ToRegister:
......@@ -67,7 +66,7 @@ class RegistryTest(unittest.TestCase):
self.assertEqual(registry.get('something'), something)
def test_can_register_via_decorator_using_custom_name(self):
registry = registries.Registry()
registry = persisting_theory.Registry()
@registry.register(name="custom_name")
def something():
......@@ -89,11 +88,11 @@ class RegistryTest(unittest.TestCase):
def test_autodiscover_raises_an_error_if_there_is_an_error_in_imported_module(self):
with self.assertRaises(NameError):
registry = test_registries.awesome_people
registry.autodiscover(apps=('buggy_app',))
registry.autodiscover(apps=('tests.buggy_app',))
def test_meta_registry_can_autodiscovering_registries_and_trigger_their_autodiscover_method(self):
registry = registries.meta_registry
registry = persisting_theory.meta_registry
registry.autodiscover(apps=TEST_APPS)
self.assertEqual(len(registry), 2)
......@@ -112,7 +111,7 @@ class RegistryTest(unittest.TestCase):
def test_can_manipulate_data_before_registering(self):
class ModifyData(registries.Registry):
class ModifyData(persisting_theory.Registry):
def prepare_data(self, data):
return "hello " + data
......@@ -126,7 +125,7 @@ class RegistryTest(unittest.TestCase):
def test_can_manipulate_key_before_registering(self):
class ModifyKey(registries.Registry):
class ModifyKey(persisting_theory.Registry):
def prepare_name(self, data, key=None):
return "custom_key " + data.first_name
......@@ -149,7 +148,7 @@ class RegistryTest(unittest.TestCase):
class PostRegisterException(Exception):
pass
class PostRegister(registries.Registry):
class PostRegister(persisting_theory.Registry):
def post_register(self, data, name):
raise PostRegisterException('Post register triggered')
......
[tox]
envlist = py27,py34
skipsdist = True
[testenv]
deps=nose
commands=nosetests
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment