Changeset 1840


Ignore:
Timestamp:
08/12/06 11:53:08 (13 years ago)
Author:
spascoe
Message:

Added a module for extracting the dxs directory structure to NDG_HOME.

Test suite still doesn't work automatically because of import ordering
problems. I'm going to try to fix this by moving imports out of
ndg.dx.server.init.

Location:
TI03-DataExtractor/branches/repackaging/server
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • TI03-DataExtractor/branches/repackaging/server/lib/ndg/dx/server/test/__init__.py

    r1817 r1840  
    55""" 
    66 
    7 import unittest, os, pkg_resources, tempfile, shutil 
    8 from ndg.utils.config import config 
     7import sys, os, pkg_resources, tempfile, shutil 
     8import unittest 
     9 
     10from ndg.dx.server.MakeConfig import makeConfig 
    911 
    1012class TestCase(unittest.TestCase): 
     13    """ 
     14    These tests assume you have a NDG_HOME directory pre-configured. 
     15    """ 
     16 
    1117    def setUp(self): 
    12         # Add the test configuration file 
    13         configStream = pkg_resources.resource_stream('ndg.dx.server.test', 'server.conf') 
    14         config.readfp(configStream) 
    15  
    16         # Get the dxs configuration directory 
    17         dxsPath = pkg_resources.resource_filename('ndg.dx.server', 'dxs') 
    18  
    19         # Create a temporary basedir 
    20         self.tempdir = tempfile.mkdtemp() 
    21  
    22         # Copy dxs to tempdir to preserve state. 
    23         basedir = os.path.join(self.tempdir, 'dxs') 
    24         print 'Copying %s to %s' % (dxsPath, basedir) 
    25         shutil.copytree(dxsPath, basedir) 
    26  
    27         # Set BASEDIR 
    28         config.set('ndg.dx.server', 'BASEDIR', basedir) 
    29  
     18        # Create the NDG_HOME/dxs directory if it doesn't exist  
     19        makeConfig() 
    3020 
    3121    def testStartSession(self): 
    32         from ndg.dx.server.scripts import DXWSInterface 
    33  
    34         from ndg.utils.config import config 
    35         print 'BASEDIR = %s' % config.get('ndg.dx.server', 'BASEDIR') 
    36         print 'SESSION_OBJECT_DIR = %s' % config.get('ndg.dx.server', 'SESSION_OBJECT_DIR') 
    37         print 'INPUT_DATASETS_FILE = %s' % config.get('ndg.dx.server', 'INPUT_DATASETS_FILE') 
    38      
    39  
     22        from ndg.dx.server.scripts import DXWSInterface     
    4023        print DXWSInterface.startSession('rob', 'rob1') 
    41  
    42     def tearDown(self): 
    43         shutil.rmtree(self.tempdir) 
    44  
    4524 
    4625test_suite = unittest.TestSuite() 
  • TI03-DataExtractor/branches/repackaging/server/setup.py

    r1817 r1840  
    88 
    99from setuptools import setup, find_packages 
     10 
     11# 'python setup.py test' imports modules in the package before it runs the test_suite 
     12# This screws up any attempt to set NDG_HOME and put a suitable ndg.conf in it for testing. 
     13# I'm hoping this will solve the problem. 
     14from setuptools.command.test import test 
     15class ndgTest(test): 
     16    description = "create a temporary NDG environment before testing" 
     17 
     18    user_options = [ 
     19        ('test-home', 'h', "directory to create the NDG environment"), 
     20        ('test-conf', 'c', "configuration file to base NDG_HOME/ndg.conf on" 
     21                          " (default: egg:ndg.dx.server.test.server.conf)"), 
     22        ] + test.user_options 
     23 
     24    def initialize_options(self): 
     25        test.initialize_options(self) 
     26        self.test_home = None 
     27        self.test_conf = None 
     28 
     29    def finalize_options(self): 
     30        test.initialize_options(self) 
     31        if not self.test_home: 
     32            self.test_home = './test_ndg_home' 
     33 
     34    def run(self): 
     35        import os, pkg_resources, shutil, ConfigParser 
     36 
     37        # Wipe clean self.test_home 
     38        if os.path.exists(self.test_home): 
     39            shutil.rmtree(self.test_home) 
     40            os.mkdir(self.test_home) 
     41        # Set NDG_HOME to be picked up by ndg.utils.config 
     42        os.environ['NDG_HOME'] = self.test_home 
     43 
     44        # get global configuration (this will read /etc/ndg.conf) 
     45        from ndg.utils.config import config 
     46        from ndg.dx.server.MakeConfig import makeConfig 
     47 
     48        # parse selected test_conf 
     49        if self.test_conf: 
     50            config.read(self.test_conf) 
     51        else: 
     52            fp = pkg_resources.resource_stream('ndg.dx.server.test', 'server.conf') 
     53            config.readfp(fp) 
     54             
     55        # Set BASEDIR and create the dxs directory 
     56        config.set('ndg.dx.server', 'basedir', os.path.join(self.test_home, 'dxs')) 
     57        makeConfig() 
     58 
     59        # Run the tests 
     60        return test.run(self) 
    1061 
    1162setup( 
     
    4192 
    4293    test_suite = 'ndg.dx.server.test.test_suite', 
     94    cmdclass = {'test': ndgTest}, 
    4395    ) 
    4496     
Note: See TracChangeset for help on using the changeset viewer.