예제 #1
0
 def test_expand_list_of_dicts(self):
     s = Store()
     key_a = s.new('a', components=['x', 'y'])
     dct = [{'index': 0, 'dependent': {key_a: [0, 1]}}]
     out = variable.expand(dct, s)
     expected = [{'index': 0, 'dependent': {'a - x': 0, 'a - y': 1}}]
     self.assertListEqual(out, expected)
예제 #2
0
 def test_expand_nested(self):
     s = Store()
     key_a = s.new('a', components=['x', 'y'])
     dct = {'dependent': {'another_level': {key_a: [0, 1]}}}
     out = variable.expand(dct, s)
     expected = {'dependent': {'another_level': {'a - x': 0, 'a - y': 1}}}
     self.assertDictEqual(out, expected)
예제 #3
0
 def test_expand_basic(self):
     s = Store()
     key_a = s.new('a', components=['x', 'y'])
     dct = {key_a: [0, 1]}
     out = variable.expand(dct, s)
     expected = {'a - x': 0, 'a - y': 1}
     self.assertDictEqual(out, expected)
예제 #4
0
 def test_new(self):
     s = Store()
     name = 'a'
     doc = 'b'
     unit = 'c'
     v = s.new(name, doc, unit)
     v_check = Variable(name, doc, unit)
     self.assertEqual(str(v_check), str(v))
     self.assertTrue(v in s)
     self.assertEqual(str(s[v]), str(v))
예제 #5
0
 def test_nearest(self):
     s = Store()
     s.new('dummy')
     s.new('the one we want')
     s.new('irrelevant')
     v = s.nearest('one we wnt')
     self.assertEqual(v.name, 'the one we want')
예제 #6
0
    def test_tabulate_store2(self):
        # TODO: FIX
        t = Tabulator()
        box = Box(get_lst2_b())
        store = Store()
        d = store.new('d', components=['x', 'y'])
        index = d.label
        columns = ['a', 'b']
        values = d
        pt = t.tabulate(box=box,
                        values=values,
                        columns=columns,
                        index=index,
                        store=store)
        expected = '''a    1       2    
b    1   2   1   2
d:                
x   12  13  16  19
y   30  31  34  37'''
        self.assertEqual(str(pt), expected)
예제 #7
0
    def test_tabulate_store(self):
        t = Tabulator()
        box = Box(get_lst2_b())
        store = Store()
        d = store.new('d', components=['x', 'y'])
        index = ['a', 'b']
        columns = d.label
        values = d
        pt = t.tabulate(box=box,
                        values=values,
                        columns=columns,
                        index=index,
                        store=store)
        expected = '''d:    x   y
a b        
1 1  12  30
  2  13  31
2 1  16  34
  2  19  37'''
        self.assertEqual(str(pt), expected)
예제 #8
0
    def test_tabulate_store_nested_cols(self):
        t = Tabulator()
        box = Box(get_lst2_c())
        store = Store()
        d = store.new('d', components=['x', 'y'])
        index = ['a', 'b']
        columns = ['c', d.label]
        values = d
        pt = t.tabulate(box=box,
                        values=values,
                        columns=columns,
                        index=index,
                        store=store)
        expected = '''c     1       2    
d:    x   y   x   y
a b                
1 1  11  21  14  24
  2  13  23  12  22
2 1  15  25  16  26
  2  17  27  18  28'''
        self.assertEqual(str(pt), expected)
예제 #9
0
    def test_tabulate_store_units(self):
        t = Tabulator()
        store = Store()
        d = store.new('d', unit='mm', components=['x', 'y'])
        aliases = Aliases({'d': d})
        translated = aliases.translate(get_lst2_b())
        box = Box(translated)
        index = ['a', 'b']
        columns = d.label
        values = d
        pt = t.tabulate(box=box,
                        values=values,
                        columns=columns,
                        index=index,
                        store=store)
        expected = '''d:   x [mm]  y [mm]
a b                
1 1      12      30
  2      13      31
2 1      16      34
  2      19      37'''
        self.assertEqual(str(pt), expected)