Migrate code style to Black

This commit is contained in:
Nick Hall
2023-07-31 14:40:59 +01:00
parent 6cb4380d01
commit 41720c5a7e
1109 changed files with 91319 additions and 67252 deletions

View File

@@ -25,22 +25,25 @@ import logging
import sys
import os
log = logging.getLogger('Gramps.Tests.GrampsLogger')
log = logging.getLogger("Gramps.Tests.GrampsLogger")
import gramps.gen.const as const
const.rootDir = os.path.join(os.path.dirname(__file__), '../../gramps')
sys.path.append(os.path.join(const.rootDir, 'test'))
const.rootDir = os.path.join(os.path.dirname(__file__), "../../gramps")
sys.path.append(os.path.join(const.rootDir, "test"))
try:
from guitest.gtktest import GtkTestCase
TestCaseBase = GtkTestCase
log.info("Using guitest")
except:
TestCaseBase = unittest.TestCase
sys.path.append(const.rootDir)
sys.path.append(os.path.join(const.rootDir, 'GrampsLogger'))
sys.path.append(os.path.join(const.rootDir, "GrampsLogger"))
from gramps.gui.logger import RotateHandler, _errorreportassistant
class ErrorReportAssistantTest(TestCaseBase):
"""Test the ErrorReportAssistant."""
@@ -54,19 +57,20 @@ class ErrorReportAssistantTest(TestCaseBase):
l.addHandler(rh)
l.info("info message")
# Comment this out because there is noone to close the dialogue
# error_detail="Test error"
# ass = _errorreportassistant.ErrorReportAssistant(error_detail=error_detail,
# rotate_handler=rh)
#
# assert ass._error_detail == error_detail
# Comment this out because there is noone to close the dialogue
# error_detail="Test error"
# ass = _errorreportassistant.ErrorReportAssistant(error_detail=error_detail,
# rotate_handler=rh)
#
# assert ass._error_detail == error_detail
l.removeHandler(rh)
def testSuite():
suite = unittest.makeSuite(ErrorReportAssistantTest,'test')
suite = unittest.makeSuite(ErrorReportAssistantTest, "test")
return suite
if __name__ == '__main__':
if __name__ == "__main__":
unittest.TextTestRunner().run(testSuite())

View File

@@ -26,14 +26,16 @@ import sys
from gi.repository import Gtk
import os
log = logging.getLogger('Gramps.Tests.GrampsLogger')
log = logging.getLogger("Gramps.Tests.GrampsLogger")
import gramps.gen.const as const
const.rootDir = os.path.join(os.path.dirname(__file__), '../../gramps')
sys.path.append(os.path.join(const.rootDir, 'test'))
const.rootDir = os.path.join(os.path.dirname(__file__), "../../gramps")
sys.path.append(os.path.join(const.rootDir, "test"))
sys.path.append(const.rootDir)
from gramps.gui.logger import RotateHandler, GtkHandler
class GtkHandlerTest(unittest.TestCase):
"""Test the GtkHandler."""
@@ -56,6 +58,8 @@ class GtkHandlerTest(unittest.TestCase):
l.warn("A warn message")
l.debug("A debug message")
log_message = "Debug message"
# Comment this out because there is noone to close the dialogue
# try:
# wibble
@@ -66,11 +70,10 @@ class GtkHandlerTest(unittest.TestCase):
# Gtk.main_iteration()
def testSuite():
suite = unittest.makeSuite(GtkHandlerTest,'test')
suite = unittest.makeSuite(GtkHandlerTest, "test")
return suite
if __name__ == '__main__':
if __name__ == "__main__":
unittest.TextTestRunner().run(testSuite())

View File

@@ -26,7 +26,7 @@ from bsddb3 import db
print("Test that db.DBEnv().open() works")
with tempfile.TemporaryDirectory() as env_name:
env = db.DBEnv()
env.set_cachesize(0,0x2000000)
env.set_cachesize(0, 0x2000000)
env.set_lk_max_locks(25000)
env.set_lk_max_objects(25000)
# env.set_flags(db.DB_LOG_AUTOREMOVE,1)
@@ -47,14 +47,21 @@ with tempfile.TemporaryDirectory() as env_name:
autoremove_method(autoremove_flag, 1)
else:
print("Failed to set autoremove flag")
env_flags = db.DB_CREATE|db.DB_RECOVER|db.DB_PRIVATE|\
db.DB_INIT_MPOOL|db.DB_INIT_LOCK|\
db.DB_INIT_LOG|db.DB_INIT_TXN|db.DB_THREAD
env_flags = (
db.DB_CREATE
| db.DB_RECOVER
| db.DB_PRIVATE
| db.DB_INIT_MPOOL
| db.DB_INIT_LOCK
| db.DB_INIT_LOG
| db.DB_INIT_TXN
| db.DB_THREAD
)
try:
env.open(env_name,env_flags)
env.open(env_name, env_flags)
except db.DBRunRecoveryError as e:
print("Exception: ")
print(e)
env.remove(env_name)
env.open(env_name,env_flags)
env.open(env_name, env_flags)
print("OK")

View File

@@ -46,32 +46,35 @@ print(sys.path)
tran = None
def dummy_callback(dummy):
pass
def add_source( db,title,commit=True,fail=False):
def add_source(db, title, commit=True, fail=False):
global tran
if tran is None:
tran = db.transaction_begin(DbTxn("add source", db))
db.disable_signals()
s = RelLib.Source()
db.add_source(s,tran)
db.add_source(s, tran)
s.set_title(title)
if fail:
return # Fail here
db.commit_source(s,tran)
return # Fail here
db.commit_source(s, tran)
db.enable_signals()
if commit:
db.transaction_commit(tran)
tran = None
def add_person( db,firstname,lastname,commit=True,fail=False):
def add_person(db, firstname, lastname, commit=True, fail=False):
global tran
if tran is None:
tran = db.transaction_begin(DbTxn("add person", db))
db.disable_signals()
p = RelLib.Person()
db.add_person(p,tran)
db.add_person(p, tran)
n = RelLib.Name()
n.set_first_name(firstname)
s = RelLib.Surname()
@@ -79,23 +82,25 @@ def add_person( db,firstname,lastname,commit=True,fail=False):
n.add_surname(s)
p.set_primary_name(n)
if fail:
return # Fail here
db.commit_person(p,tran)
return # Fail here
db.commit_person(p, tran)
db.enable_signals()
if commit:
db.transaction_commit(tran)
tran = None
def print_db_content(db):
for h in db.get_person_handles():
print("DB contains: person %s" % h)
for h in db.get_source_handles():
print("DB contains: source %s" % h)
tmpdir = tempfile.mkdtemp()
try:
filename1 = os.path.join(tmpdir,'test1.grdb')
filename2 = os.path.join(tmpdir,'test2.grdb')
filename1 = os.path.join(tmpdir, "test1.grdb")
filename2 = os.path.join(tmpdir, "test2.grdb")
print("\nUsing Database file: %s" % filename1)
dbstate = DbState()
dbman = CLIDbManager(dbstate)
@@ -103,16 +108,16 @@ try:
db = make_database("bsddb")
db.load(dirpath, None)
print("Add person 1")
add_person( db,"Anton", "Albers",True,False)
add_person(db, "Anton", "Albers", True, False)
print("Add source")
add_source( db,"A short test",True,False)
add_source(db, "A short test", True, False)
print("Add person 2 without commit")
add_person( db,"Bernd","Beta",False,False)
add_person(db, "Bernd", "Beta", False, False)
print("Add source")
add_source( db,"A short test",True,False)
add_source(db, "A short test", True, False)
print("Add person 3")
add_person( db,"Chris","Connor",True,False)
print_db_content( db)
add_person(db, "Chris", "Connor", True, False)
print_db_content(db)
print("Closing Database file: %s" % filename1)
db.close()
tran = None
@@ -124,10 +129,10 @@ try:
db = make_database("bsddb")
db.load(dirpath, None)
print("Add person 4")
add_person( db,"Felix", "Fowler",True,False)
print ("Add person 4")
add_person( db,"Felix", "Fowler",False,False)
print_db_content( db)
add_person(db, "Felix", "Fowler", True, False)
print("Add person 4")
add_person(db, "Felix", "Fowler", False, False)
print_db_content(db)
print("Closing Database file: %s" % filename1)
db.close()
tran = None
@@ -140,14 +145,14 @@ try:
db.load(dirpath, None)
print("Add source")
add_source( db,"A short test",False,False)
add_source(db, "A short test", False, False)
# actually, adding a second source while the first transaction is not
# committed will just add the second source to the first transaction, so
# nothing special will fail.
print("Add source 2 will fail; but I don't see why it should")
add_source( db,"Bang bang bang",True,True)
add_source(db, "Bang bang bang", True, True)
print_db_content( db)
print_db_content(db)
print("Closing Database file: %s" % filename2)
db.close()
finally:

View File

@@ -31,17 +31,31 @@ import sys
import unittest
from optparse import OptionParser
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
os.environ['GRAMPS_RESOURCES'] = os.path.join(
os.path.dirname(os.path.abspath(__file__)), '..')
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
os.environ["GRAMPS_RESOURCES"] = os.path.join(
os.path.dirname(os.path.abspath(__file__)), ".."
)
def make_parser():
usage = "usage: %prog [options]"
parser = OptionParser(usage)
parser.add_option("-v", "--verbosity", type="int", dest="verbose_level", default=0,
help="Level of verboseness")
parser.add_option("-p", "--performance", action="store_true", dest="performance", default=False,
help="Run the performance tests.")
parser.add_option(
"-v",
"--verbosity",
type="int",
dest="verbose_level",
default=0,
help="Level of verboseness",
)
parser.add_option(
"-p",
"--performance",
action="store_true",
dest="performance",
default=False,
help="Run the performance tests.",
)
return parser
@@ -51,14 +65,16 @@ def getTestSuites():
# a tuple per directory of (dirpath,filelist) if the directory
# contains any test files.
paths = [(f[0],f[2]) for f in os.walk('.') \
if len ([i for i in f[2] \
if i[-8:] == "_Test.py"]) ]
paths = [
(f[0], f[2])
for f in os.walk(".")
if len([i for i in f[2] if i[-8:] == "_Test.py"])
]
test_suites = []
perf_suites = []
for (dir,test_modules) in paths:
for dir, test_modules in paths:
sys.path.append(dir)
for module in test_modules:
@@ -71,23 +87,26 @@ def getTestSuites():
except:
pass
return (test_suites,perf_suites)
return (test_suites, perf_suites)
def allTheTests():
return unittest.TestSuite(getTestSuites()[0])
def perfTests():
return unittest.TestSuite(getTestSuites()[1])
if __name__ == '__main__':
if __name__ == "__main__":
console = logging.StreamHandler()
console.setLevel(logging.INFO)
console.setFormatter(logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s'))
console.setFormatter(logging.Formatter("%(name)-12s: %(levelname)-8s %(message)s"))
logger = logging.getLogger('Gramps')
logger = logging.getLogger("Gramps")
logger.addHandler(console)
(options,args) = make_parser().parse_args()
(options, args) = make_parser().parse_args()
if options.verbose_level == 1:
logger.setLevel(logging.INFO)
@@ -101,7 +120,7 @@ if __name__ == '__main__':
elif options.verbose_level >= 4:
logger.setLevel(logging.NOTSET)
console.setLevel(logging.NOTSET)
os.environ['GRAMPS_SIGNAL'] = "1"
os.environ["GRAMPS_SIGNAL"] = "1"
else:
logger.setLevel(logging.ERROR)
console.setLevel(logging.ERROR)