|
13 | 13 |
|
14 | 14 |
|
15 | 15 | @pytest.fixture |
16 | | -def monkeypatch_feed(monkeypatch): |
| 16 | +def local_feed(): |
17 | 17 | """Use local file instead of downloading feed from web""" |
18 | | - local_path = os.path.join(HERE, "realpython_20180919.xml") |
19 | | - monkeypatch.setattr(feed, "URL", local_path) |
20 | | - return local_path |
| 18 | + return os.path.join(HERE, "realpython_20180919.xml") |
21 | 19 |
|
22 | 20 |
|
23 | 21 | @pytest.fixture |
24 | | -def monkeypatch_summary_feed(monkeypatch): |
| 22 | +def local_summary_feed(): |
25 | 23 | """Use local file instead of downloading feed from web""" |
26 | | - local_path = os.path.join(HERE, "realpython_descriptions_20180919.xml") |
27 | | - monkeypatch.setattr(feed, "URL", local_path) |
28 | | - return local_path |
| 24 | + return os.path.join(HERE, "realpython_descriptions_20180919.xml") |
29 | 25 |
|
30 | 26 |
|
31 | 27 | # |
32 | 28 | # Tests |
33 | 29 | # |
34 | | -def test_site(monkeypatch_feed): |
| 30 | +def test_site(local_feed): |
35 | 31 | """Test that we can read the site title and link""" |
36 | 32 | expected = "Real Python (https://realpython.com/)" |
37 | | - assert feed.get_site() == expected |
| 33 | + assert feed.get_site(url=local_feed) == expected |
38 | 34 |
|
39 | 35 |
|
40 | | -def test_article_title(monkeypatch_feed): |
| 36 | +def test_article_title(local_feed): |
41 | 37 | """Test that title is added at top of article""" |
42 | 38 | article_id = 0 |
43 | | - title = feed.get_titles()[article_id] |
44 | | - article = feed.get_article(article_id) |
| 39 | + title = feed.get_titles(url=local_feed)[article_id] |
| 40 | + article = feed.get_article(article_id, url=local_feed) |
45 | 41 |
|
46 | 42 | assert article.strip("# ").startswith(title) |
47 | 43 |
|
48 | 44 |
|
49 | | -def test_article(monkeypatch_feed): |
| 45 | +def test_article(local_feed): |
50 | 46 | """Test that article is returned""" |
51 | 47 | article_id = 2 |
52 | 48 | article_phrases = [ |
53 | 49 | "logging.info('This is an info message')", |
54 | 50 | "By using the `level` parameter", |
55 | 51 | " * `level`: The root logger", |
56 | 52 | ] |
57 | | - article = feed.get_article(article_id) |
| 53 | + article = feed.get_article(article_id, url=local_feed) |
58 | 54 |
|
59 | 55 | for phrase in article_phrases: |
60 | 56 | assert phrase in article |
61 | 57 |
|
62 | 58 |
|
63 | | -def test_titles(monkeypatch_feed): |
| 59 | +def test_titles(local_feed): |
64 | 60 | """Test that titles are found""" |
65 | | - titles = feed.get_titles() |
| 61 | + titles = feed.get_titles(url=local_feed) |
66 | 62 |
|
67 | 63 | assert len(titles) == 20 |
68 | 64 | assert titles[0] == "Absolute vs Relative Imports in Python" |
69 | 65 | assert titles[9] == "Primer on Python Decorators" |
70 | 66 |
|
71 | 67 |
|
72 | | -def test_summary(monkeypatch_summary_feed): |
| 68 | +def test_summary(local_summary_feed): |
73 | 69 | """Test that summary feeds can be read""" |
74 | 70 | article_id = 1 |
75 | 71 | summary_phrases = [ |
76 | 72 | "Get the inside scoop", |
77 | 73 | "this list of\ninformative videos", |
78 | 74 | ] |
79 | | - summary = feed.get_article(article_id) |
| 75 | + summary = feed.get_article(article_id, url=local_summary_feed) |
80 | 76 |
|
81 | 77 | for phrase in summary_phrases: |
82 | 78 | assert phrase in summary |
83 | 79 |
|
84 | 80 |
|
85 | | -def test_invalid_article_id(monkeypatch_feed): |
| 81 | +def test_invalid_article_id(local_feed): |
86 | 82 | """Test that invalid article ids are handled gracefully""" |
87 | 83 | article_id = "wrong" |
88 | 84 | with pytest.raises(SystemExit): |
89 | | - feed.get_article(article_id) |
| 85 | + feed.get_article(article_id, url=local_feed) |
0 commit comments