Tests on Python 3 #845

Merged
merged 18 commits into from Oct 9, 2011

3 participants

@takluyver
IPython member

This gets the bulk of the test suite passing on Python 3 - there's just a few isolated cases where it still doesn't.

@takluyver
IPython member

I've added context managers for AssertPrints and AssertNotPrints, removing the need for manually switching stdout (or stderr) in each location we need to check that something is being printed.

@fperez fperez and 1 other commented on an outdated diff Oct 9, 2011
IPython/core/page.py
@@ -68,6 +68,55 @@ def page_dumb(strng, start=0, screen_lines=25):
last_escape = esc_list[-1]
print >>io.stdout, last_escape + os.linesep.join(screens[-1])
+def _detect_screen_size(use_curses, screen_lines_def):
+ if (TERM=='xterm' or TERM=='xterm-color') and sys.platform != 'sunos5':
@fperez
IPython member
fperez added a line comment Oct 9, 2011

Now that this is a function, it should have a docstring explaining its call signature.

@fperez
IPython member
fperez added a line comment Oct 9, 2011

It should also be possible to add a small test for this guy, if nothing else at least a smoke test that validates its call form. Even simple tests like that do help catch regressions and api changes.

@takluyver
IPython member
takluyver added a line comment Oct 9, 2011

I'll do a docstring, but the reason I pulled it out like this was that the code was throwing an exception in the test suite (Python 3 termios didn't seem to like sys.stdout not being an actual OS stream), so I wanted to put a try/except around it. So I'm not sure how we can really test it in isolation.

@fperez
IPython member
fperez added a line comment Oct 9, 2011

Oh, the test could be just

def test_smoke():
  try:
   call_func(args)
  except ExpectedException:
    pass

at least that will call it and make sure that if we change the signature or a different exception is thrown, we see it.

As I said, it's just smoke testing so trivial to implement, but better than nothing.

@takluyver
IPython member
takluyver added a line comment Oct 9, 2011

OK, done one like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fperez fperez commented on an outdated diff Oct 9, 2011
IPython/testing/tools.py
@@ -323,6 +325,59 @@ def check_pairs(func, pairs):
out = func(inp)
assert out == expected, pair_fail_msg.format(name, inp, expected, out)
+if py3compat.PY3:
+ MyStringIO = StringIO
+else:
+ # In Python 2, stdout/stderr can have either bytes or unicode written to them,
+ # so we need a class that can handle both.
+ class MyStringIO(StringIO):
+ def write(self, s):
+ s = py3compat.cast_unicode(s, encoding=getdefaultencoding())
+ super(MyStringIO, self).write(s)
+
+notprinted_msg = """Did not find {0!r} in printed output (on {1}):
+{2!r}"""
+class AssertPrints(object):
@fperez
IPython member
fperez added a line comment Oct 9, 2011

blank lines missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fperez
IPython member

Other than the small comments above, go for it. The code looks clean, thanks!

@fperez
IPython member

Great, ran the test suite on oneiric and all looks good. Merging now; excellent work.

@fperez fperez merged commit 9b734ea into ipython:master Oct 9, 2011
@takluyver
IPython member

Great, thanks Fernando.

@minrk
IPython member

@takluyver - why are you disabling our warning mechanism? Have you removed the entire utils.warn module? And if not, why only in utils.path?

IPython member

I'm not disabling it, just switching to the standard warnings module. utils.warn's docstring says "Shoudn't we just use the built in warnings module." I came upon it because it caused some unicode/bytes friction with capturing stdout into a StringIO in the test suite. I've since resolved that friction another way, but it seemed sensible to switch to the stdlib warnings system while I had the code open.

If we're happy with using the standard library warning system, I'll look round to see where else utils.warn is used. If not, it's easy enough to change this back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment