@@ -75,11 +75,10 @@ def test_ipython():
7575 import IPython
7676 except ImportError :
7777 pytest .skip ("ipython not available; install manually" )
78- import pykern .pkdebug
79- from pykern .pkdebug import pkdp
80- from pykern import pkcompat
78+ return
79+ from pykern import pkdebug , pkcompat , pkunit
8180
82- pykern . pkdebug .init (output = None )
81+ pkdebug .init (output = None )
8382 # Overwrite the _ipython_write method. This doesn't test how ipython is
8483 # running. We'll do that separately
8584 save = []
@@ -88,43 +87,25 @@ def _write(msg):
8887 save .append (msg )
8988
9089 try :
91- pykern .pkdebug ._ipython_write = _write
92- pkdp ("abcdefgh" )
93- assert (
94- "abcdefgh" in save [0 ]
95- ), "When _ipython_write is set, should be called if no output"
90+ pkdebug ._ipython_write = _write
91+ pkdebug .pkdp ("abcdefgh" )
92+ pkunit .pkre ("abcdefgh" , save [0 ])
9693 finally :
97- pykern . pkdebug ._ipython_write = None
94+ pkdebug ._ipython_write = None
9895 import subprocess
9996
100- try :
101- p = subprocess .Popen (
102- [
103- "ipython" ,
104- "--colors" ,
105- "NoColor" ,
106- "-c" ,
107- 'from pykern.pkdebug import pkdp; pkdp("abcdef")' ,
108- ],
109- stdout = subprocess .PIPE ,
110- stderr = subprocess .PIPE ,
111- )
112- # Not a brilliant test, but does demonstrate that write_err works
113- assert "<module> abcdef" in pkcompat .from_bytes (
114- p .stderr .read ()
115- ), "When in IPython, pkdp() should output to stdout"
116- # We make this rigid, because we want to know when IPython interpreter changes
117- o = pkcompat .from_bytes (p .stdout .read ())
118- assert re .search (
119- "Out\\ [1\\ ]: \n ?'abcdef'" , o
120- ), "IPython pkdp() is evaluated and written to stdout {}" .format (o )
121-
122- except OSError as e :
123- # If we don't have IPython, then ignore error
124- import errno
125-
126- if e .errno != errno .ENOENT :
127- reraise
97+ # Verify works as ipython process
98+ p = subprocess .Popen (
99+ [
100+ "ipython" ,
101+ "-c" ,
102+ 'from pykern.pkdebug import pkdp; pkdp("abcdef")' ,
103+ ],
104+ stdout = subprocess .PIPE ,
105+ stderr = subprocess .PIPE ,
106+ )
107+ pkunit .pkre ("<module> abcdef" , p .stderr .read ())
108+ pkunit .pkre (r"OUT...:\s+'abcdef'" , p .stdout .read ())
128109
129110
130111def test_logging (capsys , caplog ):
0 commit comments