Mercurial > silorider
comparison tests/test_format.py @ 0:a1b7a459326a
Initial commit.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 18 Jul 2018 20:46:04 -0700 |
parents | |
children | a921cc2306bc |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a1b7a459326a |
---|---|
1 import pytest | |
2 from silorider.format import format_entry | |
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() | |
14 entry.best_name = best_name | |
15 entry.is_micropost = is_micropost | |
16 entry.url = test_url | |
17 return entry | |
18 | |
19 | |
20 @pytest.mark.parametrize("title, limit, add_url, expected", [ | |
21 ('A test entry', None, False, 'A test entry'), | |
22 ('A test entry', None, 'auto', 'A test entry ' + test_url), | |
23 ('A test entry', None, True, 'A test entry ' + test_url), | |
24 | |
25 ('A test entry', 80, False, 'A test entry'), | |
26 ('A test entry', 80, 'auto', 'A test entry ' + test_url), | |
27 ('A test entry', 80, True, 'A test entry ' + test_url), | |
28 | |
29 ('A test entry that is very very long because its title has many many ' | |
30 'words in it for no good reason', 80, False, | |
31 'A test entry that is very very long because its title has many many ' | |
32 'words in...'), | |
33 ('A test entry that is very very long because its title has many many ' | |
34 'words in it for no good reason', 80, 'auto', | |
35 'A test entry that is very very long because its... ' + test_url), | |
36 ('A test entry that is very very long because its title has many many ' | |
37 'words in it for no good reason', 80, True, | |
38 'A test entry that is very very long because its... ' + test_url) | |
39 ]) | |
40 def test_format_lonform_entry(title, limit, add_url, expected): | |
41 entry = _make_test_entry(title, False) | |
42 actual = format_entry(entry, limit, add_url) | |
43 assert actual == expected | |
44 | |
45 | |
46 @pytest.mark.parametrize("text, limit, add_url, expected", [ | |
47 ('A test entry', None, False, 'A test entry'), | |
48 ('A test entry', None, 'auto', 'A test entry'), | |
49 ('A test entry', None, True, 'A test entry ' + test_url), | |
50 | |
51 ('A test entry', 80, False, 'A test entry'), | |
52 ('A test entry', 80, 'auto', 'A test entry'), | |
53 ('A test entry', 80, True, 'A test entry ' + test_url), | |
54 | |
55 ('A test entry that is very very long because its title has many many ' | |
56 'words in it for no good reason', 80, False, | |
57 'A test entry that is very very long because its title has many many ' | |
58 'words in...'), | |
59 ('A test entry that is very very long because its title has many many ' | |
60 'words in it for no good reason', 80, 'auto', | |
61 'A test entry that is very very long because its... ' + test_url), | |
62 ('A test entry that is very very long because its title has many many ' | |
63 'words in it for no good reason', 80, True, | |
64 'A test entry that is very very long because its... ' + test_url) | |
65 ]) | |
66 def test_format_micropost_entry(text, limit, add_url, expected): | |
67 entry = _make_test_entry(text, True) | |
68 actual = format_entry(entry, limit, add_url) | |
69 assert actual == expected |