@@ -151,6 +151,59 @@ class MyEnum(Enum):
151151 with tt .AssertNotPrints (('[autoreload of %s failed:' % mod_name ), channel = 'stderr' ):
152152 self .shell .run_code ("pass" ) # trigger another reload
153153
154+ def test_reload_class_attributes (self ):
155+ self .shell .magic_autoreload ("2" )
156+ mod_name , mod_fn = self .new_module (textwrap .dedent ("""
157+ class MyClass:
158+
159+ def __init__(self, a=10):
160+ self.a = a
161+ self.b = 22
162+ # self.toto = 33
163+
164+ def square(self):
165+ print('compute square')
166+ return self.a*self.a
167+ """ ))
168+ self .shell .run_code ("from %s import MyClass" % mod_name )
169+ self .shell .run_code ("c = MyClass(5)" )
170+ self .shell .run_code ("c.square()" )
171+ with nt .assert_raises (AttributeError ):
172+ self .shell .run_code ("c.cube()" )
173+ with nt .assert_raises (AttributeError ):
174+ self .shell .run_code ("c.power(5)" )
175+ self .shell .run_code ("c.b" )
176+ with nt .assert_raises (AttributeError ):
177+ self .shell .run_code ("c.toto" )
178+
179+
180+ self .write_file (mod_fn , textwrap .dedent ("""
181+ class MyClass:
182+
183+ def __init__(self, a=10):
184+ self.a = a
185+ self.b = 11
186+
187+ def power(self, p):
188+ print('compute power '+str(p))
189+ return self.a**p
190+ """ ))
191+
192+ self .shell .run_code ("d = MyClass(5)" )
193+ self .shell .run_code ("d.power(5)" )
194+ with nt .assert_raises (AttributeError ):
195+ self .shell .run_code ("c.cube()" )
196+ with nt .assert_raises (AttributeError ):
197+ self .shell .run_code ("c.square(5)" )
198+ self .shell .run_code ("c.b" )
199+ self .shell .run_code ("c.a" )
200+ with nt .assert_raises (AttributeError ):
201+ self .shell .run_code ("c.toto" )
202+
203+
204+
205+
206+
154207
155208 def _check_smoketest (self , use_aimport = True ):
156209 """
@@ -340,3 +393,7 @@ def test_smoketest_aimport(self):
340393
341394 def test_smoketest_autoreload (self ):
342395 self ._check_smoketest (use_aimport = False )
396+
397+
398+
399+
0 commit comments