##// END OF EJS Templates
utils/tests: move to pytest.mark.parameterize in test_text.py
utils/tests: move to pytest.mark.parameterize in test_text.py

File last commit:

r27420:3a78d13b
r27420:3a78d13b
Show More
test_text.py
208 lines | 7.0 KiB | text/x-python | PythonLexer
Fernando Perez
Add failing test: columnize called with very long entries....
r4538 # encoding: utf-8
"""Tests for IPython.utils.text"""
#-----------------------------------------------------------------------------
# Copyright (C) 2011 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import os
MinRK
update EvalFormatter to allow arbitrary expressions...
r4654 import math
Matthias BUSSONNIER
re-write columnize, with intermediate step....
r7387 import random
Thomas Kluyver
Fix EvalFormatter test for Python 3.4...
r13990 import sys
Fernando Perez
Add failing test: columnize called with very long entries....
r4538
Thomas Kluyver
Simplify some pathlib imports
r24258 from pathlib import Path
Fernando Perez
Add failing test: columnize called with very long entries....
r4538
Samuel Gaist
[utils][tests][text] Remove nose
r26927 import pytest
Fernando Perez
Add failing test: columnize called with very long entries....
r4538 from IPython.utils import text
#-----------------------------------------------------------------------------
# Globals
#-----------------------------------------------------------------------------
def test_columnize():
Fernando Perez
Fix bug where tab-completion with very long filenames would crash the qt console....
r4539 """Basic columnize tests."""
size = 5
naught101
add some extra tests for row-first columnize
r21616 items = [l*size for l in 'abcd']
Fernando Perez
Fix bug where tab-completion with very long filenames would crash the qt console....
r4539 out = text.columnize(items, displaywidth=80)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert out == "aaaaa bbbbb ccccc ddddd\n"
naught101
add some extra tests for row-first columnize
r21616 out = text.columnize(items, displaywidth=25)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert out == "aaaaa ccccc\nbbbbb ddddd\n"
Matthias BUSSONNIER
re-write columnize, with intermediate step....
r7387 out = text.columnize(items, displaywidth=12)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert out == "aaaaa ccccc\nbbbbb ddddd\n"
Matthias BUSSONNIER
re-write columnize, with intermediate step....
r7387 out = text.columnize(items, displaywidth=10)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert out == "aaaaa\nbbbbb\nccccc\nddddd\n"
naught101
add some extra tests for row-first columnize
r21616
out = text.columnize(items, row_first=True, displaywidth=80)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert out == "aaaaa bbbbb ccccc ddddd\n"
naught101
add some extra tests for row-first columnize
r21616 out = text.columnize(items, row_first=True, displaywidth=25)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert out == "aaaaa bbbbb\nccccc ddddd\n"
naught101
add some extra tests for row-first columnize
r21616 out = text.columnize(items, row_first=True, displaywidth=12)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert out == "aaaaa bbbbb\nccccc ddddd\n"
naught101
add some extra tests for row-first columnize
r21616 out = text.columnize(items, row_first=True, displaywidth=10)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert out == "aaaaa\nbbbbb\nccccc\nddddd\n"
naught101
add some extra tests for row-first columnize
r21616
naught101
Add spread option, to allow columns to fill space.
r21621 out = text.columnize(items, displaywidth=40, spread=True)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert out == "aaaaa bbbbb ccccc ddddd\n"
naught101
Add spread option, to allow columns to fill space.
r21621 out = text.columnize(items, displaywidth=20, spread=True)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert out == "aaaaa ccccc\nbbbbb ddddd\n"
naught101
Add spread option, to allow columns to fill space.
r21621 out = text.columnize(items, displaywidth=12, spread=True)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert out == "aaaaa ccccc\nbbbbb ddddd\n"
naught101
Add spread option, to allow columns to fill space.
r21621 out = text.columnize(items, displaywidth=10, spread=True)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert out == "aaaaa\nbbbbb\nccccc\nddddd\n"
naught101
Add spread option, to allow columns to fill space.
r21621
Matthias BUSSONNIER
re-write columnize, with intermediate step....
r7387
def test_columnize_random():
luz.paz
Misc. typos fixes...
r24132 """Test with random input to hopefully catch edge case """
naught101
add some extra tests for row-first columnize
r21616 for row_first in [True, False]:
for nitems in [random.randint(2,70) for i in range(2,20)]:
displaywidth = random.randint(20,200)
rand_len = [random.randint(2,displaywidth) for i in range(nitems)]
items = ['x'*l for l in rand_len]
out = text.columnize(items, row_first=row_first, displaywidth=displaywidth)
longer_line = max([len(x) for x in out.split('\n')])
longer_element = max(rand_len)
Nikita Kniazev
Rewrite bunch of `raise AssertionError` and `assert False` tests
r27087 assert longer_line <= displaywidth, (
f"Columnize displayed something lager than displaywidth : {longer_line}\n"
f"longer element : {longer_element}\n"
f"displaywidth : {displaywidth}\n"
f"number of element : {nitems}\n"
f"size of each element : {rand_len}\n"
f"row_first={row_first}\n"
)
Fernando Perez
Fix bug where tab-completion with very long filenames would crash the qt console....
r4539
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715
Nate Rush
utils/tests: move to pytest.mark.parameterize in test_text.py
r27420 @pytest.mark.parametrize('row_first', [True, False])
def test_columnize_medium(row_first):
naught101
add some extra tests for row-first columnize
r21616 """Test with inputs than shouldn't be wider than 80"""
Matthias BUSSONNIER
re-write columnize, with intermediate step....
r7387 size = 40
items = [l*size for l in 'abc']
Nate Rush
utils/tests: move to pytest.mark.parameterize in test_text.py
r27420 out = text.columnize(items, row_first=row_first, displaywidth=80)
assert out == "\n".join(items + [""]), "row_first={0}".format(row_first)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715
Fernando Perez
Fix bug where tab-completion with very long filenames would crash the qt console....
r4539
Nate Rush
utils/tests: move to pytest.mark.parameterize in test_text.py
r27420 @pytest.mark.parametrize('row_first', [True, False])
def test_columnize_long(row_first):
Fernando Perez
Fix bug where tab-completion with very long filenames would crash the qt console....
r4539 """Test columnize with inputs longer than the display window"""
size = 11
items = [l*size for l in 'abc']
Nate Rush
utils/tests: move to pytest.mark.parameterize in test_text.py
r27420 out = text.columnize(items, row_first=row_first, displaywidth=size - 1)
assert out == "\n".join(items + [""]), "row_first={0}".format(row_first)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715
MinRK
update EvalFormatter to allow arbitrary expressions...
r4654
Thomas Kluyver
Add DollarFormatter and tests.
r5354 def eval_formatter_check(f):
Thomas Kluyver
Use DollarFormatter to fill in names in ! shell calls....
r5355 ns = dict(n=12, pi=math.pi, stuff='hello there', os=os, u=u"café", b="café")
Thomas Kluyver
Various fixes to tests in IPython.utils.
r4891 s = f.format("{n} {n//4} {stuff.split()[0]}", **ns)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert s == "12 3 hello"
Nikita Kniazev
Rewrite bunch of `raise AssertionError` and `assert False` tests
r27087 s = f.format(" ".join(["{n//%i}" % i for i in range(1, 8)]), **ns)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert s == "12 6 4 3 2 2 1"
Nikita Kniazev
Rewrite bunch of `raise AssertionError` and `assert False` tests
r27087 s = f.format("{[n//i for i in range(1,8)]}", **ns)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert s == "[12, 6, 4, 3, 2, 2, 1]"
MinRK
update EvalFormatter to allow arbitrary expressions...
r4654 s = f.format("{stuff!s}", **ns)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert s == ns["stuff"]
MinRK
update EvalFormatter to allow arbitrary expressions...
r4654 s = f.format("{stuff!r}", **ns)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert s == repr(ns["stuff"])
Thomas Kluyver
Use DollarFormatter to fill in names in ! shell calls....
r5355 # Check with unicode:
s = f.format("{u}", **ns)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert s == ns["u"]
Thomas Kluyver
Use DollarFormatter to fill in names in ! shell calls....
r5355 # This decodes in a platform dependent manner, but it shouldn't error out
s = f.format("{b}", **ns)
Samuel Gaist
[utils][tests][text] Remove nose
r26927
pytest.raises(NameError, f.format, "{dne}", **ns)
MinRK
update EvalFormatter to allow arbitrary expressions...
r4654
Thomas Kluyver
Add DollarFormatter and tests.
r5354 def eval_formatter_slicing_check(f):
MinRK
update EvalFormatter to allow arbitrary expressions...
r4654 ns = dict(n=12, pi=math.pi, stuff='hello there', os=os)
s = f.format(" {stuff.split()[:]} ", **ns)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert s == " ['hello', 'there'] "
MinRK
update EvalFormatter to allow arbitrary expressions...
r4654 s = f.format(" {stuff.split()[::-1]} ", **ns)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert s == " ['there', 'hello'] "
MinRK
update EvalFormatter to allow arbitrary expressions...
r4654 s = f.format("{stuff[::2]}", **ns)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert s == ns["stuff"][::2]
Samuel Gaist
[utils][tests][text] Remove nose
r26927 pytest.raises(SyntaxError, f.format, "{n:x}", **ns)
MinRK
update EvalFormatter to allow arbitrary expressions...
r4654
Thomas Kluyver
Add DollarFormatter and tests.
r5354 def eval_formatter_no_slicing_check(f):
Nikita Kniazev
Rewrite bunch of `raise AssertionError` and `assert False` tests
r27087 ns = dict(n=12, pi=math.pi, stuff="hello there", os=os)
s = f.format("{n:x} {pi**2:+f}", **ns)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert s == "c +9.869604"
s = f.format("{stuff[slice(1,4)]}", **ns)
assert s == "ell"
Hugo
Drop support for Python 3.3
r24260
s = f.format("{a[:]}", a=[1, 2])
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert s == "[1, 2]"
MinRK
update EvalFormatter to allow arbitrary expressions...
r4654
Thomas Kluyver
Add DollarFormatter and tests.
r5354 def test_eval_formatter():
f = text.EvalFormatter()
eval_formatter_check(f)
eval_formatter_no_slicing_check(f)
def test_full_eval_formatter():
f = text.FullEvalFormatter()
eval_formatter_check(f)
eval_formatter_slicing_check(f)
def test_dollar_formatter():
f = text.DollarFormatter()
eval_formatter_check(f)
eval_formatter_slicing_check(f)
Marin Gilles
Revert "added absolute_import to utils.text module + test"...
r21541
Thomas Kluyver
Add DollarFormatter and tests.
r5354 ns = dict(n=12, pi=math.pi, stuff='hello there', os=os)
s = f.format("$n", **ns)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert s == "12"
Thomas Kluyver
Add DollarFormatter and tests.
r5354 s = f.format("$n.real", **ns)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert s == "12"
Thomas Kluyver
Add DollarFormatter and tests.
r5354 s = f.format("$n/{stuff[:5]}", **ns)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert s == "12/hello"
Thomas Kluyver
Allow 2033 to get literal $ in shell commands.
r5365 s = f.format("$n $$HOME", **ns)
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert s == "12 $HOME"
Thomas Kluyver
Add test for to specify name of an environment variable.
r5375 s = f.format("${foo}", foo="HOME")
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert s == "$HOME"
Fernando Perez
Add robust email-quote-stripping function to text utilities.
r7713
def test_strip_email():
src = """\
>> >>> def f(x):
>> ... return x+1
Marin Gilles
Revert "added absolute_import to utils.text module + test"...
r21541 >> ...
Fernando Perez
Add robust email-quote-stripping function to text utilities.
r7713 >> >>> zz = f(2.5)"""
cln = """\
>>> def f(x):
... return x+1
Marin Gilles
Revert "added absolute_import to utils.text module + test"...
r21541 ...
Fernando Perez
Add robust email-quote-stripping function to text utilities.
r7713 >>> zz = f(2.5)"""
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert text.strip_email_quotes(src) == cln
Fernando Perez
Fix logic for longest_substring when only one input....
r7715
def test_strip_email2():
Nikita Kniazev
Rewrite bunch of `raise AssertionError` and `assert False` tests
r27087 src = "> > > list()"
cln = "list()"
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert text.strip_email_quotes(src) == cln
Thomas Kluyver
Add tests for things in utils
r15516
Nikita Kniazev
Rewrite bunch of `raise AssertionError` and `assert False` tests
r27087
Thomas Kluyver
Add tests for things in utils
r15516 def test_LSString():
lss = text.LSString("abc\ndef")
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 assert lss.l == ["abc", "def"]
assert lss.s == "abc def"
Marin Gilles
test fix to try path for cwd
r21547 lss = text.LSString(os.getcwd())
Samuel Gaist
[utils][tests][text] Remove nose
r26927 assert isinstance(lss.p[0], Path)
Thomas Kluyver
Add tests for things in utils
r15516
Nikita Kniazev
Rewrite bunch of `raise AssertionError` and `assert False` tests
r27087
Thomas Kluyver
Add tests for things in utils
r15516 def test_SList():
Matthias Bussonnier
Remove nose.tools.assert_equal from more places.
r26715 sl = text.SList(["a 11", "b 1", "a 2"])
assert sl.n == "a 11\nb 1\na 2"
assert sl.s == "a 11 b 1 a 2"
assert sl.grep(lambda x: x.startswith("a")) == text.SList(["a 11", "a 2"])
assert sl.fields(0) == text.SList(["a", "b", "a"])
assert sl.sort(field=1, nums=True) == text.SList(["b 1", "a 2", "a 11"])