forked from realpython/reader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_viewer.py
More file actions
40 lines (31 loc) · 997 Bytes
/
test_viewer.py
File metadata and controls
40 lines (31 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Tests for the reader.viewer module"""
# Third party imports
import pytest
# Reader imports
from reader import viewer
#
# Tests
#
def test_show(capsys):
"""Test that show adds information to stdout"""
text = "Lorem ipsum dolor sit amet"
viewer.show(text)
stdout, stderr = capsys.readouterr()
assert stderr == ""
# It's ok if the viewer adds some information
assert text in stdout
def test_show_list(capsys):
"""Test that show_list shows a list of items with an ID"""
site = "Real Python"
things = ["pathlib", "data classes", "python 3.7", "decorators"]
viewer.show_list(site, things)
stdout, stderr = capsys.readouterr()
assert stderr == ""
# Site name is shown in header
lines = stdout.split("\n")
assert site in lines[0]
# Each thing is listed preceded by a number
for thing, line in zip(things, lines[1:]):
line_parts = line.split()
assert line_parts[0].isnumeric()
assert thing in line