Show
Ignore:
Timestamp:
02/16/10 10:59:22 (2 years ago)
Author:
apdavison
Message:

Moved Error classes out of common into an errors module (see ticket:157)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/test/unittests/generictests.py

    r702 r711  
    99import os 
    1010import cPickle as pickle 
    11 from pyNN import common, random, utility, recording 
     11from pyNN import common, random, utility, recording, errors 
    1212import glob 
    1313 
     
    6666        """create(): Trying to create a cell type which is not a standard cell or 
    6767        valid native cell should raise an Exception.""" 
    68         self.assertRaises(common.InvalidModelError, sim.create, 'qwerty', n=10) 
     68        self.assertRaises(errors.InvalidModelError, sim.create, 'qwerty', n=10) 
    6969     
    7070    def testCreateWithInvalidParameter(self): 
    7171        """create(): Creating a cell with an invalid parameter should raise an Exception.""" 
    72         self.assertRaises(common.NonExistentParameterError, sim.create, sim.IF_curr_alpha, {'tau_foo':3.141592654})   
     72        self.assertRaises(errors.NonExistentParameterError, sim.create, sim.IF_curr_alpha, {'tau_foo':3.141592654})   
    7373 
    7474# ============================================================================== 
     
    136136        """connect(): Connecting from non-existent cell should raise a ConnectionError.""" 
    137137        if self.postcells[0].local: 
    138             self.assertRaises(common.ConnectionError, sim.connect, 12345, self.postcells[0]) 
     138            self.assertRaises(errors.ConnectionError, sim.connect, 12345, self.postcells[0]) 
    139139         
    140140    def testConnectNonExistentPostCell(self): 
    141141        """connect(): Connecting to a non-existent cell should raise a ConnectionError.""" 
    142         self.assertRaises(common.ConnectionError, sim.connect, self.precells[0], 'cell45678') 
     142        self.assertRaises(errors.ConnectionError, sim.connect, self.precells[0], 'cell45678') 
    143143     
    144144    def testInvalidSourceId(self): 
    145145        """connect(): sources must be integers.""" 
    146146        self.precells.append('74367598') 
    147         self.assertRaises(common.ConnectionError, sim.connect, self.precells, self.postcells) 
     147        self.assertRaises(errors.ConnectionError, sim.connect, self.precells, self.postcells) 
    148148     
    149149    def testInvalidTargetId(self): 
    150150        """connect(): targets must be integers.""" 
    151151        self.postcells.append('99.9') 
    152         self.assertRaises(common.ConnectionError, sim.connect, self.precells, self.postcells) 
     152        self.assertRaises(errors.ConnectionError, sim.connect, self.precells, self.postcells) 
    153153     
    154154    def testConnectTooSmallDelay(self): 
    155         self.assertRaises(common.ConnectionError, sim.connect, self.precells[0], self.postcells[0], delay=1e-12) 
     155        self.assertRaises(errors.ConnectionError, sim.connect, self.precells[0], self.postcells[0], delay=1e-12) 
    156156 
    157157# ============================================================================== 
     
    295295            try: 
    296296                self.assertAlmostEqual(cell.tau_m, 35.7, 5) 
    297             except common.NotLocalError: # if cell is not on this node 
     297            except errors.NotLocalError: # if cell is not on this node 
    298298                pass 
    299299        if self.single_cell.local: 
     
    306306                self.assertAlmostEqual(cell.tau_syn_E, 5.432, 6) 
    307307                self.assertAlmostEqual(cell.tau_m, 35.7, 5) 
    308             except common.NotLocalError: # if cell is not on this node 
     308            except errors.NotLocalError: # if cell is not on this node 
    309309                pass 
    310310             
     
    312312        # note that although syn_shape is added to the NEURON parameter dict when creating 
    313313        # an IF_curr_exp, it is not a valid parameter to be changed later. 
    314         self.assertRaises(common.NonExistentParameterError, sim.set, self.cells, 'syn_shape', 'alpha') 
     314        self.assertRaises(errors.NonExistentParameterError, sim.set, self.cells, 'syn_shape', 'alpha') 
    315315     
    316316# ============================================================================== 
     
    340340     
    341341    def testInvalidCellType(self): 
    342         self.assertRaises(common.InvalidModelError, sim.Population, (3,3), 'qwerty', {}) 
     342        self.assertRaises(errors.InvalidModelError, sim.Population, (3,3), 'qwerty', {}) 
    343343         
    344344# ============================================================================== 
     
    377377         
    378378    def testInvalidIndexDimension(self): 
    379         self.assertRaises(common.InvalidDimensionsError, self.net1.__getitem__, (10,2)) 
     379        self.assertRaises(errors.InvalidDimensionsError, self.net1.__getitem__, (10,2)) 
    380380         
    381381# ============================================================================== 
     
    475475                 
    476476    def test_set_invalid_type(self): 
    477         self.assertRaises(common.InvalidParameterValueError, self.p1.set, 'foo', {}) 
    478         self.assertRaises(common.InvalidParameterValueError, self.p1.set, [1,2,3]) 
     477        self.assertRaises(errors.InvalidParameterValueError, self.p1.set, 'foo', {}) 
     478        self.assertRaises(errors.InvalidParameterValueError, self.p1.set, [1,2,3]) 
    479479                 
    480480    def testSetInvalidFromDict(self): 
    481         self.assertRaises(common.InvalidParameterValueError, self.p1.set, {'v_thresh':'hello','tau_m':56.78}) 
     481        self.assertRaises(errors.InvalidParameterValueError, self.p1.set, {'v_thresh':'hello','tau_m':56.78}) 
    482482             
    483483    def testSetNonexistentFromPair(self): 
    484484        """Population.set(): Trying to set a nonexistent parameter should raise an exception.""" 
    485         self.assertRaises(common.NonExistentParameterError, self.p1.set, 'tau_foo', 10.0) 
     485        self.assertRaises(errors.NonExistentParameterError, self.p1.set, 'tau_foo', 10.0) 
    486486     
    487487    def testSetNonexistentFromDict(self): 
    488488        """Population.set(): When some of the parameters in a dict are inexistent, an exception should be raised. 
    489489           There is no guarantee that the existing parameters will be set.""" 
    490         self.assertRaises(common.NonExistentParameterError, self.p1.set, {'tau_foo': 10.0, 'tau_m': 21.0}) 
     490        self.assertRaises(errors.NonExistentParameterError, self.p1.set, {'tau_foo': 10.0, 'tau_m': 21.0}) 
    491491             
    492492    def testRandomInit(self): 
     
    516516        """Population.tset(): If the size of the valueArray does not match that of the Population, should raise an InvalidDimensionsError.""" 
    517517        array_in = numpy.array([[0.1,0.2,0.3],[0.4,0.5,0.6]]) 
    518         self.assertRaises(common.InvalidDimensionsError, self.p1.tset, 'i_offset', array_in) 
     518        self.assertRaises(errors.InvalidDimensionsError, self.p1.tset, 'i_offset', array_in) 
    519519     
    520520    def testTSetInvalidValues(self): 
    521521        """Population.tset(): If some of the values in the valueArray are invalid, should raise an exception.""" 
    522522        array_in = numpy.array([['potatoes','carrots'],['oranges','bananas']]) 
    523         self.assertRaises(common.InvalidParameterValueError, self.p2.tset, 'spike_times', array_in) 
     523        self.assertRaises(errors.InvalidParameterValueError, self.p2.tset, 'spike_times', array_in) 
    524524         
    525525    def testRSetNumpy(self): 
     
    648648    def testSynapticConductanceRecording(self): 
    649649        # current-based synapses 
    650         self.assertRaises(common.RecordingError, self.pop2.record_gsyn) 
     650        self.assertRaises(errors.RecordingError, self.pop2.record_gsyn) 
    651651        # conductance-based synapses 
    652652        cells_to_record = [self.pop3[1,0], self.pop3[2,2]] 
     
    674674 
    675675    def testRecordVmFromSpikeSource(self): 
    676         self.assertRaises(common.RecordingError, self.pop1.record_v) 
     676        self.assertRaises(errors.RecordingError, self.pop1.record_v) 
    677677         
    678678     
     
    896896            result = 2.345*numpy.ones(len(prj.connections)) 
    897897            assert_arrays_almost_equal(numpy.array(weights), result, 1e-7, msg=prj.label) 
    898         self.assertRaises(common.InvalidWeightError, prj2.setWeights, 2.345) # current-based inhibitory needs negative weights 
     898        self.assertRaises(errors.InvalidWeightError, prj2.setWeights, 2.345) # current-based inhibitory needs negative weights 
    899899             
    900900    def testSetNegativeWeights(self): 
     
    910910        assert_arrays_almost_equal(numpy.array(weights), result, 1e-7) 
    911911        for prj in prj1, prj3, prj4: 
    912             self.assertRaises(common.InvalidWeightError, prj.setWeights, -2.345)  
     912            self.assertRaises(errors.InvalidWeightError, prj.setWeights, -2.345)  
    913913     
    914914    def test_set_weights_with_array(self):