Show More
@@ -1,91 +1,91 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Module with tests for ansi filters |
|
2 | Module with tests for ansi filters | |
3 | """ |
|
3 | """ | |
4 |
|
4 | |||
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 |
|
16 | |||
17 | from IPython.utils.coloransi import TermColors |
|
17 | from IPython.utils.coloransi import TermColors | |
18 |
|
18 | |||
19 | from ...tests.base import TestsBase |
|
19 | from ...tests.base import TestsBase | |
20 | from ..ansi import * |
|
20 | from ..ansi import strip_ansi, ansi2html, ansi2latex | |
21 |
|
21 | |||
22 |
|
22 | |||
23 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
24 | # Class |
|
24 | # Class | |
25 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
26 |
|
26 | |||
27 | class TestAnsi(TestsBase): |
|
27 | class TestAnsi(TestsBase): | |
28 | """Contains test functions for ansi.py""" |
|
28 | """Contains test functions for ansi.py""" | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | def test_strip_ansi(self): |
|
31 | def test_strip_ansi(self): | |
32 | """ |
|
32 | """ | |
33 | strip_ansi test |
|
33 | strip_ansi test | |
34 | """ |
|
34 | """ | |
35 | correct_outputs = { |
|
35 | correct_outputs = { | |
36 | '%s%s%s' % (TermColors.Green, TermColors.White, TermColors.Red) : '', |
|
36 | '%s%s%s' % (TermColors.Green, TermColors.White, TermColors.Red) : '', | |
37 | 'hello%s' % TermColors.Blue: 'hello', |
|
37 | 'hello%s' % TermColors.Blue: 'hello', | |
38 | 'he%s%sllo' % (TermColors.Yellow, TermColors.Cyan) : 'hello', |
|
38 | 'he%s%sllo' % (TermColors.Yellow, TermColors.Cyan) : 'hello', | |
39 | '%shello' % TermColors.Blue : 'hello', |
|
39 | '%shello' % TermColors.Blue : 'hello', | |
40 | '{0}h{0}e{0}l{0}l{0}o{0}'.format(TermColors.Red) : 'hello', |
|
40 | '{0}h{0}e{0}l{0}l{0}o{0}'.format(TermColors.Red) : 'hello', | |
41 | 'hel%slo' % TermColors.Green : 'hello', |
|
41 | 'hel%slo' % TermColors.Green : 'hello', | |
42 | 'hello' : 'hello'} |
|
42 | 'hello' : 'hello'} | |
43 |
|
43 | |||
44 | for inval, outval in correct_outputs.items(): |
|
44 | for inval, outval in correct_outputs.items(): | |
45 | yield self._try_strip_ansi, inval, outval |
|
45 | yield self._try_strip_ansi, inval, outval | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | def _try_strip_ansi(self, inval, outval): |
|
48 | def _try_strip_ansi(self, inval, outval): | |
49 | assert outval == strip_ansi(inval) |
|
49 | assert outval == strip_ansi(inval) | |
50 |
|
50 | |||
51 |
|
51 | |||
52 | def test_ansi2html(self): |
|
52 | def test_ansi2html(self): | |
53 | """ |
|
53 | """ | |
54 | ansi2html test |
|
54 | ansi2html test | |
55 | """ |
|
55 | """ | |
56 | correct_outputs = { |
|
56 | correct_outputs = { | |
57 | '%s' % (TermColors.Red) : '<span class="ansired"></span>', |
|
57 | '%s' % (TermColors.Red) : '<span class="ansired"></span>', | |
58 | 'hello%s' % TermColors.Blue: 'hello<span class="ansiblue"></span>', |
|
58 | 'hello%s' % TermColors.Blue: 'hello<span class="ansiblue"></span>', | |
59 | 'he%s%sllo' % (TermColors.Green, TermColors.Cyan) : 'he<span class="ansigreen"></span><span class="ansicyan">llo</span>', |
|
59 | 'he%s%sllo' % (TermColors.Green, TermColors.Cyan) : 'he<span class="ansigreen"></span><span class="ansicyan">llo</span>', | |
60 | '%shello' % TermColors.Yellow : '<span class="ansiyellow">hello</span>', |
|
60 | '%shello' % TermColors.Yellow : '<span class="ansiyellow">hello</span>', | |
61 | '{0}h{0}e{0}l{0}l{0}o{0}'.format(TermColors.White) : '<span class="ansigrey">h</span><span class="ansigrey">e</span><span class="ansigrey">l</span><span class="ansigrey">l</span><span class="ansigrey">o</span><span class="ansigrey"></span>', |
|
61 | '{0}h{0}e{0}l{0}l{0}o{0}'.format(TermColors.White) : '<span class="ansigrey">h</span><span class="ansigrey">e</span><span class="ansigrey">l</span><span class="ansigrey">l</span><span class="ansigrey">o</span><span class="ansigrey"></span>', | |
62 | 'hel%slo' % TermColors.Green : 'hel<span class="ansigreen">lo</span>', |
|
62 | 'hel%slo' % TermColors.Green : 'hel<span class="ansigreen">lo</span>', | |
63 | 'hello' : 'hello'} |
|
63 | 'hello' : 'hello'} | |
64 |
|
64 | |||
65 | for inval, outval in correct_outputs.items(): |
|
65 | for inval, outval in correct_outputs.items(): | |
66 | yield self._try_ansi2html, inval, outval |
|
66 | yield self._try_ansi2html, inval, outval | |
67 |
|
67 | |||
68 |
|
68 | |||
69 | def _try_ansi2html(self, inval, outval): |
|
69 | def _try_ansi2html(self, inval, outval): | |
70 | self.fuzzy_compare(outval, ansi2html(inval)) |
|
70 | self.fuzzy_compare(outval, ansi2html(inval)) | |
71 |
|
71 | |||
72 |
|
72 | |||
73 | def test_ansi2latex(self): |
|
73 | def test_ansi2latex(self): | |
74 | """ |
|
74 | """ | |
75 | ansi2latex test |
|
75 | ansi2latex test | |
76 | """ |
|
76 | """ | |
77 | correct_outputs = { |
|
77 | correct_outputs = { | |
78 | '%s' % (TermColors.Red) : r'\red{}', |
|
78 | '%s' % (TermColors.Red) : r'\red{}', | |
79 | 'hello%s' % TermColors.Blue: r'hello\blue{}', |
|
79 | 'hello%s' % TermColors.Blue: r'hello\blue{}', | |
80 | 'he%s%sllo' % (TermColors.Green, TermColors.Cyan) : r'he\green{}\cyan{llo}', |
|
80 | 'he%s%sllo' % (TermColors.Green, TermColors.Cyan) : r'he\green{}\cyan{llo}', | |
81 | '%shello' % TermColors.Yellow : r'\yellow{hello}', |
|
81 | '%shello' % TermColors.Yellow : r'\yellow{hello}', | |
82 | '{0}h{0}e{0}l{0}l{0}o{0}'.format(TermColors.White) : r'\white{h}\white{e}\white{l}\white{l}\white{o}\white{}', |
|
82 | '{0}h{0}e{0}l{0}l{0}o{0}'.format(TermColors.White) : r'\white{h}\white{e}\white{l}\white{l}\white{o}\white{}', | |
83 | 'hel%slo' % TermColors.Green : r'hel\green{lo}', |
|
83 | 'hel%slo' % TermColors.Green : r'hel\green{lo}', | |
84 | 'hello' : 'hello'} |
|
84 | 'hello' : 'hello'} | |
85 |
|
85 | |||
86 | for inval, outval in correct_outputs.items(): |
|
86 | for inval, outval in correct_outputs.items(): | |
87 | yield self._try_ansi2latex, inval, outval |
|
87 | yield self._try_ansi2latex, inval, outval | |
88 |
|
88 | |||
89 |
|
89 | |||
90 | def _try_ansi2latex(self, inval, outval): |
|
90 | def _try_ansi2latex(self, inval, outval): | |
91 | self.fuzzy_compare(outval, ansi2latex(inval), case_sensitive=True) |
|
91 | self.fuzzy_compare(outval, ansi2latex(inval), case_sensitive=True) |
@@ -1,72 +1,72 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Module with tests for Highlight |
|
2 | Module with tests for Highlight | |
3 | """ |
|
3 | """ | |
4 |
|
4 | |||
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 |
|
16 | |||
17 |
|
17 | |||
18 | from ...tests.base import TestsBase |
|
18 | from ...tests.base import TestsBase | |
19 |
from ..highlight import |
|
19 | from ..highlight import highlight2html, highlight2latex | |
20 |
|
20 | |||
21 |
|
21 | |||
22 | #----------------------------------------------------------------------------- |
|
22 | #----------------------------------------------------------------------------- | |
23 | # Class |
|
23 | # Class | |
24 | #----------------------------------------------------------------------------- |
|
24 | #----------------------------------------------------------------------------- | |
25 |
|
25 | |||
26 | class TestHighlight(TestsBase): |
|
26 | class TestHighlight(TestsBase): | |
27 | """Contains test functions for highlight.py""" |
|
27 | """Contains test functions for highlight.py""" | |
28 |
|
28 | |||
29 | #Hello world test, magics test, blank string test |
|
29 | #Hello world test, magics test, blank string test | |
30 | tests = [ |
|
30 | tests = [ | |
31 | """ |
|
31 | """ | |
32 | #Hello World Example |
|
32 | #Hello World Example | |
33 |
|
33 | |||
34 | def say(text): |
|
34 | def say(text): | |
35 | print(text) |
|
35 | print(text) | |
36 |
|
36 | |||
37 | say('Hello World!') |
|
37 | say('Hello World!') | |
38 | """, |
|
38 | """, | |
39 | """ |
|
39 | """ | |
40 | %%pylab |
|
40 | %%pylab | |
41 | plot(x,y, 'r') |
|
41 | plot(x,y, 'r') | |
42 | """ |
|
42 | """ | |
43 | ] |
|
43 | ] | |
44 |
|
44 | |||
45 | tokens = [ |
|
45 | tokens = [ | |
46 | ['Hello World Example', 'say', 'text', 'print', 'def'], |
|
46 | ['Hello World Example', 'say', 'text', 'print', 'def'], | |
47 | ['pylab', 'plot']] |
|
47 | ['pylab', 'plot']] | |
48 |
|
48 | |||
49 |
|
49 | |||
50 | def test_highlight2html(self): |
|
50 | def test_highlight2html(self): | |
51 | """ |
|
51 | """ | |
52 | highlight2html test |
|
52 | highlight2html test | |
53 | """ |
|
53 | """ | |
54 | for index, test in enumerate(self.tests): |
|
54 | for index, test in enumerate(self.tests): | |
55 | yield self._try_highlight, highlight2html, test, self.tokens[index] |
|
55 | yield self._try_highlight, highlight2html, test, self.tokens[index] | |
56 |
|
56 | |||
57 |
|
57 | |||
58 | def test_highlight2latex(self): |
|
58 | def test_highlight2latex(self): | |
59 | """ |
|
59 | """ | |
60 | highlight2latex test |
|
60 | highlight2latex test | |
61 | """ |
|
61 | """ | |
62 | for index, test in enumerate(self.tests): |
|
62 | for index, test in enumerate(self.tests): | |
63 | yield self._try_highlight, highlight2latex, test, self.tokens[index] |
|
63 | yield self._try_highlight, highlight2latex, test, self.tokens[index] | |
64 |
|
64 | |||
65 |
|
65 | |||
66 | def _try_highlight(self, method, test, tokens): |
|
66 | def _try_highlight(self, method, test, tokens): | |
67 | """ |
|
67 | """ | |
68 | Try highlighting source, look for key tokens |
|
68 | Try highlighting source, look for key tokens | |
69 | """ |
|
69 | """ | |
70 | results = method(test) |
|
70 | results = method(test) | |
71 | for token in tokens: |
|
71 | for token in tokens: | |
72 | assert token in results |
|
72 | assert token in results |
@@ -1,72 +1,72 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Module with tests for Latex |
|
2 | Module with tests for Latex | |
3 | """ |
|
3 | """ | |
4 |
|
4 | |||
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 |
|
16 | |||
17 |
|
17 | |||
18 | from ...tests.base import TestsBase |
|
18 | from ...tests.base import TestsBase | |
19 | from ..latex import * |
|
19 | from ..latex import escape_latex, strip_math_space | |
20 |
|
20 | |||
21 |
|
21 | |||
22 | #----------------------------------------------------------------------------- |
|
22 | #----------------------------------------------------------------------------- | |
23 | # Class |
|
23 | # Class | |
24 | #----------------------------------------------------------------------------- |
|
24 | #----------------------------------------------------------------------------- | |
25 |
|
25 | |||
26 | class TestLatex(TestsBase): |
|
26 | class TestLatex(TestsBase): | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | def test_escape_latex(self): |
|
29 | def test_escape_latex(self): | |
30 | """ |
|
30 | """ | |
31 | escape_latex test |
|
31 | escape_latex test | |
32 | """ |
|
32 | """ | |
33 | tests = [ |
|
33 | tests = [ | |
34 | (r'How are \you doing today?', r'How are \textbackslashyou doing today?'), |
|
34 | (r'How are \you doing today?', r'How are \textbackslashyou doing today?'), | |
35 | (r'\escapechar=`\A\catcode`\|=0 |string|foo', r'\textbackslashescapechar=`\textbackslashA\textbackslashcatcode`\textbackslash|=0 |string|foo'), |
|
35 | (r'\escapechar=`\A\catcode`\|=0 |string|foo', r'\textbackslashescapechar=`\textbackslashA\textbackslashcatcode`\textbackslash|=0 |string|foo'), | |
36 | (r'# $ % & ~ _ ^ \ { }',r'\# \$ \% \& \~{} \_ \^{} \textbackslash \{ \}'), |
|
36 | (r'# $ % & ~ _ ^ \ { }',r'\# \$ \% \& \~{} \_ \^{} \textbackslash \{ \}'), | |
37 | ('','')] |
|
37 | ('','')] | |
38 |
|
38 | |||
39 | for test in tests: |
|
39 | for test in tests: | |
40 | yield self._try_escape_latex, test[0], test[1] |
|
40 | yield self._try_escape_latex, test[0], test[1] | |
41 |
|
41 | |||
42 |
|
42 | |||
43 | def _try_escape_latex(self, test, result): |
|
43 | def _try_escape_latex(self, test, result): | |
44 | """ |
|
44 | """ | |
45 | Try to remove latex from string |
|
45 | Try to remove latex from string | |
46 | """ |
|
46 | """ | |
47 | assert escape_latex(test) == result |
|
47 | assert escape_latex(test) == result | |
48 |
|
48 | |||
49 |
|
49 | |||
50 | def test_strip_math_space(self): |
|
50 | def test_strip_math_space(self): | |
51 | """ |
|
51 | """ | |
52 | strip_math_space test |
|
52 | strip_math_space test | |
53 | """ |
|
53 | """ | |
54 | tests = [ |
|
54 | tests = [ | |
55 | ('$e$','$e$'), |
|
55 | ('$e$','$e$'), | |
56 | ('$ e $','$e$'), |
|
56 | ('$ e $','$e$'), | |
57 | ('xxx$e^i$yyy','xxx$e^i$yyy'), |
|
57 | ('xxx$e^i$yyy','xxx$e^i$yyy'), | |
58 | ('xxx$ e^i $yyy','xxx$e^i$yyy'), |
|
58 | ('xxx$ e^i $yyy','xxx$e^i$yyy'), | |
59 | ('xxx$e^i $yyy','xxx$e^i$yyy'), |
|
59 | ('xxx$e^i $yyy','xxx$e^i$yyy'), | |
60 | ('xxx$ e^i$yyy','xxx$e^i$yyy'), |
|
60 | ('xxx$ e^i$yyy','xxx$e^i$yyy'), | |
61 | ('\$ e $ e $','\$ e $e$'), |
|
61 | ('\$ e $ e $','\$ e $e$'), | |
62 | ('','')] |
|
62 | ('','')] | |
63 |
|
63 | |||
64 | for test in tests: |
|
64 | for test in tests: | |
65 | yield self._try_strip_math_space, test[0], test[1] |
|
65 | yield self._try_strip_math_space, test[0], test[1] | |
66 |
|
66 | |||
67 |
|
67 | |||
68 | def _try_strip_math_space(self, test, result): |
|
68 | def _try_strip_math_space(self, test, result): | |
69 | """ |
|
69 | """ | |
70 | Try to remove spaces between dollar symbols and contents correctly |
|
70 | Try to remove spaces between dollar symbols and contents correctly | |
71 | """ |
|
71 | """ | |
72 | assert strip_math_space(test) == result |
|
72 | assert strip_math_space(test) == result |
@@ -1,99 +1,99 b'' | |||||
1 |
|
1 | |||
2 | """ |
|
2 | """ | |
3 | Module with tests for Markdown |
|
3 | Module with tests for Markdown | |
4 | """ |
|
4 | """ | |
5 |
|
5 | |||
6 | #----------------------------------------------------------------------------- |
|
6 | #----------------------------------------------------------------------------- | |
7 | # Copyright (c) 2013, the IPython Development Team. |
|
7 | # Copyright (c) 2013, the IPython Development Team. | |
8 | # |
|
8 | # | |
9 | # Distributed under the terms of the Modified BSD License. |
|
9 | # Distributed under the terms of the Modified BSD License. | |
10 | # |
|
10 | # | |
11 | # The full license is in the file COPYING.txt, distributed with this software. |
|
11 | # The full license is in the file COPYING.txt, distributed with this software. | |
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 |
|
13 | |||
14 | #----------------------------------------------------------------------------- |
|
14 | #----------------------------------------------------------------------------- | |
15 | # Imports |
|
15 | # Imports | |
16 | #----------------------------------------------------------------------------- |
|
16 | #----------------------------------------------------------------------------- | |
17 |
|
17 | |||
18 | from copy import copy |
|
18 | from copy import copy | |
19 |
|
19 | |||
20 | from IPython.testing.decorators import onlyif_cmds_exist |
|
20 | from IPython.testing.decorators import onlyif_cmds_exist | |
21 | from IPython.utils.py3compat import string_types |
|
21 | from IPython.utils.py3compat import string_types | |
22 |
|
22 | |||
23 | from ...tests.base import TestsBase |
|
23 | from ...tests.base import TestsBase | |
24 | from ..markdown import * |
|
24 | from ..markdown import markdown2latex, markdown2html, markdown2rst | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | #----------------------------------------------------------------------------- |
|
27 | #----------------------------------------------------------------------------- | |
28 | # Class |
|
28 | # Class | |
29 | #----------------------------------------------------------------------------- |
|
29 | #----------------------------------------------------------------------------- | |
30 |
|
30 | |||
31 | class TestMarkdown(TestsBase): |
|
31 | class TestMarkdown(TestsBase): | |
32 |
|
32 | |||
33 | tests = [ |
|
33 | tests = [ | |
34 | '*test', |
|
34 | '*test', | |
35 | '**test', |
|
35 | '**test', | |
36 | '*test*', |
|
36 | '*test*', | |
37 | '_test_', |
|
37 | '_test_', | |
38 | '__test__', |
|
38 | '__test__', | |
39 | '__*test*__', |
|
39 | '__*test*__', | |
40 | '**test**', |
|
40 | '**test**', | |
41 | '#test', |
|
41 | '#test', | |
42 | '##test', |
|
42 | '##test', | |
43 | 'test\n----', |
|
43 | 'test\n----', | |
44 | 'test [link](https://google.com/)'] |
|
44 | 'test [link](https://google.com/)'] | |
45 |
|
45 | |||
46 | tokens = [ |
|
46 | tokens = [ | |
47 | '*test', |
|
47 | '*test', | |
48 | '**test', |
|
48 | '**test', | |
49 | 'test', |
|
49 | 'test', | |
50 | 'test', |
|
50 | 'test', | |
51 | 'test', |
|
51 | 'test', | |
52 | 'test', |
|
52 | 'test', | |
53 | 'test', |
|
53 | 'test', | |
54 | 'test', |
|
54 | 'test', | |
55 | 'test', |
|
55 | 'test', | |
56 | 'test', |
|
56 | 'test', | |
57 | ('test', 'https://google.com/')] |
|
57 | ('test', 'https://google.com/')] | |
58 |
|
58 | |||
59 |
|
59 | |||
60 | @onlyif_cmds_exist('pandoc') |
|
60 | @onlyif_cmds_exist('pandoc') | |
61 | def test_markdown2latex(self): |
|
61 | def test_markdown2latex(self): | |
62 | """ |
|
62 | """ | |
63 | markdown2latex test |
|
63 | markdown2latex test | |
64 | """ |
|
64 | """ | |
65 | for index, test in enumerate(self.tests): |
|
65 | for index, test in enumerate(self.tests): | |
66 | yield self._try_markdown, markdown2latex, test, self.tokens[index] |
|
66 | yield self._try_markdown, markdown2latex, test, self.tokens[index] | |
67 |
|
67 | |||
68 |
|
68 | |||
69 | @onlyif_cmds_exist('pandoc') |
|
69 | @onlyif_cmds_exist('pandoc') | |
70 | def test_markdown2html(self): |
|
70 | def test_markdown2html(self): | |
71 | """ |
|
71 | """ | |
72 | markdown2html test |
|
72 | markdown2html test | |
73 | """ |
|
73 | """ | |
74 | for index, test in enumerate(self.tests): |
|
74 | for index, test in enumerate(self.tests): | |
75 | yield self._try_markdown, markdown2html, test, self.tokens[index] |
|
75 | yield self._try_markdown, markdown2html, test, self.tokens[index] | |
76 |
|
76 | |||
77 |
|
77 | |||
78 | @onlyif_cmds_exist('pandoc') |
|
78 | @onlyif_cmds_exist('pandoc') | |
79 | def test_markdown2rst(self): |
|
79 | def test_markdown2rst(self): | |
80 | """ |
|
80 | """ | |
81 | markdown2rst test |
|
81 | markdown2rst test | |
82 | """ |
|
82 | """ | |
83 |
|
83 | |||
84 | #Modify token array for rst, escape asterik |
|
84 | #Modify token array for rst, escape asterik | |
85 | tokens = copy(self.tokens) |
|
85 | tokens = copy(self.tokens) | |
86 | tokens[0] = r'\*test' |
|
86 | tokens[0] = r'\*test' | |
87 | tokens[1] = r'\*\*test' |
|
87 | tokens[1] = r'\*\*test' | |
88 |
|
88 | |||
89 | for index, test in enumerate(self.tests): |
|
89 | for index, test in enumerate(self.tests): | |
90 | yield self._try_markdown, markdown2rst, test, tokens[index] |
|
90 | yield self._try_markdown, markdown2rst, test, tokens[index] | |
91 |
|
91 | |||
92 |
|
92 | |||
93 | def _try_markdown(self, method, test, tokens): |
|
93 | def _try_markdown(self, method, test, tokens): | |
94 | results = method(test) |
|
94 | results = method(test) | |
95 | if isinstance(tokens, string_types): |
|
95 | if isinstance(tokens, string_types): | |
96 | assert tokens in results |
|
96 | assert tokens in results | |
97 | else: |
|
97 | else: | |
98 | for token in tokens: |
|
98 | for token in tokens: | |
99 | assert token in results |
|
99 | assert token in results |
@@ -1,131 +1,132 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Module with tests for Strings |
|
2 | Module with tests for Strings | |
3 | """ |
|
3 | """ | |
4 |
|
4 | |||
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 |
|
16 | |||
17 | from ...tests.base import TestsBase |
|
17 | from ...tests.base import TestsBase | |
18 | from ..strings import * |
|
18 | from ..strings import wrap_text, html2text, add_anchor, strip_dollars, | |
|
19 | strip_files_prefix, get_lines, comment_lines, ipython2python | |||
19 |
|
20 | |||
20 |
|
21 | |||
21 | #----------------------------------------------------------------------------- |
|
22 | #----------------------------------------------------------------------------- | |
22 | # Class |
|
23 | # Class | |
23 | #----------------------------------------------------------------------------- |
|
24 | #----------------------------------------------------------------------------- | |
24 |
|
25 | |||
25 | class TestStrings(TestsBase): |
|
26 | class TestStrings(TestsBase): | |
26 |
|
27 | |||
27 | def test_wrap_text(self): |
|
28 | def test_wrap_text(self): | |
28 | """ |
|
29 | """ | |
29 | wrap_text test |
|
30 | wrap_text test | |
30 | """ |
|
31 | """ | |
31 | test_text = """ |
|
32 | test_text = """ | |
32 | Tush! never tell me; I take it much unkindly |
|
33 | Tush! never tell me; I take it much unkindly | |
33 | That thou, Iago, who hast had my purse |
|
34 | That thou, Iago, who hast had my purse | |
34 | As if the strings were thine, shouldst know of this. |
|
35 | As if the strings were thine, shouldst know of this. | |
35 | """ |
|
36 | """ | |
36 | for length in [30,5,1]: |
|
37 | for length in [30,5,1]: | |
37 | yield self._confirm_wrap_text, test_text, length |
|
38 | yield self._confirm_wrap_text, test_text, length | |
38 |
|
39 | |||
39 | def _confirm_wrap_text(self, text, length): |
|
40 | def _confirm_wrap_text(self, text, length): | |
40 | for line in wrap_text(text, length).split('\n'): |
|
41 | for line in wrap_text(text, length).split('\n'): | |
41 | assert len(line) <= length |
|
42 | assert len(line) <= length | |
42 |
|
43 | |||
43 | def test_html2text(self): |
|
44 | def test_html2text(self): | |
44 | """ |
|
45 | """ | |
45 | html2text test |
|
46 | html2text test | |
46 | """ |
|
47 | """ | |
47 | #TODO: More tests |
|
48 | #TODO: More tests | |
48 | assert html2text('<name>joe</name>') == 'joe' |
|
49 | assert html2text('<name>joe</name>') == 'joe' | |
49 |
|
50 | |||
50 |
|
51 | |||
51 | def test_add_anchor(self): |
|
52 | def test_add_anchor(self): | |
52 | """ |
|
53 | """ | |
53 | add_anchor test |
|
54 | add_anchor test | |
54 | """ |
|
55 | """ | |
55 | #TODO: More tests |
|
56 | #TODO: More tests | |
56 | results = add_anchor('<b>Hello World!</b>') |
|
57 | results = add_anchor('<b>Hello World!</b>') | |
57 | assert 'Hello World!' in results |
|
58 | assert 'Hello World!' in results | |
58 | assert 'id="' in results |
|
59 | assert 'id="' in results | |
59 | assert 'class="anchor-link"' in results |
|
60 | assert 'class="anchor-link"' in results | |
60 | assert '<b' in results |
|
61 | assert '<b' in results | |
61 | assert '</b>' in results |
|
62 | assert '</b>' in results | |
62 |
|
63 | |||
63 |
|
64 | |||
64 | def test_strip_dollars(self): |
|
65 | def test_strip_dollars(self): | |
65 | """ |
|
66 | """ | |
66 | strip_dollars test |
|
67 | strip_dollars test | |
67 | """ |
|
68 | """ | |
68 | tests = [ |
|
69 | tests = [ | |
69 | ('', ''), |
|
70 | ('', ''), | |
70 | ('$$', ''), |
|
71 | ('$$', ''), | |
71 | ('$H$', 'H'), |
|
72 | ('$H$', 'H'), | |
72 | ('$He', 'He'), |
|
73 | ('$He', 'He'), | |
73 | ('H$el', 'H$el'), |
|
74 | ('H$el', 'H$el'), | |
74 | ('Hell$', 'Hell'), |
|
75 | ('Hell$', 'Hell'), | |
75 | ('Hello', 'Hello'), |
|
76 | ('Hello', 'Hello'), | |
76 | ('W$o$rld', 'W$o$rld')] |
|
77 | ('W$o$rld', 'W$o$rld')] | |
77 | for test in tests: |
|
78 | for test in tests: | |
78 | yield self._try_strip_dollars, test[0], test[1] |
|
79 | yield self._try_strip_dollars, test[0], test[1] | |
79 |
|
80 | |||
80 |
|
81 | |||
81 | def _try_strip_dollars(self, test, result): |
|
82 | def _try_strip_dollars(self, test, result): | |
82 | assert strip_dollars(test) == result |
|
83 | assert strip_dollars(test) == result | |
83 |
|
84 | |||
84 |
|
85 | |||
85 | def test_strip_files_prefix(self): |
|
86 | def test_strip_files_prefix(self): | |
86 | """ |
|
87 | """ | |
87 | strip_files_prefix test |
|
88 | strip_files_prefix test | |
88 | """ |
|
89 | """ | |
89 | tests = [ |
|
90 | tests = [ | |
90 | ('', ''), |
|
91 | ('', ''), | |
91 | ('/files', '/files'), |
|
92 | ('/files', '/files'), | |
92 | ('test="/files"', 'test="/files"'), |
|
93 | ('test="/files"', 'test="/files"'), | |
93 | ('My files are in `files/`', 'My files are in `files/`'), |
|
94 | ('My files are in `files/`', 'My files are in `files/`'), | |
94 | ('<a href="files/test.html">files/test.html</a>', '<a href="test.html">files/test.html</a>')] |
|
95 | ('<a href="files/test.html">files/test.html</a>', '<a href="test.html">files/test.html</a>')] | |
95 | for test in tests: |
|
96 | for test in tests: | |
96 | yield self._try_files_prefix, test[0], test[1] |
|
97 | yield self._try_files_prefix, test[0], test[1] | |
97 |
|
98 | |||
98 |
|
99 | |||
99 | def _try_files_prefix(self, test, result): |
|
100 | def _try_files_prefix(self, test, result): | |
100 | assert strip_files_prefix(test) == result |
|
101 | assert strip_files_prefix(test) == result | |
101 |
|
102 | |||
102 |
|
103 | |||
103 | def test_comment_lines(self): |
|
104 | def test_comment_lines(self): | |
104 | """ |
|
105 | """ | |
105 | comment_lines test |
|
106 | comment_lines test | |
106 | """ |
|
107 | """ | |
107 | for line in comment_lines('hello\nworld\n!').split('\n'): |
|
108 | for line in comment_lines('hello\nworld\n!').split('\n'): | |
108 | assert line.startswith('# ') |
|
109 | assert line.startswith('# ') | |
109 | for line in comment_lines('hello\nworld\n!', 'beep').split('\n'): |
|
110 | for line in comment_lines('hello\nworld\n!', 'beep').split('\n'): | |
110 | assert line.startswith('beep') |
|
111 | assert line.startswith('beep') | |
111 |
|
112 | |||
112 |
|
113 | |||
113 | def test_get_lines(self): |
|
114 | def test_get_lines(self): | |
114 | """ |
|
115 | """ | |
115 | get_lines test |
|
116 | get_lines test | |
116 | """ |
|
117 | """ | |
117 | text = "hello\nworld\n!" |
|
118 | text = "hello\nworld\n!" | |
118 | assert get_lines(text, start=1) == "world\n!" |
|
119 | assert get_lines(text, start=1) == "world\n!" | |
119 | assert get_lines(text, end=2) == "hello\nworld" |
|
120 | assert get_lines(text, end=2) == "hello\nworld" | |
120 | assert get_lines(text, start=2, end=5) == "!" |
|
121 | assert get_lines(text, start=2, end=5) == "!" | |
121 | assert get_lines(text, start=-2) == "world\n!" |
|
122 | assert get_lines(text, start=-2) == "world\n!" | |
122 |
|
123 | |||
123 |
|
124 | |||
124 | def test_ipython2python(self): |
|
125 | def test_ipython2python(self): | |
125 | """ |
|
126 | """ | |
126 | ipython2python test |
|
127 | ipython2python test | |
127 | """ |
|
128 | """ | |
128 | #TODO: More tests |
|
129 | #TODO: More tests | |
129 | results = ipython2python(u'%%pylab\nprint("Hello-World")').replace("u'", "'") |
|
130 | results = ipython2python(u'%%pylab\nprint("Hello-World")').replace("u'", "'") | |
130 | self.fuzzy_compare(results, u"get_ipython().run_cell_magic('pylab', '', 'print(\"Hello-World\")')", |
|
131 | self.fuzzy_compare(results, u"get_ipython().run_cell_magic('pylab', '', 'print(\"Hello-World\")')", | |
131 | ignore_spaces=True, ignore_newlines=True) |
|
132 | ignore_spaces=True, ignore_newlines=True) |
General Comments 0
You need to be logged in to leave comments.
Login now