ui: Remove UserInterface.display_results()
authorW. Trevor King <wking@tremily.us>
Thu, 7 Feb 2013 03:09:06 +0000 (22:09 -0500)
committerW. Trevor King <wking@tremily.us>
Wed, 13 Mar 2013 21:17:15 +0000 (17:17 -0400)
Having quizzer.cli.main() calling ui.display_results() does not
translate well to an HTML-based UI.

CommandLineInterface now displays results as part of its .run()
implementation.

quizzer/cli.py
quizzer/ui/__init__.py
quizzer/ui/cli.py

index cc4880ca48ea490867de4f3f02b94eb1b583ae24..e0d0ced3d76aa743761bde0bb1ab01b4c8c67840 100644 (file)
@@ -90,4 +90,3 @@ def main():
         ui.run()
     finally:
         ui.answers.save()
-    ui.display_results()
index 4b39468bcdf3bf6e27880076498b7a4dbc5c987c..0db903cb53ef5a876aab4fd19bae3628c4958514 100644 (file)
@@ -32,9 +32,6 @@ class UserInterface (object):
     def run(self):
         raise NotImplementedError()
 
-    def display_results(self):
-        raise NotImplementedError()
-
     def get_question(self):
         if self.stack:
             return self.stack.pop(0)
index 464faec2ee62c0942299354684b03ab9e6228084..473b34d2cb0ec8b524a55838ba70aadd19bd3e06 100644 (file)
@@ -181,21 +181,21 @@ class CommandLineInterface (UserInterface):
         }
 
     def run(self):
-        if not self.stack:
-            return
-        cmd = QuestionCommandLine(ui=self)
-        cmd.cmdloop()
-        print()
+        if self.stack:
+            cmd = QuestionCommandLine(ui=self)
+            cmd.cmdloop()
+            print()
+        self._display_results()
 
-    def display_results(self):
+    def _display_results(self):
         print(_colorize(self.colors['result'], 'results:'))
         for question in self.quiz:
             if question.id in self.answers:
-                self.display_result(question=question)
+                self._display_result(question=question)
                 print()
-        self.display_totals()
+        self._display_totals()
 
-    def display_result(self, question):
+    def _display_result(self, question):
         answers = self.answers.get(question.id, [])
         print('question:')
         print('  {}'.format(
@@ -218,7 +218,7 @@ class CommandLineInterface (UserInterface):
             print('  you answered: {}'.format(ans))
             print('     which was: {}'.format(correct))
 
-    def display_totals(self):
+    def _display_totals(self):
         answered = self.answers.get_answered(questions=self.quiz)
         correctly_answered = self.answers.get_correctly_answered(
             questions=self.quiz)