def test_set_attributes(self): t = StochasticTensor(self.distrib, tf.constant([1., 2., 3.])) self.assertTrue(hasattr(t, '_self_is_observed')) self.assertFalse(hasattr(t.__wrapped__, '_self_is_observed')) t._self_is_observed = 123 self.assertEqual(t._self_is_observed, 123) self.assertFalse(hasattr(t.__wrapped__, '_self_is_observed')) self.assertTrue(hasattr(t, 'log_prob')) self.assertFalse(hasattr(t.__wrapped__, 'log_prob')) t.log_prob = 456 self.assertEqual(t.log_prob, 456) self.assertTrue(hasattr(t, 'log_prob')) self.assertFalse(hasattr(t.__wrapped__, 'log_prob')) self.assertTrue(hasattr(t, 'get_shape')) self.assertTrue(hasattr(t.__wrapped__, 'get_shape')) t.get_shape = 789 self.assertEqual(t.get_shape, 789) self.assertEqual(t.__wrapped__.get_shape, 789) self.assertTrue(hasattr(t, 'get_shape')) self.assertTrue(hasattr(t.__wrapped__, 'get_shape')) t.abc = 1001 self.assertEqual(t.abc, 1001) self.assertEqual(t.__wrapped__.abc, 1001) self.assertTrue(hasattr(t, 'abc')) self.assertTrue(hasattr(t.__wrapped__, 'abc')) t.__wrapped__.xyz = 2002 self.assertEqual(t.xyz, 2002) self.assertEqual(t.__wrapped__.xyz, 2002) self.assertTrue(hasattr(t, 'xyz')) self.assertTrue(hasattr(t.__wrapped__, 'xyz'))
def test_del_attributes(self): t = StochasticTensor(self.distrib, tf.constant([1., 2., 3.])) del t._self_is_observed self.assertFalse(hasattr(t, '_self_is_observed')) self.assertFalse(hasattr(t.__wrapped__, '_self_is_observed')) t.abc = 1001 del t.abc self.assertFalse(hasattr(t, 'abc')) self.assertFalse(hasattr(t.__wrapped__, 'abc')) t.__wrapped__.xyz = 2002 del t.xyz self.assertFalse(hasattr(t, 'xyz')) self.assertFalse(hasattr(t.__wrapped__, 'xyz')) t.log_prob = 123 del t.log_prob self.assertFalse(hasattr(t.__wrapped__, 'log_prob')) self.assertNotEqual(t.log_prob, 123)