MCPcopy Create free account
hub / github.com/rthalley/dnspython / test_no_collateral_damage

Method test_no_collateral_damage

tests/test_immutable.py:126–149  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

124 self.assertFalse(hasattr(a, "b"))
125
126 def test_no_collateral_damage(self):
127 # A and B are immutable but not related. The magic that lets
128 # us write to immutable things while initializing B should not let
129 # B mess with A.
130
131 class A:
132 def __init__(self, a):
133 self.a = a
134
135 A = self.immutable_module.immutable(A)
136
137 class B:
138 def __init__(self, a, b):
139 self.b = a.a + b
140 # rudely attempt to mutate innocent immutable bystander 'a'
141 a.a = 1000
142
143 B = self.immutable_module.immutable(B)
144
145 a = A(10)
146 self.assertEqual(a.a, 10)
147 with self.assertRaises(TypeError):
148 B(a, 20)
149 self.assertEqual(a.a, 10)

Callers

nothing calls this directly

Calls 2

BClass · 0.85
AClass · 0.70

Tested by

no test coverage detected