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)
def test_col_pop(self): cols = ['aa', 'b', 'c', 'μεαν'] dict1 = {_k: [_i] for _i, _k in enumerate(cols)} st1 = Struct(dict1) val = st1.col_pop('aa') self.assertEqual(val, [0]) self.assertEqual(list(st1.keys()), cols[1:]) with self.assertRaises(IndexError): st1.col_pop('aa') with self.assertRaises(IndexError): st1.col_pop(['aa']) st2 = st1.col_pop(['b', 'c']) self.assertEqual(list(st1.keys()), cols[3:]) self.assertEqual(list(st2.keys()), ['b', 'c']) self.assertEqual(st2.b, [1]) self.assertEqual(st2.c, [2]) st3 = st1.col_pop(slice(None)) self.assertEqual(st1.get_ncols(), 0) self.assertEqual(st3.get_ncols(), 1) self.assertEqual(st3.μεαν, [3])