##// END OF EJS Templates
Prepare some test for pytest in completers....
Prepare some test for pytest in completers. swap the context manager and the function definition. It is undefined wither the test are collected and then run at once; or ran while they are being yielded. In the fist case (what pytest does) the function was called outside the context manager, in the later case (node) it was working as expected.

File last commit:

r22911:4335860f
r25093:17c73977
Show More
test_pycolorize.py
78 lines | 2.0 KiB | text/x-python | PythonLexer
Matthias Bussonnier
Test more edge cases of the highlighting parser
r21801 # coding: utf-8
MinRK
always use StringIO, never cStringIO...
r4794 """Test suite for our color utilities.
Authors
-------
* Min RK
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2011 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING.txt, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# third party
import nose.tools as nt
# our own
from IPython.utils.PyColorize import Parser
Matthias Bussonnier
Test more edge cases of the highlighting parser
r21801 import io
MinRK
always use StringIO, never cStringIO...
r4794
#-----------------------------------------------------------------------------
# Test functions
#-----------------------------------------------------------------------------
Matthias Bussonnier
Test more edge cases of the highlighting parser
r21801 sample = u"""
def function(arg, *args, kwarg=True, **kwargs):
'''
this is docs
'''
pass is True
False == None
MinRK
always use StringIO, never cStringIO...
r4794
Matthias Bussonnier
Test more edge cases of the highlighting parser
r21801 with io.open(ru'unicode'):
raise ValueError("\n escape \r sequence")
print("wěird ünicoðe")
class Bar(Super):
def __init__(self):
super(Bar, self).__init__(1**2, 3^4, 5 or 6)
"""
def test_loop_colors():
Matthias Bussonnier
Start refactoring handling of color....
r22911 for style in ('Linux', 'NoColor','LightBG', 'Neutral'):
Matthias Bussonnier
Test more edge cases of the highlighting parser
r21801
def test_unicode_colorize():
Matthias Bussonnier
Start refactoring handling of color....
r22911 p = Parser(style=style)
f1 = p.format('1/0', 'str')
f2 = p.format(u'1/0', 'str')
Matthias Bussonnier
Test more edge cases of the highlighting parser
r21801 nt.assert_equal(f1, f2)
def test_parse_sample():
"""and test writing to a buffer"""
buf = io.StringIO()
Matthias Bussonnier
Start refactoring handling of color....
r22911 p = Parser(style=style)
p.format(sample, buf)
Matthias Bussonnier
Test more edge cases of the highlighting parser
r21801 buf.seek(0)
f1 = buf.read()
nt.assert_not_in('ERROR', f1)
def test_parse_error():
Matthias Bussonnier
Start refactoring handling of color....
r22911 p = Parser(style=style)
f1 = p.format(')', 'str')
if style != 'NoColor':
Matthias Bussonnier
Test more edge cases of the highlighting parser
r21801 nt.assert_in('ERROR', f1)
yield test_unicode_colorize
yield test_parse_sample
yield test_parse_error