Changeset 329

Show
Ignore:
Timestamp:
11/13/08 11:09:04 (2 months ago)
Author:
apdavison
Message:

Added unit tests for datastore module

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/datastore/__init__.py

    r298 r329  
    11""" 
     2NeuroTools.datastore 
     3==================== 
     4 
    25The `datastore` package aims to present a consistent interface for persistent 
    36data storage, irrespective of storage back-end. 
     
    2124  `full_type`: the object class and module 
    2225  `version`: the source-code version 
     26   
     27Classes 
     28------- 
     29 
     30ShelveDataStore    - Persistent data store based on the `shelve` module and the 
     31                     filesystem. 
     32DjangoORMDataStore - Persistent data store using the Django ORM 
     33                     (object-relational mapping - an object-oriented interface 
     34                     to an SQL database) to store/retrieve keys/indices 
     35                     with data stored using `pickle` on the filesystem. 
     36   
    2337""" 
    2438 
  • trunk/src/datastore/django_orm/__init__.py

    r213 r329  
    33""" 
    44 
    5 from datastore.interface import AbstractDataStore 
     5from NeuroTools.datastore.interface import AbstractDataStore 
    66from django.conf import settings 
    77 
     
    1818        self.root_dir = data_root_dir 
    1919        settings.configure(USE_I18N=False, 
    20                            INSTALLED_APPS=('datastore.django_orm',), 
     20                           INSTALLED_APPS=('NeuroTools.datastore.django_orm',), 
    2121                           **database_parameters) 
    2222        DJANGO_CONFIGURED = True 
    2323        from django.core.management import call_command  
    2424        call_command('syncdb')  
    25              
     25     
     26    def __del__(self): 
     27        global DJANGO_CONFIGURED 
     28        DJANGO_CONFIGURED = False 
    2629     
    2730    def retrieve(self, component, attribute_name): 
  • trunk/src/datastore/django_orm/models.py

    r213 r329  
    2626        """ 
    2727        state = {'type': str(self.type), 
    28                  'parameters_uri': self.parameters_uri} 
     28                 'parameters_uri': str(self.parameters_uri)} # convert from unicode 
    2929        if self.input is None: 
    3030            state['input'] = 'None' 
     
    3333        return hashlib.sha1(pickle.dumps(state)).hexdigest() 
    3434 
     35    def __unicode__(self): 
     36        return '<ComponentState: type=%s, uri=%s, input=%s>' % (str(self.type), 
     37                                                                self.parameters_uri, 
     38                                                                self.input and self.input.global_id() or 'None') 
    3539 
    3640class DataItem(models.Model): 
     
    4246        path = os.path.join(root_dir, cs.global_id() + ".dj") 
    4347        if not (os.path.exists(path) and os.path.isdir(path)): 
    44             os.mkdir(path) 
     48            os.makedirs(path) 
    4549        filename = os.path.join(path, self.attribute_name) 
    4650        return filename 
  • trunk/src/datastore/shelve_ds.py

    r298 r329  
    33""" 
    44 
    5 from datastore.interface import AbstractDataStore 
    6 from datastore.keygenerators import join_with_underscores 
     5from NeuroTools.datastore.interface import AbstractDataStore 
     6from NeuroTools.datastore.keygenerators import join_with_underscores 
    77import os.path, shelve 
    8  
     8import logging 
    99 
    1010class ShelveDataStore(AbstractDataStore):