From a2fa3b3110a3c8d70d564abcea1b5a490987807e Mon Sep 17 00:00:00 2001 From: berryman Date: Sat, 8 Dec 2012 15:31:21 -0500 Subject: [PATCH] assign answer attribute to Card using kwargs; make the test cases check question cards --- plugin.py | 8 +++++++- test.py | 11 ++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/plugin.py b/plugin.py index 41f7112..0137747 100644 --- a/plugin.py +++ b/plugin.py @@ -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): diff --git a/test.py b/test.py index 99e5727..207405e 100644 --- a/test.py +++ b/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