Suppress extraneous output in unit tests

This commit is contained in:
Nick Hall
2017-03-06 21:55:48 +00:00
parent f57386ab63
commit 3b9d97d348
17 changed files with 62 additions and 25 deletions

View File

@ -44,10 +44,10 @@ _SPINNER = ['|', '/', '-', '\\']
# User class # User class
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class User(user.User): class User(user.UserBase):
""" """
This class provides a means to interact with the user via CLI. 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, def __init__(self, callback=None, error=None,
auto_accept=False, quiet=False, auto_accept=False, quiet=False,
@ -58,7 +58,7 @@ class User(user.User):
:param error: If given, notify_error delegates to this callback :param error: If given, notify_error delegates to this callback
:type error: function(title, error) :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.steps = 0;
self.current_step = 0; self.current_step = 0;
self._input = input self._input = input

View File

@ -27,7 +27,7 @@ import os
from ....db.utils import import_as_dict from ....db.utils import import_as_dict
from ....filters import GenericFilterFactory from ....filters import GenericFilterFactory
from ....const import DATA_DIR from ....const import DATA_DIR
from gramps.cli.user import User from ....user import User
from ..event import ( from ..event import (
AllEvents, HasType, HasIdOf, HasGallery, RegExpIdOf, HasCitation, HasNote, AllEvents, HasType, HasIdOf, HasGallery, RegExpIdOf, HasCitation, HasNote,

View File

@ -27,7 +27,7 @@ import os
from ....db.utils import import_as_dict from ....db.utils import import_as_dict
from ....filters import GenericFilterFactory from ....filters import GenericFilterFactory
from ....const import DATA_DIR from ....const import DATA_DIR
from gramps.cli.user import User from ....user import User
from ..family import ( from ..family import (
AllFamilies, HasRelType, HasGallery, HasIdOf, HasLDS, HasNote, RegExpIdOf, AllFamilies, HasRelType, HasGallery, HasIdOf, HasLDS, HasNote, RegExpIdOf,

View File

@ -27,7 +27,7 @@ import os
from ....db.utils import import_as_dict from ....db.utils import import_as_dict
from ....filters import GenericFilterFactory from ....filters import GenericFilterFactory
from ....const import DATA_DIR from ....const import DATA_DIR
from gramps.cli.user import User from ....user import User
from ..media import ( from ..media import (
AllMedia, HasIdOf, RegExpIdOf, HasCitation, HasNoteRegexp, AllMedia, HasIdOf, RegExpIdOf, HasCitation, HasNoteRegexp,

View File

@ -27,7 +27,7 @@ import os
from ....db.utils import import_as_dict from ....db.utils import import_as_dict
from ....filters import GenericFilterFactory from ....filters import GenericFilterFactory
from ....const import DATA_DIR from ....const import DATA_DIR
from gramps.cli.user import User from ....user import User
from ..note import ( from ..note import (
AllNotes, HasIdOf, RegExpIdOf, HasNote, MatchesRegexpOf, AllNotes, HasIdOf, RegExpIdOf, HasNote, MatchesRegexpOf,

View File

@ -27,7 +27,7 @@ import os
from ....db.utils import import_as_dict from ....db.utils import import_as_dict
from ....filters import GenericFilter from ....filters import GenericFilter
from ....const import DATA_DIR from ....const import DATA_DIR
from gramps.cli.user import User from ....user import User
from ..person import ( from ..person import (
Disconnected, Everyone, FamilyWithIncompleteEvent, HasAlternateName, Disconnected, Everyone, FamilyWithIncompleteEvent, HasAlternateName,

View File

@ -27,7 +27,7 @@ import os
from ....db.utils import import_as_dict from ....db.utils import import_as_dict
from ....filters import GenericFilterFactory from ....filters import GenericFilterFactory
from ....const import DATA_DIR from ....const import DATA_DIR
from gramps.cli.user import User from ....user import User
from ..place import ( from ..place import (
AllPlaces, HasCitation, HasGallery, HasIdOf, RegExpIdOf, HasNote, AllPlaces, HasCitation, HasGallery, HasIdOf, RegExpIdOf, HasNote,

View File

@ -27,7 +27,7 @@ import os
from ....db.utils import import_as_dict from ....db.utils import import_as_dict
from ....filters import GenericFilterFactory from ....filters import GenericFilterFactory
from ....const import DATA_DIR from ....const import DATA_DIR
from gramps.cli.user import User from ....user import User
from ..repository import ( from ..repository import (
AllRepos, HasIdOf, RegExpIdOf, HasNoteRegexp, HasReferenceCountOf, AllRepos, HasIdOf, RegExpIdOf, HasNoteRegexp, HasReferenceCountOf,

View File

@ -30,7 +30,7 @@ from .. import (Person, Family, Event, Place, Repository, Source, Citation,
from ..serialize import to_json from ..serialize import to_json
from ...db.utils import import_as_dict from ...db.utils import import_as_dict
from ...const import DATA_DIR 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")) TEST_DIR = os.path.abspath(os.path.join(DATA_DIR, "tests"))
EXAMPLE = os.path.join(TEST_DIR, "example.gramps") EXAMPLE = os.path.join(TEST_DIR, "example.gramps")

View File

@ -28,7 +28,7 @@ from .. import (Person, Family, Event, Source, Place, Citation,
from ..serialize import to_json, from_json from ..serialize import to_json, from_json
from ...db.utils import import_as_dict from ...db.utils import import_as_dict
from ...const import DATA_DIR 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")) TEST_DIR = os.path.abspath(os.path.join(DATA_DIR, "tests"))
EXAMPLE = os.path.join(TEST_DIR, "example.gramps") EXAMPLE = os.path.join(TEST_DIR, "example.gramps")

View File

@ -32,7 +32,7 @@ import lxml.etree as ET
from gramps.plugins.lib.libgrampsxml import GRAMPS_XML_VERSION from gramps.plugins.lib.libgrampsxml import GRAMPS_XML_VERSION
from gramps.test.test_util import Gramps 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.gen.const import DATA_DIR, USER_PLUGINS, TEMP_DIR
from gramps.version import VERSION from gramps.version import VERSION
from gramps.gen.lib import Name, Surname 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, def do_case(self, phoenix_id, titanic_id, input_doc, expect_doc,
test_error_str=''): test_error_str=''):
"""Do the merge and "assert" the result.""" """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( result_str, err_str = gramps.run(
'-d', '.ImportXML', '--config=preferences.eprefix:DEFAULT', '-d', '.ImportXML', '--config=preferences.eprefix:DEFAULT',
'-i', '-', '-f', 'gramps', '-a', 'tool', '-p', '-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, def do_family_case(self, phoenix_id, titanic_id, father_h, mother_h,
input_doc, expect_doc, test_error_str=''): 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( result_str, err_str = gramps.run(
'-d', '.ImportXML', '--config=preferences.eprefix:DEFAULT', '-d', '.ImportXML', '--config=preferences.eprefix:DEFAULT',
'-i', '-', '-f', 'gramps', '-a', 'tool', '-p', '-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, def raw_contains(self, phoenix_id, titanic_id, input_doc, expect_str,
test_error_str=''): test_error_str=''):
gramps = Gramps(user=User(auto_accept=True, quiet=True)) gramps = Gramps(user=User())
result_str, err_str = gramps.run( result_str, err_str = gramps.run(
'-d', '.ImportXML', '--config=preferences.eprefix:DEFAULT', '-d', '.ImportXML', '--config=preferences.eprefix:DEFAULT',
'-i', '-', '-f', 'gramps', '-a', 'tool', '-p', '-i', '-', '-f', 'gramps', '-a', 'tool', '-p',

View File

@ -26,7 +26,7 @@ import sys
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from contextlib import contextmanager 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 provides a means to interact with the user in an abstract way.
This class should be overridden by each respective user interface to This class should be overridden by each respective user interface to
@ -187,3 +187,40 @@ class User(metaclass=ABCMeta):
""" """
Displays information to the user 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

View File

@ -44,14 +44,14 @@ from .dialog import (WarningDialog, ErrorDialog, DBErrorDialog,
# User class # User class
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class User(user.User): class User(user.UserBase):
""" """
This class provides a means to interact with the user via GTK. 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, def __init__(self, callback=None, error=None, parent=None,
uistate=None, dbstate=None): # TODO User API: gen==cli==gui 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 self._progress = None
if parent: if parent:

View File

@ -26,7 +26,7 @@ import difflib
from gramps.test.test_util import Gramps from gramps.test.test_util import Gramps
from gramps.gen.const import TEMP_DIR, DATA_DIR from gramps.gen.const import TEMP_DIR, DATA_DIR
from gramps.gen.datehandler import set_format 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 from gramps.gen.utils.config import config
TREE_NAME = "Test_exporttest" TREE_NAME = "Test_exporttest"

View File

@ -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.merge.diff import diff_dbs, to_struct
from gramps.gen.simple import SimpleAccess from gramps.gen.simple import SimpleAccess
from gramps.gen.utils.id import set_det_id 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.gen.const import TEMP_DIR, DATA_DIR
from gramps.test.test_util import capture from gramps.test.test_util import capture
from gramps.plugins.export.exportxml import XmlWriter from gramps.plugins.export.exportxml import XmlWriter

View File

@ -27,7 +27,7 @@ import random
from gramps.test.test_util import Gramps from gramps.test.test_util import Gramps
from gramps.gen.const import DATA_DIR 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.utils.id import set_det_id
from gramps.gen import const from gramps.gen import const
from gramps.gen.utils.config import config from gramps.gen.utils.config import config

View File

@ -32,7 +32,7 @@ import contextlib
from io import TextIOWrapper, BytesIO, StringIO from io import TextIOWrapper, BytesIO, StringIO
from gramps.gen.dbstate import DbState 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.grampscli import CLIManager
from gramps.cli.argparser import ArgParser from gramps.cli.argparser import ArgParser
from gramps.cli.arghandler import ArgHandler from gramps.cli.arghandler import ArgHandler
@ -249,7 +249,7 @@ class Gramps:
from gramps.cli.clidbman import CLIDbManager from gramps.cli.clidbman import CLIDbManager
self.dbstate = dbstate or DbState() self.dbstate = dbstate or DbState()
#we need a manager for the CLI session #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.climanager = CLIManager(self.dbstate, setloader=True, user=self.user)
self.clidbmanager = CLIDbManager(self.dbstate) self.clidbmanager = CLIDbManager(self.dbstate)