Created
November 10, 2021 02:27
-
-
Save dahyun31x/b553cc88e7798d6916287b6ea2645707 to your computer and use it in GitHub Desktop.
pytest로 입출력을 테스트하는 방법
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
from io import StringIO | |
# 입력 스트림을 테스트, 출력 (스트링을 스트림으로 만들 수도 있음) | |
def test_load_csv(): | |
raw = StringIO('a,b,c\n1,2,3\n4,5,6') # string을 stream으로 변경 | |
actual = load_csv(raw) | |
expected = [ | |
{'a': '1', 'b': '2', 'c': '3'}, | |
{'a': '4', 'b': '5', 'c': '6'}, | |
] | |
assert expected == actual | |
def load_csv(f): | |
return list(csv.DictReader(f)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment