diff --git a/gramps/cli/user.py b/gramps/cli/user.py index 815da7df9..72ee54f86 100644 --- a/gramps/cli/user.py +++ b/gramps/cli/user.py @@ -44,10 +44,10 @@ _SPINNER = ['|', '/', '-', '\\'] # User class # #------------------------------------------------------------------------- -class User(user.User): +class User(user.UserBase): """ This class provides a means to interact with the user via CLI. - It implements the interface in :class:`.gen.user.User` + It implements the interface in :class:`.gen.user.UserBase` """ def __init__(self, callback=None, error=None, auto_accept=False, quiet=False, @@ -58,7 +58,7 @@ class User(user.User): :param error: If given, notify_error delegates to this callback :type error: function(title, error) """ - user.User.__init__(self, callback, error, uistate, dbstate) + user.UserBase.__init__(self, callback, error, uistate, dbstate) self.steps = 0; self.current_step = 0; self._input = input diff --git a/gramps/gen/filters/rules/test/event_rules_test.py b/gramps/gen/filters/rules/test/event_rules_test.py index 56125ed7c..f158ee45d 100644 --- a/gramps/gen/filters/rules/test/event_rules_test.py +++ b/gramps/gen/filters/rules/test/event_rules_test.py @@ -27,7 +27,7 @@ import os from ....db.utils import import_as_dict from ....filters import GenericFilterFactory from ....const import DATA_DIR -from gramps.cli.user import User +from ....user import User from ..event import ( AllEvents, HasType, HasIdOf, HasGallery, RegExpIdOf, HasCitation, HasNote, diff --git a/gramps/gen/filters/rules/test/family_rules_test.py b/gramps/gen/filters/rules/test/family_rules_test.py index a5e4d7716..2cce8d523 100644 --- a/gramps/gen/filters/rules/test/family_rules_test.py +++ b/gramps/gen/filters/rules/test/family_rules_test.py @@ -27,7 +27,7 @@ import os from ....db.utils import import_as_dict from ....filters import GenericFilterFactory from ....const import DATA_DIR -from gramps.cli.user import User +from ....user import User from ..family import ( AllFamilies, HasRelType, HasGallery, HasIdOf, HasLDS, HasNote, RegExpIdOf, diff --git a/gramps/gen/filters/rules/test/media_rules_test.py b/gramps/gen/filters/rules/test/media_rules_test.py index e2877c48e..9c289b064 100644 --- a/gramps/gen/filters/rules/test/media_rules_test.py +++ b/gramps/gen/filters/rules/test/media_rules_test.py @@ -27,7 +27,7 @@ import os from ....db.utils import import_as_dict from ....filters import GenericFilterFactory from ....const import DATA_DIR -from gramps.cli.user import User +from ....user import User from ..media import ( AllMedia, HasIdOf, RegExpIdOf, HasCitation, HasNoteRegexp, diff --git a/gramps/gen/filters/rules/test/note_rules_test.py b/gramps/gen/filters/rules/test/note_rules_test.py index df06fddff..c71714a94 100644 --- a/gramps/gen/filters/rules/test/note_rules_test.py +++ b/gramps/gen/filters/rules/test/note_rules_test.py @@ -27,7 +27,7 @@ import os from ....db.utils import import_as_dict from ....filters import GenericFilterFactory from ....const import DATA_DIR -from gramps.cli.user import User +from ....user import User from ..note import ( AllNotes, HasIdOf, RegExpIdOf, HasNote, MatchesRegexpOf, diff --git a/gramps/gen/filters/rules/test/person_rules_test.py b/gramps/gen/filters/rules/test/person_rules_test.py index eb234009f..900afcfc1 100644 --- a/gramps/gen/filters/rules/test/person_rules_test.py +++ b/gramps/gen/filters/rules/test/person_rules_test.py @@ -27,7 +27,7 @@ import os from ....db.utils import import_as_dict from ....filters import GenericFilter from ....const import DATA_DIR -from gramps.cli.user import User +from ....user import User from ..person import ( Disconnected, Everyone, FamilyWithIncompleteEvent, HasAlternateName, diff --git a/gramps/gen/filters/rules/test/place_rules_test.py b/gramps/gen/filters/rules/test/place_rules_test.py index 947c59c56..8d8c44afe 100644 --- a/gramps/gen/filters/rules/test/place_rules_test.py +++ b/gramps/gen/filters/rules/test/place_rules_test.py @@ -27,7 +27,7 @@ import os from ....db.utils import import_as_dict from ....filters import GenericFilterFactory from ....const import DATA_DIR -from gramps.cli.user import User +from ....user import User from ..place import ( AllPlaces, HasCitation, HasGallery, HasIdOf, RegExpIdOf, HasNote, diff --git a/gramps/gen/filters/rules/test/repository_rules_test.py b/gramps/gen/filters/rules/test/repository_rules_test.py index 7ebeeb0bf..8d6728e63 100644 --- a/gramps/gen/filters/rules/test/repository_rules_test.py +++ b/gramps/gen/filters/rules/test/repository_rules_test.py @@ -27,7 +27,7 @@ import os from ....db.utils import import_as_dict from ....filters import GenericFilterFactory from ....const import DATA_DIR -from gramps.cli.user import User +from ....user import User from ..repository import ( AllRepos, HasIdOf, RegExpIdOf, HasNoteRegexp, HasReferenceCountOf, diff --git a/gramps/gen/lib/test/schema_test.py b/gramps/gen/lib/test/schema_test.py index 0d2e55293..fb73eb0c7 100644 --- a/gramps/gen/lib/test/schema_test.py +++ b/gramps/gen/lib/test/schema_test.py @@ -30,7 +30,7 @@ from .. import (Person, Family, Event, Place, Repository, Source, Citation, from ..serialize import to_json from ...db.utils import import_as_dict from ...const import DATA_DIR -from gramps.cli.user import User +from ...user import User TEST_DIR = os.path.abspath(os.path.join(DATA_DIR, "tests")) EXAMPLE = os.path.join(TEST_DIR, "example.gramps") diff --git a/gramps/gen/lib/test/serialize_test.py b/gramps/gen/lib/test/serialize_test.py index 1e8df55b5..37754fc47 100644 --- a/gramps/gen/lib/test/serialize_test.py +++ b/gramps/gen/lib/test/serialize_test.py @@ -28,7 +28,7 @@ from .. import (Person, Family, Event, Source, Place, Citation, from ..serialize import to_json, from_json from ...db.utils import import_as_dict from ...const import DATA_DIR -from gramps.cli.user import User +from ...user import User TEST_DIR = os.path.abspath(os.path.join(DATA_DIR, "tests")) EXAMPLE = os.path.join(TEST_DIR, "example.gramps") diff --git a/gramps/gen/merge/test/merge_ref_test.py b/gramps/gen/merge/test/merge_ref_test.py index 862808dec..265c91a1a 100644 --- a/gramps/gen/merge/test/merge_ref_test.py +++ b/gramps/gen/merge/test/merge_ref_test.py @@ -32,7 +32,7 @@ import lxml.etree as ET from gramps.plugins.lib.libgrampsxml import GRAMPS_XML_VERSION from gramps.test.test_util import Gramps -from gramps.cli.user import User +from gramps.gen.user import User from gramps.gen.const import DATA_DIR, USER_PLUGINS, TEMP_DIR from gramps.version import VERSION from gramps.gen.lib import Name, Surname @@ -93,7 +93,7 @@ class BaseMergeCheck(unittest.TestCase): def do_case(self, phoenix_id, titanic_id, input_doc, expect_doc, test_error_str=''): """Do the merge and "assert" the result.""" - gramps = Gramps(user=User(auto_accept=True, quiet=True)) + gramps = Gramps(user=User()) result_str, err_str = gramps.run( '-d', '.ImportXML', '--config=preferences.eprefix:DEFAULT', '-i', '-', '-f', 'gramps', '-a', 'tool', '-p', @@ -154,7 +154,7 @@ class BaseMergeCheck(unittest.TestCase): def do_family_case(self, phoenix_id, titanic_id, father_h, mother_h, input_doc, expect_doc, test_error_str=''): - gramps = Gramps(user=User(auto_accept=True, quiet=True)) + gramps = Gramps(user=User()) result_str, err_str = gramps.run( '-d', '.ImportXML', '--config=preferences.eprefix:DEFAULT', '-i', '-', '-f', 'gramps', '-a', 'tool', '-p', @@ -166,7 +166,7 @@ class BaseMergeCheck(unittest.TestCase): def raw_contains(self, phoenix_id, titanic_id, input_doc, expect_str, test_error_str=''): - gramps = Gramps(user=User(auto_accept=True, quiet=True)) + gramps = Gramps(user=User()) result_str, err_str = gramps.run( '-d', '.ImportXML', '--config=preferences.eprefix:DEFAULT', '-i', '-', '-f', 'gramps', '-a', 'tool', '-p', diff --git a/gramps/gen/user.py b/gramps/gen/user.py index 6d9a9116c..d19702db5 100644 --- a/gramps/gen/user.py +++ b/gramps/gen/user.py @@ -26,7 +26,7 @@ import sys from abc import ABCMeta, abstractmethod from contextlib import contextmanager -class User(metaclass=ABCMeta): +class UserBase(metaclass=ABCMeta): """ This class provides a means to interact with the user in an abstract way. This class should be overridden by each respective user interface to @@ -187,3 +187,40 @@ class User(metaclass=ABCMeta): """ Displays information to the user """ + +class User(UserBase): + """ + An implementation of the :class:`.gen.user.UserBase` class which supresses + output and accepts prompts. This is useful for unit tests. + """ + + def __init__(self, callback=None, error=None, uistate=None, dbstate=None): + UserBase.__init__(self, callback=lambda x: x) + + def begin_progress(self, title, message, steps): + pass + + def step_progress(self): + pass + + def end_progress(self): + pass + + def prompt(self, title, message, accept_label, reject_label, parent=None, + default_label=None): + return True + + def warn(self, title, warning=""): + pass + + def notify_error(self, title, error=""): + pass + + def notify_db_error(self, error): + pass + + def notify_db_repair(self, error): + pass + + def info(self, msg1, infotext, parent=None, monospaced=False): + pass diff --git a/gramps/gui/user.py b/gramps/gui/user.py index d33c9bc89..0d81504ab 100644 --- a/gramps/gui/user.py +++ b/gramps/gui/user.py @@ -44,14 +44,14 @@ from .dialog import (WarningDialog, ErrorDialog, DBErrorDialog, # User class # #------------------------------------------------------------------------- -class User(user.User): +class User(user.UserBase): """ This class provides a means to interact with the user via GTK. - It implements the interface in :class:`.gen.user.User` + It implements the interface in :class:`.gen.user.UserBase` """ def __init__(self, callback=None, error=None, parent=None, uistate=None, dbstate=None): # TODO User API: gen==cli==gui - user.User.__init__(self, callback, error, uistate, dbstate) + user.UserBase.__init__(self, callback, error, uistate, dbstate) self._progress = None if parent: diff --git a/gramps/plugins/test/test_exports.py b/gramps/plugins/test/test_exports.py index de0d0db70..3501d2951 100644 --- a/gramps/plugins/test/test_exports.py +++ b/gramps/plugins/test/test_exports.py @@ -26,7 +26,7 @@ import difflib from gramps.test.test_util import Gramps from gramps.gen.const import TEMP_DIR, DATA_DIR from gramps.gen.datehandler import set_format -from gramps.cli.user import User +from gramps.gen.user import User from gramps.gen.utils.config import config TREE_NAME = "Test_exporttest" diff --git a/gramps/plugins/test/test_imports.py b/gramps/plugins/test/test_imports.py index 52094de72..60e99562a 100644 --- a/gramps/plugins/test/test_imports.py +++ b/gramps/plugins/test/test_imports.py @@ -35,7 +35,7 @@ from gramps.gen.db.utils import import_as_dict from gramps.gen.merge.diff import diff_dbs, to_struct from gramps.gen.simple import SimpleAccess from gramps.gen.utils.id import set_det_id -from gramps.cli.user import User +from gramps.gen.user import User from gramps.gen.const import TEMP_DIR, DATA_DIR from gramps.test.test_util import capture from gramps.plugins.export.exportxml import XmlWriter diff --git a/gramps/plugins/test/test_tools.py b/gramps/plugins/test/test_tools.py index a543663af..376e917a3 100644 --- a/gramps/plugins/test/test_tools.py +++ b/gramps/plugins/test/test_tools.py @@ -27,7 +27,7 @@ import random from gramps.test.test_util import Gramps from gramps.gen.const import DATA_DIR -from gramps.cli.user import User +from gramps.gen.user import User from gramps.gen.utils.id import set_det_id from gramps.gen import const from gramps.gen.utils.config import config diff --git a/gramps/test/test_util.py b/gramps/test/test_util.py index 0117f7302..1134726a5 100644 --- a/gramps/test/test_util.py +++ b/gramps/test/test_util.py @@ -32,7 +32,7 @@ import contextlib from io import TextIOWrapper, BytesIO, StringIO from gramps.gen.dbstate import DbState -from gramps.cli.user import User +from gramps.gen.user import User from gramps.cli.grampscli import CLIManager from gramps.cli.argparser import ArgParser from gramps.cli.arghandler import ArgHandler @@ -249,7 +249,7 @@ class Gramps: from gramps.cli.clidbman import CLIDbManager self.dbstate = dbstate or DbState() #we need a manager for the CLI session - self.user = user or User(auto_accept=True, quiet=False) + self.user = user or User() self.climanager = CLIManager(self.dbstate, setloader=True, user=self.user) self.clidbmanager = CLIDbManager(self.dbstate)