Merge pull request #1141 from a-andre:raise_min

This commit is contained in:
Nick Hall 2020-11-15 21:30:54 +00:00
commit 1a99f9f7a0
10 changed files with 21 additions and 116 deletions

View File

@ -10,7 +10,7 @@ Requirements
============ ============
The following packages **MUST** be installed in order for Gramps to work: The following packages **MUST** be installed in order for Gramps to work:
* **Python** 3.3 or greater - The programming language used by Gramps. https://www.python.org/ * **Python** 3.5 or greater - The programming language used by Gramps. https://www.python.org/
* **GTK** 3.12 or greater - A cross-platform widget toolkit for creating graphical user interfaces. http://www.gtk.org/ * **GTK** 3.12 or greater - A cross-platform widget toolkit for creating graphical user interfaces. http://www.gtk.org/
* **pygobject** 3.12 or greater - Python Bindings for GLib/GObject/GIO/GTK+ https://wiki.gnome.org/Projects/PyGObject * **pygobject** 3.12 or greater - Python Bindings for GLib/GObject/GIO/GTK+ https://wiki.gnome.org/Projects/PyGObject

View File

@ -22,20 +22,8 @@
""" Unittest for argparser.py """ """ Unittest for argparser.py """
import unittest import unittest
from unittest.mock import Mock
from ..argparser import ArgParser from ..argparser import ArgParser
import sys
try:
if sys.version_info < (3,3):
from mock import Mock
else:
from unittest.mock import Mock
MOCKING = True
except:
MOCKING = False
print ("Mocking disabled", sys.exc_info()[0:2])
class TestArgParser(unittest.TestCase): class TestArgParser(unittest.TestCase):
def setUp(self): def setUp(self):

View File

@ -22,21 +22,10 @@
""" Unittest for user.py """ """ Unittest for user.py """
import unittest import unittest
from unittest.mock import Mock, patch
from .. import user from .. import user
import sys import sys
try:
if sys.version_info < (3,3):
from mock import Mock, patch
else:
from unittest.mock import Mock, patch
MOCKING = True
except:
MOCKING = False
print ("Mocking disabled", sys.exc_info()[0:2])
class TestUser: class TestUser:
TITLE = "Testing prompt" TITLE = "Testing prompt"
MSG = "Choices are hard. Nevertheless, please choose!" MSG = "Choices are hard. Nevertheless, please choose!"
@ -46,10 +35,9 @@ class TestUser:
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()
if MOCKING: self.user = user.User()
self.user = user.User() self.user._fileout = Mock(spec=sys.stderr)
self.user._fileout = Mock(spec=sys.stderr) self.user._input = Mock(spec=input)
self.user._input = Mock(spec=input)
def test_default_fileout_has_write(self): def test_default_fileout_has_write(self):
assert hasattr(self.real_user._fileout, 'write') assert hasattr(self.real_user._fileout, 'write')
@ -57,7 +45,6 @@ class TestUser_prompt(unittest.TestCase):
def test_default_input(self): def test_default_input(self):
assert self.real_user._input.__name__.endswith('input') assert self.real_user._input.__name__.endswith('input')
@unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
def test_prompt_returns_True_if_ACCEPT_entered(self): def test_prompt_returns_True_if_ACCEPT_entered(self):
self.user._input.configure_mock(return_value = TestUser.ACCEPT) self.user._input.configure_mock(return_value = TestUser.ACCEPT)
assert self.user.prompt( assert self.user.prompt(
@ -65,7 +52,6 @@ class TestUser_prompt(unittest.TestCase):
), "True expected!" ), "True expected!"
self.user._input.assert_called_once_with() self.user._input.assert_called_once_with()
@unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
def test_prompt_returns_False_if_REJECT_entered(self): def test_prompt_returns_False_if_REJECT_entered(self):
self.user._input.configure_mock(return_value = TestUser.REJECT) self.user._input.configure_mock(return_value = TestUser.REJECT)
assert not self.user.prompt( assert not self.user.prompt(
@ -87,37 +73,24 @@ class TestUser_prompt(unittest.TestCase):
"'{}' never printed in prompt: {}".format( "'{}' never printed in prompt: {}".format(
text, self.user._fileout.method_calls)) text, self.user._fileout.method_calls))
@unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
def test_prompt_contains_title_text(self): def test_prompt_contains_title_text(self):
self.assert_prompt_contains_text(TestUser.TITLE) self.assert_prompt_contains_text(TestUser.TITLE)
@unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
def test_prompt_contains_msg_text(self): def test_prompt_contains_msg_text(self):
self.assert_prompt_contains_text(TestUser.MSG) self.assert_prompt_contains_text(TestUser.MSG)
@unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
def test_prompt_contains_accept_text(self): def test_prompt_contains_accept_text(self):
self.assert_prompt_contains_text(TestUser.ACCEPT) self.assert_prompt_contains_text(TestUser.ACCEPT)
@unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
def test_prompt_contains_reject_text(self): def test_prompt_contains_reject_text(self):
self.assert_prompt_contains_text(TestUser.REJECT) self.assert_prompt_contains_text(TestUser.REJECT)
@unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
def test_prompt_strips_underscore_in_accept(self): def test_prompt_strips_underscore_in_accept(self):
self.assert_prompt_contains_text("accepT", accept="accep_T") self.assert_prompt_contains_text("accepT", accept="accep_T")
@unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
def test_prompt_strips_underscore_in_reject(self): def test_prompt_strips_underscore_in_reject(self):
self.assert_prompt_contains_text("reJect", reject="re_Ject") self.assert_prompt_contains_text("reJect", reject="re_Ject")
if not MOCKING: #don't use SKIP, to avoid counting a skipped test
def test_manual_run(self):
b = self.real_user.prompt(
TestUser.TITLE, TestUser.MSG, TestUser.ACCEPT, TestUser.REJECT)
print ("Returned: {}".format(b))
@unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
def test_auto_accept_accepts_without_prompting(self): def test_auto_accept_accepts_without_prompting(self):
u = user.User(auto_accept=True) u = user.User(auto_accept=True)
u._fileout = Mock(spec=sys.stderr) u._fileout = Mock(spec=sys.stderr)
@ -126,7 +99,6 @@ class TestUser_prompt(unittest.TestCase):
), "True expected!" ), "True expected!"
assert len(u._fileout.method_calls) == 0, list(u._fileout.method_calls) assert len(u._fileout.method_calls) == 0, list(u._fileout.method_calls)
@unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
def test_EOFError_in_prompt_caught_as_False(self): def test_EOFError_in_prompt_caught_as_False(self):
self.user._input.configure_mock( self.user._input.configure_mock(
side_effect = EOFError, side_effect = EOFError,
@ -136,7 +108,6 @@ class TestUser_prompt(unittest.TestCase):
), "False expected!" ), "False expected!"
self.user._input.assert_called_once_with() self.user._input.assert_called_once_with()
@unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
class TestUser_quiet(unittest.TestCase): class TestUser_quiet(unittest.TestCase):
def setUp(self): def setUp(self):
self.user = user.User(quiet=True) self.user = user.User(quiet=True)
@ -152,7 +123,6 @@ class TestUser_quiet(unittest.TestCase):
assert len(self.user._fileout.method_calls assert len(self.user._fileout.method_calls
) == 0, list(self.user._fileout.method_calls) ) == 0, list(self.user._fileout.method_calls)
@unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
class TestUser_progress(unittest.TestCase): class TestUser_progress(unittest.TestCase):
def setUp(self): def setUp(self):

View File

@ -35,6 +35,7 @@ import ast
import sys import sys
import datetime import datetime
import glob import glob
from pathlib import Path
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -67,17 +68,6 @@ LOG = logging.getLogger(DBLOGNAME)
SIGBASE = ('person', 'family', 'source', 'event', 'media', SIGBASE = ('person', 'family', 'source', 'event', 'media',
'place', 'repository', 'reference', 'note', 'tag', 'citation') 'place', 'repository', 'reference', 'note', 'tag', 'citation')
def touch(fname, mode=0o666, dir_fd=None, **kwargs):
## After http://stackoverflow.com/questions/1158076/implement-touch-using-python
if sys.version_info < (3, 3, 0):
with open(fname, 'a'):
os.utime(fname, None) # set to now
else:
flags = os.O_CREAT | os.O_APPEND
with os.fdopen(os.open(fname, flags=flags, mode=mode, dir_fd=dir_fd)) as f:
os.utime(f.fileno() if os.utime in os.supports_fd else fname,
dir_fd=None if os.supports_fd else dir_fd, **kwargs)
class DbGenericUndo(DbUndo): class DbGenericUndo(DbUndo):
def __init__(self, grampsdb, path): def __init__(self, grampsdb, path):
super(DbGenericUndo, self).__init__(grampsdb) super(DbGenericUndo, self).__init__(grampsdb)
@ -691,7 +681,7 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
# This is just a dummy file to indicate last modified time of # This is just a dummy file to indicate last modified time of
# the database for gramps.cli.clidbman: # the database for gramps.cli.clidbman:
filename = os.path.join(self._directory, "meta_data.db") filename = os.path.join(self._directory, "meta_data.db")
touch(filename) Path(filename).touch()
# Save metadata # Save metadata
self._set_metadata('name_formats', self.name_formats) self._set_metadata('name_formats', self.name_formats)

View File

@ -20,19 +20,7 @@
# #
import unittest import unittest
import sys from unittest.mock import Mock
try:
if sys.version_info < (3,3):
from mock import Mock
else:
from unittest.mock import Mock
MOCKING = True
except:
MOCKING = False
print ("Mocking disabled, some testing skipped", sys.exc_info()[0:2])
class LexGettextTest(unittest.TestCase): class LexGettextTest(unittest.TestCase):
SRC_WORD = "Inflect-me" SRC_WORD = "Inflect-me"
@ -45,19 +33,15 @@ class LexGettextTest(unittest.TestCase):
self.trans = GrampsTranslations() self.trans = GrampsTranslations()
def setup_sgettext_mock(self, msgval_expected): def setup_sgettext_mock(self, msgval_expected):
if MOCKING: mock = Mock(return_value=msgval_expected)
mock = Mock(return_value=msgval_expected)
else:
mock = lambda msgid: msgval_expected
self.trans.sgettext = mock self.trans.sgettext = mock
def tearDown(self): def tearDown(self):
if MOCKING: try:
try: self.trans.sgettext.assert_called_once_with(
self.trans.sgettext.assert_called_once_with( self.MSGID, self.CONTEXT)
self.MSGID, self.CONTEXT) except AttributeError as e:
except AttributeError as e: print ("Apparently the test has never set up the mock: ", e)
print ("Apparently the test has never set up the mock: ", e)
def testSrcWordOnlyIfNoTranslation(self): def testSrcWordOnlyIfNoTranslation(self):
self.setup_sgettext_mock(self.SRC_WORD) self.setup_sgettext_mock(self.SRC_WORD)

View File

@ -167,7 +167,7 @@ from .gen.mime import mime_type_is_defined
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
MIN_PYTHON_VERSION = (3, 3, 0, '', 0) MIN_PYTHON_VERSION = (3, 5, 0, '', 0)
if not sys.version_info >= MIN_PYTHON_VERSION: if not sys.version_info >= MIN_PYTHON_VERSION:
logging.warning(_("Your Python version does not meet the " logging.warning(_("Your Python version does not meet the "
"requirements. At least python %(v1)d.%(v2)d.%(v3)d is needed to" "requirements. At least python %(v1)d.%(v2)d.%(v3)d is needed to"

View File

@ -75,9 +75,4 @@ def display_url(link, uistate=None):
""" """
Open the specified URL in a browser. Open the specified URL in a browser.
""" """
if (mac() and sys.version_info.major == 3 and sys.version_info.minor < 5): webbrowser.open_new_tab(link)
import subprocess
proc = subprocess.call(['/usr/bin/open', link],
stderr=subprocess.STDOUT)
else:
webbrowser.open_new_tab(link)

View File

@ -21,16 +21,8 @@
""" Unittest for editreference.py """ """ Unittest for editreference.py """
import unittest import unittest
import sys from unittest.mock import Mock, patch
import os import os
try:
if sys.version_info < (3,3):
from mock import Mock, patch
else:
from unittest.mock import Mock, patch
MOCKING = True
except:
MOCKING = False
from gramps.gen.lib import (Person, Family, Event, Source, Place, Citation, from gramps.gen.lib import (Person, Family, Event, Source, Place, Citation,
Repository, Media, Note, Tag) Repository, Media, Note, Tag)
@ -54,7 +46,6 @@ class MockEditReference(EditReference):
class TestEditReference(unittest.TestCase): class TestEditReference(unittest.TestCase):
@unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
def test_editreference(self): def test_editreference(self):
dbstate = DbState() dbstate = DbState()
db = make_database("sqlite") db = make_database("sqlite")

View File

@ -22,20 +22,8 @@
""" Unittest for user.py """ """ Unittest for user.py """
import unittest import unittest
from unittest.mock import Mock, patch
from .. import user from .. import user
import sys
try:
if sys.version_info < (3,3):
from mock import Mock, patch
else:
from unittest.mock import Mock, patch
MOCKING = True
except:
MOCKING = False
print ("Mocking disabled", sys.exc_info()[0:2])
class TestUser: class TestUser:
TITLE = "Testing prompt" TITLE = "Testing prompt"
@ -47,7 +35,6 @@ class TestUser_prompt(unittest.TestCase):
def setUp(self): def setUp(self):
self.user = user.User() self.user = user.User()
@unittest.skipUnless(MOCKING, "Requires unittest.mock to run")
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,

View File

@ -29,8 +29,8 @@ Gramps distutils module.
#check python version first #check python version first
import sys import sys
if sys.version_info < (3, 2): if sys.version_info < (3, 5):
raise SystemExit("Gramps requires Python 3.2 or later.") raise SystemExit("Gramps requires Python 3.5 or later.")
from distutils import log from distutils import log
from setuptools import setup from setuptools import setup