-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_deck_reader.py
136 lines (120 loc) · 5.7 KB
/
test_deck_reader.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
'''
This will test your DeckReader class, once you have passed
all of these tests, you can start making your control flow
to make the flashcards useable!
'''
from flash_cards import *
from io import StringIO
def test_reader_init():
test_reader = DeckReader()
assert test_reader.loaded_decks == {}
def test_reader_load_deck():
test_reader = DeckReader()
test_reader.load_deck("test_deck.csv")
test_deck = Deck("test_deck.csv")
assert test_reader.loaded_decks["test_deck"].name == "test_deck"
pass
def test_reader_print_menu(capsys):
test_reader = DeckReader()
test_reader.load_deck("test_deck.csv")
test_reader.print_menu()
captured_stdout, _ = capsys.readouterr()
output_text = captured_stdout.split("\n")
output_text[0] == "*******************"
output_text[2] == "test_deck"
output_text[3] == "******************"
def test_reader_play_front_first(monkeypatch, capsys):
# Using forloop to make sure the tests are printed somewhere.
test_reader = DeckReader()
test_reader.load_deck("test_deck.csv")
inputs = ["f\n" "\n", "\n", "\n", "\n"] # We actually want these inputs for this one
inputs_str = StringIO(''.join(inputs))
monkeypatch.setattr('sys.stdin', inputs_str)
test_reader.play_front_first("test_deck")
captured_stdout, _ = capsys.readouterr()
output_text = captured_stdout.split("\n")
# Search through all substrings to see if
# test_deck contents are being printed
# There is probably a better way to do this but this makes the most sense in my head
is_test1_in_text = False
is_test2_in_text = False
is_test3_in_text = False
is_test4_in_text = False
for text in output_text:
if text.find("test1") != -1:
test_1_index = text.find("test1")
is_test1_in_text = True
if text.find("test2") != -1:
test_2_index = text.find("test2")
is_test2_in_text = True
if text.find("test3") != -1:
is_test3_in_text = True
if text.find("test4") != -1:
is_test4_in_text = True
assert is_test1_in_text == True, "test1 not found in print out"
assert is_test2_in_text == True, "test2 not found in print out"
assert is_test3_in_text == True, "test3 not found in print out"
assert is_test4_in_text == True, "test4 not found in print out"
# Checking order of tests, this could be merged into the above code, but I am lazy
for index, text in enumerate(output_text): # Based on how user prints front and back, test1 and test2 may be in seperate elements or in the same element
if text.find("test1") != -1:
test_1_index = index
if text.find("test2") != -1:
test_2_index = index
# if in seperate elements
if test_1_index != test_2_index:
assert test_1_index < test_2_index, "When printing your deck, your back card was seen before your front card"
pass
else: # They are in the same string
index_1 = output_text[test_1_index].find("1")
index_2 = output_text[test_1_index].find("2")
assert index_1 < index_2, "When printing deck front first, your back card was seen before your front card"
def test_reader_play_back_first(monkeypatch, capsys):
test_reader = DeckReader()
test_reader.load_deck("test_deck.csv")
inputs = ["f\n" "\n", "\n", "\n", "\n"] # We actually want these inputs for this one
inputs_str = StringIO(''.join(inputs))
monkeypatch.setattr('sys.stdin', inputs_str)
test_reader.play_back_first("test_deck")
captured_stdout, _ = capsys.readouterr()
output_text = captured_stdout.split("\n")
# Search through all substrings to see if
# test_deck contents are being printed
# There is probably a better way to do this but this makes the most sense in my head
# This could later be imporved by specifiying order of these finds
is_test1_in_text = False
is_test2_in_text = False
is_test3_in_text = False
is_test4_in_text = False
for text in output_text:
if text.find("test1") != -1:
is_test1_in_text = True
if text.find("test2") != -1:
is_test2_in_text = True
if text.find("test3") != -1:
is_test3_in_text = True
if text.find("test4") != -1:
is_test4_in_text = True
assert is_test1_in_text == True, "test1 not found in print out"
assert is_test2_in_text == True, "test2 not found in print out"
assert is_test3_in_text == True, "test3 not found in print out"
assert is_test4_in_text == True, "test4 not found in print out"
# Checking order of tests, this could be merged into the above code, but I am lazy
for index, text in enumerate(output_text): # Based on how user prints front and back, test1 and test2 may be in seperate elements or in the same element
if text.find("test1") != -1:
test_1_index = index
if text.find("test2") != -1:
test_2_index = index
# if in seperate elements
if test_1_index != test_2_index:
assert test_1_index > test_2_index, "When printing your deck, your back card was seen before your front card"
pass
else: # They are in the same string
index_1 = output_text[test_1_index].find("1")
index_2 = output_text[test_1_index].find("2")
assert index_1 > index_2, "When printing deck front first, your back card was seen before your front card"
def test_reader_does_deck_exist():
test_reader = DeckReader()
test_reader.load_deck("test_deck.csv")
assert test_reader.does_deck_exist("test_deck") == True, 'test_deck is loaded in but you said it is not'
assert test_reader.does_deck_exist("adaksdjf") == False, 'Deck "adaksdjf" does not exits but you indicated it does'