assign answer attribute to Card using kwargs; make the test cases check question cards

This commit is contained in:
berryman 2012-12-08 15:31:21 -05:00
parent eb2c66aa3f
commit a2fa3b3110
2 changed files with 15 additions and 4 deletions

View File

@ -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
View File

@ -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