Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4411772

Browse files
committed
add tests
1 parent e53cc77 commit 4411772

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

IPython/extensions/tests/test_autoreload.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+

IPython/testing/iptest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,12 @@ def run_iptest():
385385
if '--with-xunit' in sys.argv and not hasattr(Xunit, 'orig_addError'):
386386
monkeypatch_xunit()
387387

388+
arg1 = sys.argv[1]
389+
if arg1.startswith('IPython/'):
390+
if arg1.endswith('.py'):
391+
arg1 = arg1[:-3]
392+
sys.argv[1] = arg1.replace('/', '.')
393+
388394
arg1 = sys.argv[1]
389395
if arg1 in test_sections:
390396
section = test_sections[arg1]

0 commit comments

Comments
 (0)