Mercurial > jouvence
annotate tests/test_renderer.py @ 11:c6d28a830f68 0.1.0
Add PyPI support.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 04 Jan 2017 08:51:18 -0800 |
parents | 6019eee799bf |
children | ee741bbe96a8 |
rev | line source |
---|---|
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 import pytest |
3
6019eee799bf
Add base classes for rendering.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
2 from fontaine.renderer import BaseTextRenderer |
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 |
3
6019eee799bf
Add base classes for rendering.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
5 class TestTextRenderer(BaseTextRenderer): |
6019eee799bf
Add base classes for rendering.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
6 def make_bold(self, text): |
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 return 'B:' + text + ':B' |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 |
3
6019eee799bf
Add base classes for rendering.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
9 def make_italics(self, text): |
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 return 'I:' + text + ':I' |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 |
3
6019eee799bf
Add base classes for rendering.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
12 def make_underline(self, text): |
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 return 'U:' + text + ':U' |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 @pytest.mark.parametrize('intext, expected', [ |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 ("_Underline_", "U:Underline:U"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 ("Here's an _underline_.", "Here's an U:underline:U."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 ("Here's an _underline_ too", "Here's an U:underline:U too"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 ("This is not_underline_", "This is not_underline_"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 ("This is not _underline_either", "This is not _underline_either"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 ("This is _two underlined_ words.", "This is U:two underlined:U words."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 ("This is _three underlined words_.", |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 "This is U:three underlined words:U."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 ("This is an \_escaped_ one.", "This is an _escaped_ one.") |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 ]) |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 def test_underline(intext, expected): |
3
6019eee799bf
Add base classes for rendering.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
28 r = TestTextRenderer() |
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 out = r.render_text(intext) |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 assert out == expected |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
32 |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 @pytest.mark.parametrize('intext, expected', [ |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 ("*Italics*", "I:Italics:I"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 ("Here's some *italics*.", "Here's some I:italics:I."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 ("Here's some *italics* too", "Here's some I:italics:I too"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
37 ("This is not*italics*", "This is not*italics*"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
38 ("This is not *italics*either", "This is not *italics*either"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
39 ("This is *two italics* words.", "This is I:two italics:I words."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
40 ("This is *three italics words*.", |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
41 "This is I:three italics words:I."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
42 ("This is some \*escaped* one.", "This is some *escaped* one.") |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
43 ]) |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
44 def test_italics(intext, expected): |
3
6019eee799bf
Add base classes for rendering.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
45 r = TestTextRenderer() |
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
46 out = r.render_text(intext) |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
47 assert out == expected |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
48 |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
49 |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
50 @pytest.mark.parametrize('intext, expected', [ |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
51 ("**Bold**", "B:Bold:B"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
52 ("Here's some **bold**.", "Here's some B:bold:B."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
53 ("Here's some **bold** too", "Here's some B:bold:B too"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
54 ("This is not**bold**", "This is not**bold**"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
55 ("This is not **bold**either", "This is not **bold**either"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
56 ("This is **two bold** words.", "This is B:two bold:B words."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
57 ("This is **three bold words**.", |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
58 "This is B:three bold words:B."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
59 ("This is some \**escaped** one.", "This is some **escaped** one.") |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
60 ]) |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
61 def test_bold(intext, expected): |
3
6019eee799bf
Add base classes for rendering.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
62 r = TestTextRenderer() |
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
63 out = r.render_text(intext) |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
64 assert out == expected |