def test_is_valid_key2(self):
     """test that a duplicate key is invalid"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types)
     self.assertFalse(model.is_valid_key(('a', 'aa', 1),
                                         model._row_data_header_set,
                                         ('test1', 'test2', 'test3')))
 def test_is_valid_key3(self):
     """test that akey with invalid type is invalid"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types)
     self.assertFalse(model.is_valid_key(('a', 'aa', 'invalid_type'),
                                         model._row_data_header_set,
                                         ('test1', 'test2', 'test3')))
 def test_get_unique_index_values2(self):
     """test that _get_unique_index_values returns unique values for specified indexes with filter index and value"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types)
     index_set = set([('d', 'dd'), ('e', 'ee')])
     index_header_values = model._get_unique_index_values(('test1','test2'), ('test3',), (5,))
     self.assertEqual(index_header_values, index_set)
 def test_add_index_value2(self):
     """test that adding an existing doesn't do anything"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types)
     result = model._add_index_value('a', 'test1')
     self.assertTrue(result)
     self.assertEqual(model._added_index_entries['test1'], set())
 def test_add_index_value3(self):
     """test that adding a new index with name already taken doesn't work"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types, used_index_values = {('test1',): set(['used_value'])})
     result = model._add_index_value('used_value', 'test1')
     self.assertFalse(result)
     self.assertEqual(model._added_index_entries['test1'], set())
 def test_set_data3(self):
     """Test set data with pivot and tuple_index_entries"""
     column_headers = [('a', 'aa', 1),
                    ('a', 'bb', 2),
                    ('b', 'cc', 3),
                    ('c', 'cc', 4),
                    ('d', 'dd', 5),
                    ('e', 'ee', 5),
                    ('a', 'cc', None),
                    ('f', 'ee', None),
                    (None, None, 6)]
     row_headers = []
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types, rows=(), columns=tuple(self.index_names), tuple_index_entries=self.tuple_index_entries)
     self.assertEqual(model._data, self.dict_data)
     self.assertEqual(model.index_names, tuple(self.index_names))
     self.assertEqual(model.pivot_rows, ())
     self.assertEqual(model.pivot_columns, tuple(self.index_names))
     self.assertEqual(model.pivot_frozen, ())
     self.assertEqual(model.frozen_value, ())
     self.assertEqual(model._row_data_header, row_headers)
     self.assertEqual(model._column_data_header, column_headers)
     self.assertEqual(model._row_data_header_set, set(r for r in row_headers if all(r)))
     self.assertEqual(model._column_data_header_set, set(r for r in column_headers if all(r)))
     self.assertEqual(model._invalid_column, set([6,7,8]))
 def test_add_index_value1(self):
     """test that adding a new index value works"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types, used_index_values = {('test1',): set()})
     result = model._add_index_value('new_index', 'test1')
     self.assertTrue(result)
     self.assertEqual(model._added_index_entries['test1'], set(['new_index']))
     self.assertEqual(model._used_index_values[('test1',)], set(['new_index']))
 def test_get_unique_index_values1(self):
     """test that _get_unique_index_values returns unique values for specified indexes"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types)
     index_set = set([('a', 'aa'), ('a', 'bb'), ('b', 'cc'),
                      ('c', 'cc'), ('d', 'dd'), ('e', 'ee')])
     index_header_values = model._get_unique_index_values(('test1','test2'), (), ())
     self.assertEqual(index_header_values, index_set)
 def test_add_index_value5(self):
     """test that adding a to two different indexes with same real name"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types, index_real_names = ['real','real','test3'])
     result1 = model._add_index_value('new_val1', 'test1')
     result2 = model._add_index_value('new_val2', 'test2')
     self.assertTrue(result1)
     self.assertTrue(result2)
     self.assertEqual(model._added_index_entries['real'], set(['new_val1','new_val2']))
Esempio n. 10
0
 def test_index_entries_without_data3(self):
     """test _index_entries_without_data with tuple_index_entries and a frozen index wich is not in tuple_index_entries"""
     model = PivotModel()
     row_headers = set([(1,),
                        (2,)])
     new_keys, new_none_keys, new_entries = model._index_entries_without_data(('test3',), row_headers, ('test1',), ('a',), self.tuple_index_entries)
     self.assertEqual(new_keys, set([(6,)]))
     self.assertEqual(new_none_keys, set())
     self.assertEqual(new_entries, {'test3': set([6])})
Esempio n. 11
0
 def test_index_entries_without_data2(self):
     """test _index_entries_without_data with tuple_index_entries and a frozen index"""
     model = PivotModel()
     row_headers = set([('aa', 1),
                        ('bb', 2)])
     new_keys, new_none_keys, new_entries = model._index_entries_without_data(('test2','test3'), row_headers, ('test1',), ('a',), self.tuple_index_entries)
     self.assertEqual(new_keys, set())
     self.assertEqual(new_none_keys, set([('cc',None), (None, 6)]))
     self.assertEqual(new_entries, {'test2': set(['cc']), 'test3': set([6])})
Esempio n. 12
0
 def test_index_entries_without_data4(self):
     """test _index_entries_without_data with tuple_index_entries with no new keys"""
     model = PivotModel()
     row_headers = set([('a', 'cc'),
                        ('f', 'ee'),
                        ('a', 'aa')])
     new_keys, new_none_keys, new_entries = model._index_entries_without_data(('test1','test2'), row_headers, (), (), self.tuple_index_entries)
     self.assertEqual(new_keys, set())
     self.assertEqual(new_none_keys, set())
     self.assertEqual(new_entries, {'test1': set(), 'test2': set()})
Esempio n. 13
0
 def test_index_entries_without_data1(self):
     """test _index_entries_without_data with tuple_index_entries"""
     model = PivotModel()
     row_headers = set([('a', 'aa', 1),
                        ('a', 'bb', 2),
                        ('e', 'ee', 3)])
     new_keys, new_none_keys, new_entries = model._index_entries_without_data(('test1','test2', 'test3'), row_headers, (), (), self.tuple_index_entries)
     self.assertEqual(new_keys, set())
     self.assertEqual(new_none_keys, set([('a','cc',None),('f','ee', None), (None, None, 6)]))
     self.assertEqual(new_entries, {'test2': set(['cc','ee']),'test1': set(['a','f']), 'test3': set([6])})
Esempio n. 14
0
 def test_add_index_value4(self):
     """test that adding a new index with name already taken doesn't work for multiple shared values"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types, used_index_values = {('test1', 'test2'): set()})
     result1 = model._add_index_value('used_value', 'test1')
     result2 = model._add_index_value('used_value', 'test2')
     self.assertTrue(result1)
     self.assertFalse(result2)
     self.assertEqual(model._added_index_entries['test1'], set(['used_value']))
     self.assertEqual(model._added_index_entries['test2'], set())
Esempio n. 15
0
 def test_is_valid_key1(self):
     """test that a correct key is valid"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types)
     model._add_index_value('valid1','test1')
     model._add_index_value('valid2','test2')
     model._add_index_value(4,'test3')
     self.assertTrue(model.is_valid_key(('valid1', 'valid2', 4),
                                         model._row_data_header_set,
                                         ('test1', 'test2', 'test3')))
Esempio n. 16
0
 def test_delete_entries_with_wrong_index(self):
     """Test that deleting an entrie with wrong index doesn't delete from used_index_values"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types, used_index_values = {('test1', 'test2'): set(['wrong_index'])})
     model._add_index_value('wrong_index','test1')
     model.delete_index_values({'test2': set(['wrong_index'])})
     self.assertEqual(model._used_index_values, {('test1', 'test2'): set(['wrong_index'])})
Esempio n. 17
0
 def test_delete_tuple_index_values_with_frozen_pivot1(self):
     """test that delete_tuple_index_values deletes data when pivot has frozen dimension"""
     model = PivotModel()
     tuple_entries = {('test1','test2'):set()}
     model.set_new_data(self.data, self.index_names, self.index_types, tuple_index_entries=tuple_entries)
     model.set_pivot(['test1','test3'], [], ['test2'], ('aa',))
     model.delete_tuple_index_values({('test1', 'test2'): set([('a','aa')])})
     self.assertEqual(model._row_data_header, [])
Esempio n. 18
0
 def test_delete_then_add_value(self):
     """test that deleting a value and then adding it back tracks in _deleted_data and _edited_data"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types, rows=(), columns=tuple(self.index_names))
     model.set_pivoted_data([['']],[0],[0])
     model.set_pivoted_data([['edited_val']],[0],[0])
     self.assertEqual(model._deleted_data, {})
     self.assertEqual(model._edit_data, {('a','aa',1): 'value_a_aa_1'})
Esempio n. 19
0
 def test_edit_value_edit_back(self):
     """test that edit a value and editing it to original value to make sure it's not in _edit_value"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types)
     model.set_pivoted_data([['new_data']],[0],[0])
     model.set_pivoted_data([['value_a_aa_1']],[0],[0])
     self.assertEqual(model._deleted_data, {})
     self.assertEqual(model._edit_data, {})
Esempio n. 20
0
 def test_delete_tuple_index_values_with_frozen_pivot4(self):
     """test that delete_tuple_index_values doesn't delete data when pivot has frozen dimension when frozen value doesn't match delete value, column"""
     model = PivotModel()
     tuple_entries = {('test1','test2'):set()}
     model.set_new_data(self.data, self.index_names, self.index_types, tuple_index_entries=tuple_entries)
     model.set_pivot([], ['test1','test3'], ['test2'], ('aa',))
     model.delete_tuple_index_values({('test1', 'test2'): set([('a','bb')])})
     self.assertEqual(model._column_data_header, [('a',1),('a',None)])
Esempio n. 21
0
 def test_add_new_value_then_delete(self):
     """test that adding a value and then deleteing it tracks in _deleted_data and _edited_data"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types, rows=('test1','test3'), columns=('test2',))
     model.set_pivoted_data([['new_data']],[0],[1])
     model.set_pivoted_data([['']],[0],[1])
     self.assertEqual(model._deleted_data, {})
     self.assertEqual(model._edit_data, {})
Esempio n. 22
0
 def test_restore_added_value(self):
     """test that restoring a added data works"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types)
     model._add_data(('new_key','aa',1),'new value')
     model._restore_data(('new_key','aa',1))
     self.assertEqual(model._deleted_data, {})
     self.assertEqual(model._edit_data, {})
     self.assertFalse(('new_key','aa',1) in model._data)
Esempio n. 23
0
 def test_restore_deleted_value(self):
     """test that restoring a deleted value works"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types)
     model._delete_data(('a','aa',1))
     model._restore_data(('a','aa',1))
     self.assertEqual(model._deleted_data, {})
     self.assertEqual(model._edit_data, {})
     self.assertEqual(model._data[('a','aa',1)], 'value_a_aa_1')
Esempio n. 24
0
 def test_delete_index_values6(self):
     """test deleting index values deletes them from _added_index_entries"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types)
     model._added_index_entries['test1'] = set(['a','b','c'])
     model.delete_index_values({'test1': set(['a'])})
     self.assertEqual(model._added_index_entries['test1'], set(['b','c']))
Esempio n. 25
0
 def test_delete_tuple_index_values6(self):
     """test deleting tuple index values also deletes added tuple index entries"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types, tuple_index_entries=self.tuple_index_entries)
     model._added_tuple_index_entries[('test1', 'test2')] = set([('a', 'aa'), ('a', 'cc')])
     model.delete_tuple_index_values({('test1', 'test2'): set([('a','aa')])})
     self.assertEqual(model._added_tuple_index_entries[('test1', 'test2')], set([('a', 'cc')]))
Esempio n. 26
0
 def test_paste_values1(self):
     """test pasting data into data only"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types)
     model.set_pivot(['test1','test2'], ['test3'], [], ())
     data = [['paste1', 'paste2', None, None, None],
             ['paste3', 'paste4', None, None, None],
             [None, None, 'value_b_cc_3', None, None],
             [None, None, None, 'value_c_cc_4', None],
             [None, None, None, None, 'value_d_dd_5'],
             [None, None, None, None, 'value_e_ee_5']]
     model.paste_data(data=[['paste1', 'paste2'],['paste3', 'paste4']], row_mask=[0, 1], col_mask=[0, 1])
     data_model = [[d for d in inner] for inner in model.get_pivoted_data(range(6),range(5))]
     self.assertEqual(data_model, data)
Esempio n. 27
0
 def test_set_data(self):
     """test set model data"""
     row_headers = [('a', 'aa', 1),
                    ('a', 'bb', 2),
                    ('b', 'cc', 3),
                    ('c', 'cc', 4),
                    ('d', 'dd', 5),
                    ('e', 'ee', 5)]
     column_headers = []
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types)
     self.assertEqual(model._data, self.dict_data)
     self.assertEqual(model.index_names, tuple(self.index_names))
     self.assertEqual(model.pivot_rows, tuple(self.index_names))
     self.assertEqual(model.pivot_columns, ())
     self.assertEqual(model.pivot_frozen, ())
     self.assertEqual(model.frozen_value, ())
     self.assertEqual(model._row_data_header, row_headers)
     self.assertEqual(model._column_data_header, column_headers)
     self.assertEqual(model._row_data_header_set, set(row_headers))
     self.assertEqual(model._column_data_header_set, set(column_headers))
Esempio n. 28
0
 def test_get_pivoted_data1(self):
     """get data with pivot and frozen index and tuple_index_entries"""
     model = PivotModel()
     model.set_new_data(self.data, self.index_names, self.index_types, tuple_index_entries=self.tuple_index_entries)
     model.set_pivot(['test2'], ['test3'], ['test1'], ('a',))
     data = [['value_a_aa_1', None, None, None, None, None],
             [None, 'value_a_bb_2', None, None, None, None],
             [None, None, None, None, None, None]]
     data_model = [[d for d in inner] for inner in model.get_pivoted_data(range(3),range(6))]
     self.assertEqual(data_model, data)
Esempio n. 29
0
 def test_delete_index_values_with_same_name4(self):
     """Test that deleteing indexes with same name deletes all in _used_index_entries"""
     model = PivotModel()
     data = [['a', 'b', 'c', 1], ['d', 'a', 'c', 1] , ['c','d','e', 1]]
     model.set_new_data(data, self.index_names, self.index_types, index_real_names = ['test','test','test3'], used_index_values={('test',): set(['a','b','c','d'])})
     model.delete_index_values({'test': set(['a'])})
     self.assertEqual(model._used_index_values[('test',)], set(['b','c','d']))
Esempio n. 30
0
 def test_delete_index_values_with_same_name2(self):
     """Test that deleteing indexes with same name deletes all data"""
     model = PivotModel()
     data = [['a', 'b', 'c', 1], ['d', 'a', 'c', 1] , ['c','d','e', 1]]
     model.set_new_data(data, self.index_names, self.index_types, index_real_names = ['test','test','test3'])
     model.delete_index_values({'test': set(['a'])})
     self.assertEqual(model._data, {('c','d','e'): 1})