def main(args): # Validate arguments. if len(args) < 1: print('Please specify a deck of flash cards.') return # Load cards. deck_filename = args[0] deck_folder, deck_name = os.path.split(deck_filename) with open(deck_filename) as f: deck_data = f.read() cards = load_cards(deck_data) print('Found {} cards'.format(len(cards))) # Load stats. stats_filename = os.path.join(deck_folder, deck_name + '.stats') if os.path.exists(stats_filename): with open(stats_filename, 'rb') as f: stats_data = f.read() stats = CardStats.load(stats_data) else: stats = CardStats() # Start the quiz. stats = do_quiz(cards, stats) # Save stats. stats_data = stats.save() with open(stats_filename, 'wb') as f: f.write(stats_data)
def test_save_load_stats(): data = test_stats.save() stats = CardStats.load(data) assert_equal(test_stats, stats)