Mercurial > silorider
annotate tests/test_format.py @ 20:a45587268314
Add missing `ronkyuu` dependency.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 19 Jan 2019 17:35:10 -0800 |
parents | a921cc2306bc |
children | fb93d3fbff4e |
rev | line source |
---|---|
0 | 1 import pytest |
18
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
2 from silorider.format import format_entry, strip_html |
0 | 3 |
4 | |
5 test_url = 'https://example.org/article' | |
6 | |
7 | |
8 class TestEntry: | |
9 pass | |
10 | |
11 | |
12 def _make_test_entry(best_name, is_micropost): | |
13 entry = TestEntry() | |
18
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
14 entry.get = lambda n: best_name |
0 | 15 entry.is_micropost = is_micropost |
16 entry.url = test_url | |
17 return entry | |
18 | |
19 | |
18
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
20 @pytest.mark.parametrize("text, expected", [ |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
21 ("<p>Something</p>", |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
22 "Something"), |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
23 ("<p>Something with <em>emphasis</em> in it</p>", |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
24 "Something with emphasis in it"), |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
25 ("<p>Something with <a href=\"http://example.org/blah\">a link</a>", |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
26 "Something with a link http://example.org/blah"), |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
27 ("<p>Something with a link <a href=\"http://example.org/blah\">http://example.org</a>", # NOQA |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
28 "Something with a link http://example.org/blah"), |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
29 ("<p>Something with <a href=\"http://example.org/first\">one link here</a> and <a href=\"http://example.org/second\">another there</a>...</p>", # NOQA |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
30 "Something with one link here http://example.org/first and another there http://example.org/second...") # NOQA |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
31 ]) |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
32 def test_strip_html(text, expected): |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
33 actual = strip_html(text) |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
34 assert actual == expected |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
35 |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
36 |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
37 @pytest.mark.parametrize("text, expected", [ |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
38 ("<p>Something with <a href=\"http://example.org/blah\">a link</a>", |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
39 "Something with a link\nhttp://example.org/blah"), |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
40 ("<p>Something with a link <a href=\"http://example.org/blah\">http://example.org</a>", # NOQA |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
41 "Something with a link http://example.org/blah"), |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
42 ("<p>Something with <a href=\"http://example.org/first\">one link here</a> and <a href=\"http://example.org/second\">another there</a>...</p>", # NOQA |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
43 "Something with one link here and another there...\nhttp://example.org/first\nhttp://example.org/second") # NOQA |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
44 ]) |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
45 def test_strip_html_with_bottom_urls(text, expected): |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
46 actual = strip_html(text, inline_urls=False) |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
47 print(actual) |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
48 print(expected) |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
49 assert actual == expected |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
50 |
a921cc2306bc
Do our own HTML parsing/stripping of micropost contents.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
51 |
0 | 52 @pytest.mark.parametrize("title, limit, add_url, expected", [ |
53 ('A test entry', None, False, 'A test entry'), | |
54 ('A test entry', None, 'auto', 'A test entry ' + test_url), | |
55 ('A test entry', None, True, 'A test entry ' + test_url), | |
56 | |
57 ('A test entry', 80, False, 'A test entry'), | |
58 ('A test entry', 80, 'auto', 'A test entry ' + test_url), | |
59 ('A test entry', 80, True, 'A test entry ' + test_url), | |
60 | |
61 ('A test entry that is very very long because its title has many many ' | |
62 'words in it for no good reason', 80, False, | |
63 'A test entry that is very very long because its title has many many ' | |
64 'words in...'), | |
65 ('A test entry that is very very long because its title has many many ' | |
66 'words in it for no good reason', 80, 'auto', | |
67 'A test entry that is very very long because its... ' + test_url), | |
68 ('A test entry that is very very long because its title has many many ' | |
69 'words in it for no good reason', 80, True, | |
70 'A test entry that is very very long because its... ' + test_url) | |
71 ]) | |
72 def test_format_lonform_entry(title, limit, add_url, expected): | |
73 entry = _make_test_entry(title, False) | |
74 actual = format_entry(entry, limit, add_url) | |
75 assert actual == expected | |
76 | |
77 | |
78 @pytest.mark.parametrize("text, limit, add_url, expected", [ | |
79 ('A test entry', None, False, 'A test entry'), | |
80 ('A test entry', None, 'auto', 'A test entry'), | |
81 ('A test entry', None, True, 'A test entry ' + test_url), | |
82 | |
83 ('A test entry', 80, False, 'A test entry'), | |
84 ('A test entry', 80, 'auto', 'A test entry'), | |
85 ('A test entry', 80, True, 'A test entry ' + test_url), | |
86 | |
87 ('A test entry that is very very long because its title has many many ' | |
88 'words in it for no good reason', 80, False, | |
89 'A test entry that is very very long because its title has many many ' | |
90 'words in...'), | |
91 ('A test entry that is very very long because its title has many many ' | |
92 'words in it for no good reason', 80, 'auto', | |
93 'A test entry that is very very long because its... ' + test_url), | |
94 ('A test entry that is very very long because its title has many many ' | |
95 'words in it for no good reason', 80, True, | |
96 'A test entry that is very very long because its... ' + test_url) | |
97 ]) | |
98 def test_format_micropost_entry(text, limit, add_url, expected): | |
99 entry = _make_test_entry(text, True) | |
100 actual = format_entry(entry, limit, add_url) | |
101 assert actual == expected |