fixing builtin tests and print_ builtin
--HG-- branch : trunk
This commit is contained in:
parent
ac934bb2b6
commit
fc3178a394
|
@ -10,8 +10,12 @@ else:
|
||||||
import __builtin__ as builtins
|
import __builtin__ as builtins
|
||||||
def print_(*args, **kwargs):
|
def print_(*args, **kwargs):
|
||||||
""" minimal backport of py3k print statement. """
|
""" minimal backport of py3k print statement. """
|
||||||
sep = 'sep' in kwargs and kwargs.pop('sep') or ' '
|
sep = ' '
|
||||||
end = 'end' in kwargs and kwargs.pop('end') or '\n'
|
if 'sep' in kwargs:
|
||||||
|
sep = kwargs.pop('sep')
|
||||||
|
end = '\n'
|
||||||
|
if 'end' in kwargs:
|
||||||
|
end = kwargs.pop('end')
|
||||||
file = 'file' in kwargs and kwargs.pop('file') or sys.stdout
|
file = 'file' in kwargs and kwargs.pop('file') or sys.stdout
|
||||||
if kwargs:
|
if kwargs:
|
||||||
args = ", ".join([str(x) for x in kwargs])
|
args = ", ".join([str(x) for x in kwargs])
|
||||||
|
|
|
@ -16,24 +16,20 @@ def test_BaseException():
|
||||||
pass
|
pass
|
||||||
assert not issubclass(MyRandomClass, py.builtin.BaseException)
|
assert not issubclass(MyRandomClass, py.builtin.BaseException)
|
||||||
|
|
||||||
assert py.builtin.BaseException.__module__ == 'exceptions'
|
assert py.builtin.BaseException.__module__ in ('exceptions', 'builtins')
|
||||||
assert Exception.__name__ == 'Exception'
|
assert Exception.__name__ == 'Exception'
|
||||||
|
|
||||||
|
|
||||||
def test_GeneratorExit():
|
def test_GeneratorExit():
|
||||||
assert py.builtin.GeneratorExit.__module__ == 'exceptions'
|
assert py.builtin.GeneratorExit.__module__ in ('exceptions', 'builtins')
|
||||||
assert issubclass(py.builtin.GeneratorExit, py.builtin.BaseException)
|
assert issubclass(py.builtin.GeneratorExit, py.builtin.BaseException)
|
||||||
|
|
||||||
def test_reversed():
|
def test_reversed():
|
||||||
reversed = py.builtin.reversed
|
reversed = py.builtin.reversed
|
||||||
r = reversed("hello")
|
r = reversed("hello")
|
||||||
assert iter(r) is r
|
assert iter(r) is r
|
||||||
assert r.next() == "o"
|
s = "".join(list(r))
|
||||||
assert r.next() == "l"
|
assert s == "olleh"
|
||||||
assert r.next() == "l"
|
|
||||||
assert r.next() == "e"
|
|
||||||
assert r.next() == "h"
|
|
||||||
py.test.raises(StopIteration, r.next)
|
|
||||||
assert list(reversed(list(reversed("hello")))) == ['h','e','l','l','o']
|
assert list(reversed(list(reversed("hello")))) == ['h','e','l','l','o']
|
||||||
py.test.raises(TypeError, reversed, reversed("hello"))
|
py.test.raises(TypeError, reversed, reversed("hello"))
|
||||||
|
|
||||||
|
@ -72,11 +68,21 @@ def test_sorted():
|
||||||
|
|
||||||
def test_print_simple():
|
def test_print_simple():
|
||||||
from py.builtin import print_
|
from py.builtin import print_
|
||||||
|
py.test.raises(TypeError, "print_(hello=3)")
|
||||||
f = py.io.TextIO()
|
f = py.io.TextIO()
|
||||||
print_("hello", "world", file=f)
|
print_("hello", "world", file=f)
|
||||||
s = f.getvalue()
|
s = f.getvalue()
|
||||||
assert s == "hello world\n"
|
assert s == "hello world\n"
|
||||||
py.test.raises(TypeError, "print_(hello=3)")
|
|
||||||
|
f = py.io.TextIO()
|
||||||
|
print_("hello", end="", file=f)
|
||||||
|
s = f.getvalue()
|
||||||
|
assert s == "hello"
|
||||||
|
|
||||||
|
f = py.io.TextIO()
|
||||||
|
print_("xyz", "abc", sep="", end="", file=f)
|
||||||
|
s = f.getvalue()
|
||||||
|
assert s == "xyzabc"
|
||||||
|
|
||||||
def test_reraise():
|
def test_reraise():
|
||||||
from py.builtin import _reraise
|
from py.builtin import _reraise
|
||||||
|
|
Loading…
Reference in New Issue