Fix User class unit tests
This commit is contained in:
parent
cf58de59c1
commit
2365a72d98
@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from .. import user
|
from .. import user
|
||||||
from ...gen.test.user_test import TestUser
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -38,6 +37,12 @@ except:
|
|||||||
MOCKING = False
|
MOCKING = False
|
||||||
print ("Mocking disabled", sys.exc_info()[0:2])
|
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):
|
class TestUser_prompt(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.real_user = user.User()
|
self.real_user = user.User()
|
||||||
|
@ -152,7 +152,7 @@ class User(user.User):
|
|||||||
reply = ""
|
reply = ""
|
||||||
### Trun response into True/False:
|
### Trun response into True/False:
|
||||||
if reply == "":
|
if reply == "":
|
||||||
return default
|
return default == accept_label
|
||||||
elif reply == accept_label:
|
elif reply == accept_label:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from .. import user
|
from .. import user
|
||||||
from ...gen.test.user_test import TestUser
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -38,6 +37,12 @@ except:
|
|||||||
MOCKING = False
|
MOCKING = False
|
||||||
print ("Mocking disabled", sys.exc_info()[0:2])
|
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):
|
class TestUser_prompt(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.user = user.User()
|
self.user = user.User()
|
||||||
@ -46,9 +51,10 @@ class TestUser_prompt(unittest.TestCase):
|
|||||||
def test_prompt_runs_QuestionDialog2(self):
|
def test_prompt_runs_QuestionDialog2(self):
|
||||||
with patch('gramps.gui.user.QuestionDialog2') as MockQD:
|
with patch('gramps.gui.user.QuestionDialog2') as MockQD:
|
||||||
self.user.prompt(TestUser.TITLE, TestUser.MSG,
|
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,
|
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()
|
MockQD.return_value.run.assert_called_once_with()
|
||||||
# TODO test that run's return is the one returned by prompt()...
|
# TODO test that run's return is the one returned by prompt()...
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user