Tidy up mocking code (#438)[First commit]
This commit is contained in:
parent
c5f2717623
commit
8ebb4d35fa
@ -29,7 +29,7 @@ Make an 'Unknown' primary object
|
||||
# Python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from time import strftime, localtime, time
|
||||
from time import strftime, time
|
||||
import os
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -147,7 +147,7 @@ def make_unknown(class_arg, explanation, class_func, commit_func, transaction,
|
||||
if not hasattr(make_unknown, 'count'):
|
||||
make_unknown.count = 1 #primitive static variable
|
||||
obj.set_name(_("Unknown, was missing %(time)s (%(count)d)") % {
|
||||
'time': strftime('%x %X', localtime()),
|
||||
'time': strftime('%x %X'),
|
||||
'count': make_unknown.count})
|
||||
make_unknown.count += 1
|
||||
else:
|
||||
@ -167,7 +167,7 @@ def create_explanation_note(dbase):
|
||||
"""
|
||||
note = Note( _('Objects referenced by this note '
|
||||
'were missing in a file imported on %s.') %
|
||||
strftime('%x %X', localtime()))
|
||||
strftime('%x %X'))
|
||||
note.set_handle(create_id())
|
||||
note.set_gramps_id(dbase.find_next_note_gramps_id())
|
||||
# Use defaults for privacy, format and type.
|
||||
|
@ -213,7 +213,7 @@ class ProgenOptions(ManagedWindow):
|
||||
# initial values
|
||||
text = "Pro-Gen Import"
|
||||
fname = os.path.basename(filename).split('\\')[-1]
|
||||
date = time.strftime('%Y-%m-%d', time.localtime())
|
||||
date = time.strftime("%Y-%m-%d")
|
||||
|
||||
# add import source title/confidence
|
||||
# citation page/confidence/privacy/attribute
|
||||
|
@ -26,7 +26,7 @@ import os
|
||||
import sys
|
||||
import re
|
||||
import locale
|
||||
from time import localtime, strptime
|
||||
from time import strptime, strftime
|
||||
from unittest.mock import patch
|
||||
#import logging
|
||||
|
||||
@ -65,6 +65,12 @@ def mock_localtime(*args):
|
||||
"""
|
||||
return strptime("25 Dec 1999", "%d %b %Y")
|
||||
|
||||
def mock_strftime(*args):
|
||||
"""
|
||||
Mock up a dummy to replace the varying 'time string results'
|
||||
"""
|
||||
return strftime(args[0], (1999, 12, 25, 0, 0, 0, 5, 359, -1))
|
||||
|
||||
class TestImports(unittest.TestCase):
|
||||
"""The test class cases will be dynamically created at import time from
|
||||
files to be tested. The following defs are used by the test cases
|
||||
@ -193,21 +199,12 @@ def make_tst_function(tstfile, file_name):
|
||||
""" This is here to support the dynamic function creation. This creates
|
||||
the test function (a method, to be precise).
|
||||
"""
|
||||
|
||||
@patch('gramps.plugins.db.dbapi.dbapi.time')
|
||||
@patch('gramps.plugins.db.bsddb.write.time')
|
||||
@patch('gramps.gen.utils.unknown.localtime')
|
||||
@patch('gramps.gen.utils.unknown.time')
|
||||
@patch('time.localtime')
|
||||
def tst(self, mockptime, mocktime, mockltime, mockwtime, mockdtime):
|
||||
@patch('gramps.gen.utils.unknown.strftime', side_effect=mock_strftime)
|
||||
@patch('time.strftime', side_effect=mock_strftime)
|
||||
def tst(self, mstrftime1, mstrftime2):
|
||||
""" This compares the import file with the expected result '.gramps'
|
||||
file.
|
||||
"""
|
||||
mockptime.side_effect = mock_localtime
|
||||
mocktime.side_effect = mock_time
|
||||
mockltime.side_effect = mock_localtime
|
||||
mockwtime.side_effect = mock_time
|
||||
mockdtime.side_effect = mock_time
|
||||
fn1 = os.path.join(TEST_DIR, tstfile)
|
||||
fn2 = os.path.join(TEST_DIR, (file_name + ".gramps"))
|
||||
fres = os.path.join(TEMP_DIR, (file_name + ".difs"))
|
||||
|
Loading…
Reference in New Issue
Block a user