File tree Expand file tree Collapse file tree 3 files changed +8
-11
lines changed
chapter03-python-packages
src/random_wikipedia_article Expand file tree Collapse file tree 3 files changed +8
-11
lines changed Original file line number Diff line number Diff line change 1
1
[project ]
2
2
name = " random-wikipedia-article"
3
3
version = " 0.1"
4
+ dependencies = [" pytest" ]
4
5
5
- [project .scripts ]
6
- random-wikipedia-article = " random_wikipedia_article:main "
6
+ [project .entry-points . pytest11 ]
7
+ random-wikipedia-article = " random_wikipedia_article"
7
8
8
9
[build-system ]
9
10
requires = [" hatchling" ]
Original file line number Diff line number Diff line change 1
1
import json
2
- import textwrap
3
2
import urllib .request
4
3
4
+ import pytest
5
+
5
6
API_URL = "https://en.wikipedia.org/api/rest_v1/page/random/summary"
6
7
7
8
8
- def main ():
9
+ @pytest .fixture
10
+ def random_wikipedia_article ():
9
11
with urllib .request .urlopen (API_URL ) as response :
10
- data = json .load (response )
11
-
12
- print (data ["title" ], end = "\n \n " )
13
- print (textwrap .fill (data ["extract" ]))
12
+ return json .load (response )
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments