コード例 #1
0
ファイル: test_struct.py プロジェクト: rtosholdings/riptable
 def test_lock(self):
     st1 = Struct({_k: [_i] for _i, _k in enumerate(['a', 'b', 'c'])})
     st1._lock()
     with self.assertRaises(AttributeError):
         st1.a = 1
     with self.assertRaises(AttributeError):
         st1.d = 1
     with self.assertRaises(AttributeError):
         st1['a'] = 1
     with self.assertRaises(AttributeError):
         st1['d'] = 1
     with self.assertRaises(AttributeError):
         del st1.b
     with self.assertRaises(AttributeError):
         st1.col_remove('c')
     with self.assertRaises(AttributeError):
         _ = st1.col_pop('c')
     with self.assertRaises(AttributeError):
         _ = st1.col_rename('c', 'C')
     with self.assertRaises(AttributeError):
         _ = st1.col_map({})
     with self.assertRaises(AttributeError):
         _ = st1.col_move_to_back('c')
     with self.assertRaises(AttributeError):
         _ = st1.col_move_to_front('c')
     st1._unlock()
     st1.a = 1
     st1.d = 1
     del st1.b
     self.assertEqual(list(st1.keys()), ['a', 'c', 'd'])
     self.assertEqual(st1.a, 1)
     self.assertEqual(st1.d, 1)
コード例 #2
0
ファイル: test_struct.py プロジェクト: rtosholdings/riptable
 def test_col_remove(self):
     cols = ['aa', 'b', 'c', 'μεαν']
     dict1 = {_k: [_i] for _i, _k in enumerate(cols)}
     st1 = Struct(dict1)
     self.assertEqual(list(st1.keys()), cols)
     st1.col_remove('aa')
     self.assertEqual(list(st1.keys()), cols[1:])
     with self.assertRaises(IndexError):
         st1.col_remove('aa')
     st1.col_remove(['b', 'c'])
     self.assertEqual(list(st1.keys()), cols[3:])
     with self.assertRaises(IndexError):
         st1.col_remove(['μεαν', 'b', 'c'])
     with self.assertRaises(TypeError):
         st1.col_remove(2)
     self.assertEqual(list(st1.keys()), cols[3:])
     st1.col_remove(['μεαν'])
     self.assertEqual(list(st1.keys()), [])
     st1.col_remove([])
     self.assertEqual(list(st1.keys()), [])