##// END OF EJS Templates
test both old and new classes
Matthias Bussonnier -
Show More
@@ -164,20 +164,26 b' class TestAutoreload(Fixture):'
164 def square(self):
164 def square(self):
165 print('compute square')
165 print('compute square')
166 return self.a*self.a
166 return self.a*self.a
167 """))
167 """
168 )
169 )
168 self.shell.run_code("from %s import MyClass" % mod_name)
170 self.shell.run_code("from %s import MyClass" % mod_name)
169 self.shell.run_code("c = MyClass(5)")
171 self.shell.run_code("first = MyClass(5)")
170 self.shell.run_code("c.square()")
172 self.shell.run_code("first.square()")
171 with nt.assert_raises(AttributeError):
173 with nt.assert_raises(AttributeError):
172 self.shell.run_code("c.cube()")
174 self.shell.run_code("first.cube()")
173 with nt.assert_raises(AttributeError):
175 with nt.assert_raises(AttributeError):
174 self.shell.run_code("c.power(5)")
176 self.shell.run_code("first.power(5)")
175 self.shell.run_code("c.b")
177 self.shell.run_code("first.b")
176 with nt.assert_raises(AttributeError):
178 with nt.assert_raises(AttributeError):
177 self.shell.run_code("c.toto")
179 self.shell.run_code("first.toto")
178
180
181 # remove square, add power
179
182
180 self.write_file(mod_fn, textwrap.dedent("""
183 self.write_file(
184 mod_fn,
185 textwrap.dedent(
186 """
181 class MyClass:
187 class MyClass:
182
188
183 def __init__(self, a=10):
189 def __init__(self, a=10):
@@ -187,23 +193,22 b' class TestAutoreload(Fixture):'
187 def power(self, p):
193 def power(self, p):
188 print('compute power '+str(p))
194 print('compute power '+str(p))
189 return self.a**p
195 return self.a**p
190 """))
196 """
197 ),
198 )
191
199
192 self.shell.run_code("d = MyClass(5)")
200 self.shell.run_code("second = MyClass(5)")
193 self.shell.run_code("d.power(5)")
201
202 for object_name in {'first', 'second'}:
203 self.shell.run_code("{object_name}.power(5)".format(object_name=object_name))
194 with nt.assert_raises(AttributeError):
204 with nt.assert_raises(AttributeError):
195 self.shell.run_code("c.cube()")
205 self.shell.run_code("{object_name}.cube()".format(object_name=object_name))
196 with nt.assert_raises(AttributeError):
206 with nt.assert_raises(AttributeError):
197 self.shell.run_code("c.square(5)")
207 self.shell.run_code("{object_name}.square(5)".format(object_name=object_name))
198 self.shell.run_code("c.b")
208 self.shell.run_code("{object_name}.b".format(object_name=object_name))
199 self.shell.run_code("c.a")
209 self.shell.run_code("{object_name}.a".format(object_name=object_name))
200 with nt.assert_raises(AttributeError):
210 with nt.assert_raises(AttributeError):
201 self.shell.run_code("c.toto")
211 self.shell.run_code("{object_name}.toto".format(object_name=object_name))
202
203
204
205
206
207
212
208 def _check_smoketest(self, use_aimport=True):
213 def _check_smoketest(self, use_aimport=True):
209 """
214 """
General Comments 0
You need to be logged in to leave comments. Login now