Пример #1
0
 def test_index_view(self):
     #=======================================================================
     #          0    1    2    3    4    5    6    7    8    9    10
     #                        one                           one
     #         two                      two
     #                   three     three          three          three
     # view:             [0    1    2    3    4    5    ]
     #=======================================================================
     self.view = ParameterIndexOperationsView(self.param_index, 2, 6)
     self.assertSetEqual(set(self.view.properties()), set([one, two,
                                                           three]))
     for v, p in zip(self.view.properties_for(np.r_[:6]),
                     self.param_index.properties_for(np.r_[2:2 + 6])):
         self.assertEqual(v, p)
     self.assertSetEqual(set(self.view[two]), set([3]))
     self.assertSetEqual(set(self.param_index[two]), set([0, 5]))
     self.view.add(two, np.array([0]))
     self.assertSetEqual(set(self.view[two]), set([0, 3]))
     self.assertSetEqual(set(self.param_index[two]), set([0, 2, 5]))
     self.view.clear()
     for v, p in zip(self.view.properties_for(np.r_[:6]),
                     self.param_index.properties_for(np.r_[2:2 + 6])):
         self.assertEqual(v, p)
         self.assertEqual(v, [])
     param_index = ParameterIndexOperations()
     param_index.add(one, [3, 9])
     param_index.add(two, [0, 5])
     param_index.add(three, [2, 4, 7, 10])
     view2 = ParameterIndexOperationsView(param_index, 2, 8)
     self.view.update(view2)
     for [i, v], [i2, v2] in zip(sorted(param_index.items()),
                                 sorted(self.param_index.items())):
         self.assertEqual(i, i2)
         np.testing.assert_equal(v, v2)
Пример #2
0
    def test_parameter_index_operations(self):
        pio = ParameterIndexOperations(
            dict(test1=np.array([4, 3, 1, 6, 4]), test2=np.r_[2:130]))
        piov = ParameterIndexOperationsView(pio, 20, 250)
        #py3 fix
        #self.assertListDictEquals(dict(piov.items()), dict(piov.copy().iteritems()))
        self.assertListDictEquals(dict(piov.items()),
                                  dict(piov.copy().items()))

        #py3 fix
        #self.assertListDictEquals(dict(pio.iteritems()), dict(pio.copy().items()))
        self.assertListDictEquals(dict(pio.items()), dict(pio.copy().items()))

        self.assertArrayListEquals(pio.copy().indices(), pio.indices())
        self.assertArrayListEquals(piov.copy().indices(), piov.indices())

        with tempfile.TemporaryFile('w+b') as f:
            pickle.dump(pio, f)
            f.seek(0)
            pio2 = pickle.load(f)
            self.assertListDictEquals(pio._properties, pio2._properties)

        f = tempfile.TemporaryFile('w+b')

        with f:
            pickle.dump(piov, f)
            f.seek(0)
            pio2 = pickle.load(f)
        #py3 fix
        #self.assertListDictEquals(dict(piov.items()), dict(pio2.iteritems()))
        self.assertListDictEquals(dict(piov.items()), dict(pio2.items()))
Пример #3
0
 def test_view_of_view(self):
     #=======================================================================
     #          0    1    2    3    4    5    6    7    8    9    10
     #                        one                           one
     #         two                      two
     #                   three     three          three          three
     # view:             [0    1    2    3    4    5    ]
     # view2:                      [0    1    2    3    4    5    ]
     #=======================================================================
     view2 = ParameterIndexOperationsView(self.view, 2, 6)
     view2.shift_right(0, 2)
Пример #4
0
 def setUp(self):
     self.param_index = ParameterIndexOperations()
     self.param_index.add(one, [3, 9])
     self.param_index.add(two, [0, 5])
     self.param_index.add(three, [2, 4, 7, 10])
     self.view = ParameterIndexOperationsView(self.param_index, 2, 6)