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

Skip to content

Commit 734fbac

Browse files
committed
Test for long strings in whos magic
1 parent 72d6055 commit 734fbac

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

tests/test_magic.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,20 @@ def __repr__(self):
731731
_ip.user_ns["a"] = A()
732732
_ip.run_line_magic("whos", "")
733733

734+
def test_whos1():
735+
ip = get_ipython()
736+
ip.user_ns["shortstr"] = "The quick brown fox jumps over the lazy dog"
737+
ip.user_ns["longstr"] = " ".join(["The quick brown fox jumps over the lazy dog"]*2)
738+
expected_short = ip.user_ns["shortstr"]
739+
expected_long = "The quick brown fox jumps<...>x jumps over the lazy dog"
740+
with capture_output() as captured:
741+
ip.run_line_magic("whos","")
742+
stdout = captured.stdout
743+
## s = " ".join([l for l in stdout.splitlines() if l.startswith('longstr') ][0].split()[2:])
744+
long = " ".join(re.split(r"\s+str\s+",[l for l in stdout.splitlines() if l.startswith('longstr') ][0])[1:])
745+
short = " ".join(re.split(r"\s+str\s+",[l for l in stdout.splitlines() if l.startswith('shortstr') ][0])[1:])
746+
assert long == expected_long
747+
assert short == expected_short
734748

735749
def doctest_precision():
736750
"""doctest for %precision

0 commit comments

Comments
 (0)