##// END OF EJS Templates
Remove yield test that are not support by pytest anymore...
Matthias Bussonnier -
Show More
@@ -41,7 +41,7 b' install:'
41 41 fi
42 42 - pip install -e file://$PWD#egg=ipython[test] --upgrade
43 43 - pip install trio curio --upgrade --upgrade-strategy eager
44 - pip install 'pytest<6' 'matplotlib !=3.2.0'
44 - pip install 'pytest' 'matplotlib !=3.2.0'
45 45 - pip install codecov check-manifest pytest-cov --upgrade
46 46
47 47
@@ -138,7 +138,7 b" def latex_to_png_dvipng(s, wrap, color='Black', scale=1.0):"
138 138 except FindCmdError:
139 139 return None
140 140 try:
141 workdir = PurePath(tempfile.mkdtemp())
141 workdir = Path(tempfile.mkdtemp())
142 142 tmpfile = workdir.joinpath("tmp.tex")
143 143 dvifile = workdir.joinpath("tmp.dvi")
144 144 outfile = workdir.joinpath("tmp.png")
@@ -9,11 +9,16 b' import nose.tools as nt'
9 9 import pytest
10 10
11 11 from IPython.lib import latextools
12 from IPython.testing.decorators import onlyif_cmds_exist, skipif_not_matplotlib
12 from IPython.testing.decorators import (
13 onlyif_cmds_exist,
14 skipif_not_matplotlib,
15 skip_iptest_but_not_pytest,
16 )
13 17 from IPython.utils.process import FindCmdError
14 18
15 19
16 20 @pytest.mark.parametrize('command', ['latex', 'dvipng'])
21 @skip_iptest_but_not_pytest
17 22 def test_check_latex_to_png_dvipng_fails_when_no_cmd(command):
18 23 def mock_find_cmd(arg):
19 24 if arg == command:
@@ -23,8 +28,15 b' def test_check_latex_to_png_dvipng_fails_when_no_cmd(command):'
23 28 assert latextools.latex_to_png_dvipng("whatever", True) == None
24 29
25 30
26 @onlyif_cmds_exist('latex', 'dvipng')
27 def test_latex_to_png_dvipng_runs():
31 @contextmanager
32 def no_op(*args, **kwargs):
33 yield
34
35
36 @onlyif_cmds_exist("latex", "dvipng")
37 @pytest.mark.parametrize("s, wrap", [(u"$$x^2$$", False), (u"x^2", True)])
38 @skip_iptest_but_not_pytest
39 def test_latex_to_png_dvipng_runs(s, wrap):
28 40 """
29 41 Test that latex_to_png_dvipng just runs without error.
30 42 """
@@ -32,36 +44,32 b' def test_latex_to_png_dvipng_runs():'
32 44 assert filename == "breqn.sty"
33 45 return None
34 46
35 for (s, wrap) in [(u"$$x^2$$", False), (u"x^2", True)]:
36 yield (latextools.latex_to_png_dvipng, s, wrap)
37
38 with patch.object(latextools, "kpsewhich", mock_kpsewhich):
39 yield (latextools.latex_to_png_dvipng, s, wrap)
47 latextools.latex_to_png_dvipng(s, wrap)
40 48
49 with patch_latextool(mock_kpsewhich):
50 latextools.latex_to_png_dvipng(s, wrap)
41 51
42 @contextmanager
43 def no_op(*args, **kwargs):
44 yield
45 52
46 53 def mock_kpsewhich(filename):
47 54 assert filename == "breqn.sty"
48 55 return None
49 56
50 57 @contextmanager
51 def patch_latextool():
52 with patch.object(latextools, "kpsewhich", mock_kpsewhich):
58 def patch_latextool(mock=mock_kpsewhich):
59 with patch.object(latextools, "kpsewhich", mock):
53 60 yield
54 61
55 62 @pytest.mark.parametrize('context', [no_op, patch_latextool])
56 63 @pytest.mark.parametrize('s_wrap', [("$x^2$", False), ("x^2", True)])
64 @skip_iptest_but_not_pytest
57 65 def test_latex_to_png_mpl_runs(s_wrap, context):
58 66 """
59 67 Test that latex_to_png_mpl just runs without error.
60 68 """
61 69 try:
62 import matplotbli
70 import matplotlib
63 71 except ImportError:
64 pytest.skip("This needs matplotlib to be availlable")
72 pytest.skip("This needs matplotlib to be available")
65 73 return
66 74 s, wrap = s_wrap
67 75 with context():
@@ -81,7 +89,7 b' def test_genelatex_no_wrap():'
81 89 assert False, ("kpsewhich should not be called "
82 90 "(called with {0})".format(filename))
83 91
84 with patch.object(latextools, "kpsewhich", mock_kpsewhich):
92 with patch_latextool(mock_kpsewhich):
85 93 assert '\n'.join(latextools.genelatex("body text", False)) == r'''\documentclass{article}
86 94 \usepackage{amsmath}
87 95 \usepackage{amsthm}
@@ -101,7 +109,7 b' def test_genelatex_wrap_with_breqn():'
101 109 assert filename == "breqn.sty"
102 110 return "path/to/breqn.sty"
103 111
104 with patch.object(latextools, "kpsewhich", mock_kpsewhich):
112 with patch_latextool(mock_kpsewhich):
105 113 assert '\n'.join(latextools.genelatex("x^2", True)) == r'''\documentclass{article}
106 114 \usepackage{amsmath}
107 115 \usepackage{amsthm}
@@ -124,7 +132,7 b' def test_genelatex_wrap_without_breqn():'
124 132 assert filename == "breqn.sty"
125 133 return None
126 134
127 with patch.object(latextools, "kpsewhich", mock_kpsewhich):
135 with patch_latextool(mock_kpsewhich):
128 136 assert '\n'.join(latextools.genelatex("x^2", True)) == r'''\documentclass{article}
129 137 \usepackage{amsmath}
130 138 \usepackage{amsthm}
@@ -12,9 +12,10 b' import string'
12 12 import unittest
13 13
14 14 import nose.tools as nt
15 import pytest
15 16
16 17 from IPython.lib import pretty
17 from IPython.testing.decorators import skip_without
18 from IPython.testing.decorators import skip_without, skip_iptest_but_not_pytest
18 19
19 20 from io import StringIO
20 21
@@ -105,17 +106,36 b' def test_callability_checking():'
105 106 nt.assert_equal(gotoutput, expectedoutput)
106 107
107 108
108 def test_sets():
109 @pytest.mark.parametrize(
110 "obj,expected_output",
111 zip(
112 [
113 set(),
114 frozenset(),
115 set([1]),
116 frozenset([1]),
117 set([1, 2]),
118 frozenset([1, 2]),
119 set([-1, -2, -3]),
120 ],
121 [
122 "set()",
123 "frozenset()",
124 "{1}",
125 "frozenset({1})",
126 "{1, 2}",
127 "frozenset({1, 2})",
128 "{-3, -2, -1}",
129 ],
130 ),
131 )
132 @skip_iptest_but_not_pytest
133 def test_sets(obj, expected_output):
109 134 """
110 135 Test that set and frozenset use Python 3 formatting.
111 136 """
112 objects = [set(), frozenset(), set([1]), frozenset([1]), set([1, 2]),
113 frozenset([1, 2]), set([-1, -2, -3])]
114 expected = ['set()', 'frozenset()', '{1}', 'frozenset({1})', '{1, 2}',
115 'frozenset({1, 2})', '{-3, -2, -1}']
116 for obj, expected_output in zip(objects, expected):
117 137 got_output = pretty.pretty(obj)
118 yield nt.assert_equal, got_output, expected_output
138 nt.assert_equal(got_output, expected_output)
119 139
120 140
121 141 @skip_without('xxlimited')
@@ -154,6 +154,17 b' def make_label_dec(label, ds=None):'
154 154 return decor
155 155
156 156
157 def skip_iptest_but_not_pytest(f):
158 """
159 Warnign this will make the test invisible to iptest.
160 """
161 import os
162
163 if os.environ.get("IPTEST_WORKING_DIR", None) is not None:
164 f.__test__ = False
165 return f
166
167
157 168 # Inspired by numpy's skipif, but uses the full apply_wrapper utility to
158 169 # preserve function metadata better and allows the skip condition to be a
159 170 # callable.
@@ -16,6 +16,9 b''
16 16 import sys
17 17
18 18 import nose.tools as nt
19 import pytest
20
21 from IPython.testing.decorators import skip_iptest_but_not_pytest
19 22
20 23 from IPython.utils import capture
21 24
@@ -66,38 +69,45 b' hello_stderr = "hello, stderr"'
66 69 #-----------------------------------------------------------------------------
67 70 # Test Functions
68 71 #-----------------------------------------------------------------------------
69
70 def test_rich_output_empty():
72 @pytest.mark.parametrize("method_mime", _mime_map.items())
73 @skip_iptest_but_not_pytest
74 def test_rich_output_empty(method_mime):
71 75 """RichOutput with no args"""
72 76 rich = capture.RichOutput()
73 for method, mime in _mime_map.items():
74 yield nt.assert_equal, getattr(rich, method)(), None
77 method, mime = method_mime
78 nt.assert_equal(getattr(rich, method)(), None)
75 79
76 80 def test_rich_output():
77 81 """test RichOutput basics"""
78 82 data = basic_data
79 83 metadata = basic_metadata
80 84 rich = capture.RichOutput(data=data, metadata=metadata)
81 yield nt.assert_equal, rich._repr_html_(), data['text/html']
82 yield nt.assert_equal, rich._repr_png_(), (data['image/png'], metadata['image/png'])
83 yield nt.assert_equal, rich._repr_latex_(), None
84 yield nt.assert_equal, rich._repr_javascript_(), None
85 yield nt.assert_equal, rich._repr_svg_(), None
85 nt.assert_equal(rich._repr_html_(), data["text/html"])
86 nt.assert_equal(rich._repr_png_(), (data["image/png"], metadata["image/png"]))
87 nt.assert_equal(rich._repr_latex_(), None)
88 nt.assert_equal(rich._repr_javascript_(), None)
89 nt.assert_equal(rich._repr_svg_(), None)
86 90
87 def test_rich_output_no_metadata():
91
92 @skip_iptest_but_not_pytest
93 @pytest.mark.parametrize("method_mime", _mime_map.items())
94 def test_rich_output_no_metadata(method_mime):
88 95 """test RichOutput with no metadata"""
89 96 data = full_data
90 97 rich = capture.RichOutput(data=data)
91 for method, mime in _mime_map.items():
92 yield nt.assert_equal, getattr(rich, method)(), data[mime]
98 method, mime = method_mime
99 nt.assert_equal(getattr(rich, method)(), data[mime])
100
93 101
94 def test_rich_output_metadata():
102 @skip_iptest_but_not_pytest
103 @pytest.mark.parametrize("method_mime", _mime_map.items())
104 def test_rich_output_metadata(method_mime):
95 105 """test RichOutput with metadata"""
96 106 data = full_data
97 107 metadata = full_metadata
98 108 rich = capture.RichOutput(data=data, metadata=metadata)
99 for method, mime in _mime_map.items():
100 yield nt.assert_equal, getattr(rich, method)(), (data[mime], metadata[mime])
109 method, mime = method_mime
110 nt.assert_equal(getattr(rich, method)(), (data[mime], metadata[mime]))
101 111
102 112 def test_rich_output_display():
103 113 """test RichOutput.display
@@ -109,10 +119,10 b' def test_rich_output_display():'
109 119 rich = capture.RichOutput(data=data)
110 120 with capture.capture_output() as cap:
111 121 rich.display()
112 yield nt.assert_equal, len(cap.outputs), 1
122 nt.assert_equal(len(cap.outputs), 1)
113 123 rich2 = cap.outputs[0]
114 yield nt.assert_equal, rich2.data, rich.data
115 yield nt.assert_equal, rich2.metadata, rich.metadata
124 nt.assert_equal(rich2.data, rich.data)
125 nt.assert_equal(rich2.metadata, rich.metadata)
116 126
117 127 def test_capture_output():
118 128 """capture_output works"""
@@ -121,8 +131,9 b' def test_capture_output():'
121 131 print(hello_stdout, end="")
122 132 print(hello_stderr, end="", file=sys.stderr)
123 133 rich.display()
124 yield nt.assert_equal, hello_stdout, cap.stdout
125 yield nt.assert_equal, hello_stderr, cap.stderr
134 nt.assert_equal(hello_stdout, cap.stdout)
135 nt.assert_equal(hello_stderr, cap.stderr)
136
126 137
127 138 def test_capture_output_no_stdout():
128 139 """test capture_output(stdout=False)"""
@@ -131,9 +142,10 b' def test_capture_output_no_stdout():'
131 142 print(hello_stdout, end="")
132 143 print(hello_stderr, end="", file=sys.stderr)
133 144 rich.display()
134 yield nt.assert_equal, "", cap.stdout
135 yield nt.assert_equal, hello_stderr, cap.stderr
136 yield nt.assert_equal, len(cap.outputs), 1
145 nt.assert_equal("", cap.stdout)
146 nt.assert_equal(hello_stderr, cap.stderr)
147 nt.assert_equal(len(cap.outputs), 1)
148
137 149
138 150 def test_capture_output_no_stderr():
139 151 """test capture_output(stderr=False)"""
@@ -143,9 +155,10 b' def test_capture_output_no_stderr():'
143 155 print(hello_stdout, end="")
144 156 print(hello_stderr, end="", file=sys.stderr)
145 157 rich.display()
146 yield nt.assert_equal, hello_stdout, cap.stdout
147 yield nt.assert_equal, "", cap.stderr
148 yield nt.assert_equal, len(cap.outputs), 1
158 nt.assert_equal(hello_stdout, cap.stdout)
159 nt.assert_equal("", cap.stderr)
160 nt.assert_equal(len(cap.outputs), 1)
161
149 162
150 163 def test_capture_output_no_display():
151 164 """test capture_output(display=False)"""
@@ -154,6 +167,6 b' def test_capture_output_no_display():'
154 167 print(hello_stdout, end="")
155 168 print(hello_stderr, end="", file=sys.stderr)
156 169 rich.display()
157 yield nt.assert_equal, hello_stdout, cap.stdout
158 yield nt.assert_equal, hello_stderr, cap.stderr
159 yield nt.assert_equal, cap.outputs, [] No newline at end of file
170 nt.assert_equal(hello_stdout, cap.stdout)
171 nt.assert_equal(hello_stderr, cap.stderr)
172 nt.assert_equal(cap.outputs, [])
@@ -20,15 +20,23 b' Authors'
20 20 # third party
21 21 import nose.tools as nt
22 22
23 from IPython.testing.decorators import skip_iptest_but_not_pytest
24
23 25 # our own
24 26 from IPython.utils.PyColorize import Parser
25 27 import io
28 import pytest
29
30
31 @pytest.fixture(scope="module", params=("Linux", "NoColor", "LightBG", "Neutral"))
32 def style(request):
33 yield request.param
26 34
27 35 #-----------------------------------------------------------------------------
28 36 # Test functions
29 37 #-----------------------------------------------------------------------------
30 38
31 sample = u"""
39 sample = """
32 40 def function(arg, *args, kwarg=True, **kwargs):
33 41 '''
34 42 this is docs
@@ -47,17 +55,9 b' class Bar(Super):'
47 55 super(Bar, self).__init__(1**2, 3^4, 5 or 6)
48 56 """
49 57
50 def test_loop_colors():
51
52 for style in ('Linux', 'NoColor','LightBG', 'Neutral'):
53 58
54 def test_unicode_colorize():
55 p = Parser(style=style)
56 f1 = p.format('1/0', 'str')
57 f2 = p.format(u'1/0', 'str')
58 nt.assert_equal(f1, f2)
59
60 def test_parse_sample():
59 @skip_iptest_but_not_pytest
60 def test_parse_sample(style):
61 61 """and test writing to a buffer"""
62 62 buf = io.StringIO()
63 63 p = Parser(style=style)
@@ -65,14 +65,12 b' def test_loop_colors():'
65 65 buf.seek(0)
66 66 f1 = buf.read()
67 67
68 nt.assert_not_in('ERROR', f1)
68 nt.assert_not_in("ERROR", f1)
69 69
70 def test_parse_error():
71 p = Parser(style=style)
72 f1 = p.format(')', 'str')
73 if style != 'NoColor':
74 nt.assert_in('ERROR', f1)
75 70
76 yield test_unicode_colorize
77 yield test_parse_sample
78 yield test_parse_error
71 @skip_iptest_but_not_pytest
72 def test_parse_error(style):
73 p = Parser(style=style)
74 f1 = p.format(")", "str")
75 if style != "NoColor":
76 nt.assert_in("ERROR", f1)
@@ -3,6 +3,8 b''
3 3 # Distributed under the terms of the Modified BSD License.
4 4
5 5 import nose.tools as nt
6 import pytest
7 from IPython.testing.decorators import skip_iptest_but_not_pytest
6 8
7 9 from IPython.utils.tokenutil import token_at_cursor, line_at_cursor
8 10
@@ -120,14 +122,20 b' def test_line_at_cursor():'
120 122 nt.assert_equal(line, "pri")
121 123 nt.assert_equal(offset, 4)
122 124
123 def test_multiline_statement():
125
126 @pytest.mark.parametrize(
127 "c, token",
128 zip(
129 list(range(16, 22)) + list(range(22, 28)),
130 ["int"] * (22 - 16) + ["map"] * (28 - 22),
131 ),
132 )
133 @skip_iptest_but_not_pytest
134 def test_multiline_statement(c, token):
124 135 cell = """a = (1,
125 136 3)
126 137
127 138 int()
128 139 map()
129 140 """
130 for c in range(16, 22):
131 yield lambda cell, c: expect_token("int", cell, c), cell, c
132 for c in range(22, 28):
133 yield lambda cell, c: expect_token("map", cell, c), cell, c
141 expect_token(token, cell, c)
@@ -23,7 +23,7 b' init:'
23 23 install:
24 24 - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
25 25 - "%CMD_IN_ENV% python -m pip install --upgrade setuptools pip"
26 - "%CMD_IN_ENV% pip install nose coverage"
26 - "%CMD_IN_ENV% pip install nose coverage pytest"
27 27 - "%CMD_IN_ENV% pip install .[test]"
28 28 - "%CMD_IN_ENV% mkdir results"
29 29 - "%CMD_IN_ENV% cd results"
General Comments 0
You need to be logged in to leave comments. Login now