From 2365a72d98cfd7e7fb559a92e6cf6fcaf7bf0a38 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Wed, 30 Nov 2016 15:49:32 +0000 Subject: [PATCH] Fix User class unit tests --- gramps/cli/test/user_test.py | 7 ++++++- gramps/cli/user.py | 2 +- gramps/gui/test/user_test.py | 12 +++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/gramps/cli/test/user_test.py b/gramps/cli/test/user_test.py index e1da67426..e8bc1f025 100644 --- a/gramps/cli/test/user_test.py +++ b/gramps/cli/test/user_test.py @@ -23,7 +23,6 @@ import unittest from .. import user -from ...gen.test.user_test import TestUser import sys try: @@ -38,6 +37,12 @@ except: MOCKING = False print ("Mocking disabled", sys.exc_info()[0:2]) +class TestUser: + TITLE = "Testing prompt" + MSG = "Choices are hard. Nevertheless, please choose!" + ACCEPT = "To be" + REJECT = "Not to be" + class TestUser_prompt(unittest.TestCase): def setUp(self): self.real_user = user.User() diff --git a/gramps/cli/user.py b/gramps/cli/user.py index 355e58713..503e27ef6 100644 --- a/gramps/cli/user.py +++ b/gramps/cli/user.py @@ -152,7 +152,7 @@ class User(user.User): reply = "" ### Trun response into True/False: if reply == "": - return default + return default == accept_label elif reply == accept_label: return True else: diff --git a/gramps/gui/test/user_test.py b/gramps/gui/test/user_test.py index 6d6794612..0e90b6c69 100644 --- a/gramps/gui/test/user_test.py +++ b/gramps/gui/test/user_test.py @@ -23,7 +23,6 @@ import unittest from .. import user -from ...gen.test.user_test import TestUser import sys try: @@ -38,6 +37,12 @@ except: MOCKING = False print ("Mocking disabled", sys.exc_info()[0:2]) +class TestUser: + TITLE = "Testing prompt" + MSG = "Choices are hard. Nevertheless, please choose!" + ACCEPT = "To be" + REJECT = "Not to be" + class TestUser_prompt(unittest.TestCase): def setUp(self): self.user = user.User() @@ -46,9 +51,10 @@ class TestUser_prompt(unittest.TestCase): def test_prompt_runs_QuestionDialog2(self): with patch('gramps.gui.user.QuestionDialog2') as MockQD: self.user.prompt(TestUser.TITLE, TestUser.MSG, - TestUser.ACCEPT, TestUser.REJECT, None) + TestUser.ACCEPT, TestUser.REJECT, parent=None) MockQD.assert_called_once_with(TestUser.TITLE, TestUser.MSG, - TestUser.ACCEPT, TestUser.REJECT, None) + TestUser.ACCEPT, TestUser.REJECT, + parent=None) MockQD.return_value.run.assert_called_once_with() # TODO test that run's return is the one returned by prompt()...