Commits

ajung committed 968e08c

enhanced resources_registry API

  • Participants
  • Parent commits 00e127e

Comments (0)

Files changed (4)

File docs/source/CHANGES.rst

 CHANGES
 =======
 
+0.2.0 (unreleased)
+------------------
+
+- enhanced resources_registry API 
+
 0.1.0 (11.07.2013)
 ------------------
 

File pp/core/resources_registry.py

 from pp.core.resource import Resource
 
 # mapping name -> directory
-resources_registry = dict()
+_resources_registry = dict()
 
 def registerResource(name, directory):
     if not os.path.exists(directory):
         raise IOError('Directory "{0:2}" does not exit'.format(directory))
-    if name in resources_registry:
+    if name in _resources_registry:
         raise KeyError('A resource "{0:2}" is already registered'.format(name))
-    resources_registry[name] = Resource(OSFS(directory))
+    _resources_registry[name] = Resource(OSFS(directory))
     LOG.info('Registered resource directory "{0:2}" as "{0:2}"'.format(directory, name))
+
+def getResource(resource):
+    return _resources_registry[resource]
+
+def getResourceNames():
+    return _resources_registry.keys()
+

File pp/core/tests/test_resources_registry.py

 ################################################################
 
 import tempfile
-from pp.core.resources_registry import resources_registry
+from pp.core.resources_registry import _resources_registry
 from pp.core.resources_registry import registerResource
+from pp.core.resources_registry import getResource
+from pp.core.resources_registry import getResourceNames
+
 import pytest
 
 def test_empty():
-    assert len(resources_registry) == 0
+    assert len(getResourceNames()) == 0
+    with pytest.raises(KeyError):
+        getResource('foo')
 
 def test_insert():
-    resources_registry.clear()
+    _resources_registry.clear()
     registerResource('foo', tempfile.gettempdir())
+    resource = getResource('foo')
+    assert getResourceNames() == ['foo']
 
 def test_insert_twice():
-    resources_registry.clear()
+    _resources_registry.clear()
     registerResource('foo', tempfile.gettempdir())
     with pytest.raises(KeyError):
         registerResource('foo', tempfile.gettempdir())
 ]
 
 setup(name='pp.core',
-      version='0.1.3',
+      version='0.2.0',
       description='pp.core',
       long_description=README + '\n\n' + CHANGES,
       classifiers=[