assign answer attribute to Card using kwargs; make the test cases check question cards
This commit is contained in:
parent
eb2c66aa3f
commit
a2fa3b3110
|
|
@ -1,5 +1,6 @@
|
|||
from random import choice
|
||||
import os
|
||||
import json
|
||||
|
||||
# Settings you change
|
||||
card_folder = 'cards'
|
||||
|
|
@ -60,10 +61,15 @@ class Deck(object):
|
|||
return card
|
||||
|
||||
class Card(object):
|
||||
def __init__(self, id, type, text, answers=None, author=None):
|
||||
def __init__(self, id, type, text, **kwargs):
|
||||
self.id = id
|
||||
self.type = type
|
||||
self.text = text
|
||||
for key, value in kwargs.iteritems():
|
||||
setattr(self, key, value)
|
||||
def __repr__(self):
|
||||
return json.dumps(self.__dict__)
|
||||
|
||||
|
||||
class GameRound(object):
|
||||
def __init__(self):
|
||||
|
|
|
|||
11
test.py
11
test.py
|
|
@ -17,7 +17,12 @@ def test_card_parsing():
|
|||
assert type(card) is Card
|
||||
assert type(card.id) is int
|
||||
assert type(card.type) is str
|
||||
assert card.type in ['answer', 'question']
|
||||
assert card.type in ['answer']
|
||||
assert type(card.text) is str
|
||||
if card.type is 'question':
|
||||
assert type(card.answers) is int
|
||||
for card in deck.questionDb:
|
||||
assert type(card) is Card
|
||||
assert type(card.id) is int
|
||||
assert type(card.type) is str
|
||||
assert card.type in ['question']
|
||||
assert type(card.text) is str
|
||||
assert type(card.answers) is int
|
||||
|
|
|
|||
Loading…
Reference in New Issue