Package paramz :: Package tests :: Module lists_and_dicts_tests
[hide private]
[frames] | no frames]

Source Code for Module paramz.tests.lists_and_dicts_tests

  1  ''' 
  2  Copyright (c) 2015, Max Zwiessele 
  3  All rights reserved. 
  4   
  5  Redistribution and use in source and binary forms, with or without 
  6  modification, are permitted provided that the following conditions are met: 
  7   
  8  * Redistributions of source code must retain the above copyright notice, this 
  9    list of conditions and the following disclaimer. 
 10   
 11  * Redistributions in binary form must reproduce the above copyright notice, 
 12    this list of conditions and the following disclaimer in the documentation 
 13    and/or other materials provided with the distribution. 
 14   
 15  * Neither the name of paramz nor the names of its 
 16    contributors may be used to endorse or promote products derived from 
 17    this software without specific prior written permission. 
 18   
 19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 20  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 21  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 22  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
 23  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
 24  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
 25  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 26  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
 27  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 29  ''' 
 30  import unittest, numpy as np 
 31  from ..core.lists_and_dicts import ArrayList, IntArrayDict, ObserverList 
 32  from ..core.observable_array import ObsAr 
 33  from ..parameterized import Parameterized 
 34           
35 -class Test(unittest.TestCase):
36 37
38 - def setUp(self):
39 40 pass
41 42
43 - def tearDown(self):
44 pass
45 46
47 - def testArrayList(self):
48 t = [] 49 a = ArrayList() 50 for r in range(3,6): 51 _ = np.random.normal(0,1,r) 52 a.append(_) 53 t.append(_) 54 r = np.random.normal() 55 self.assertRaises(ValueError, t.__contains__, r) 56 self.assertFalse(a.__contains__(r)) 57 self.assertRaises(ValueError, t.index, r) 58 self.assertRaises(ValueError, a.index, r) 59 60 r = a[2] 61 self.assertTrue(a.__contains__(r)) 62 self.assertEqual(a.index(r), 2)
63
65 o = ObserverList() 66 test1 = ObsAr(np.array([1])) 67 o.add(1, test1, None) 68 #tstr = ("; to 'ObsAr' at " + hex(id(test1)) + ">, None)]") 69 #self.assertSequenceEqual(repr(o)[-len(tstr):], tstr) 70 #tstr = '[(1, <weakref at ' 71 #self.assertSequenceEqual(repr(o)[:len(tstr)], tstr) 72 print(o)
73
75 o = ObserverList() 76 test2 = Parameterized() 77 o.add(1, test2, None) 78 print(o) 79 class O(object): 80 pass
81 test3 = O() 82 o.add(3, test3, None) 83 print(o)
84
85 - def testPrintObserverListObj(self):
86 o = ObserverList() 87 class O(object): 88 pass
89 test3 = O() 90 o.add(3, test3, None) 91 print(o) 92
93 - def testPrintPriority(self):
94 o = ObserverList() 95 class O(object): 96 pass
97 t = [O() for _ in range(4)] 98 o.add(5, t[0], None) 99 o.add(3, t[1], None) 100 o.add(3, t[2], None) 101 o.add(2, t[3], None) 102 print(o) 103 104 if __name__ == "__main__": 105 #import sys;sys.argv = ['', 'Test.testName'] 106 unittest.main() 107