Skip to content

Commit cd75cc6

Browse files
committed
merge multiple fix: python < 3.12 returns ParsingError not RuntimeError; print exception
1 parent 6c46419 commit cd75cc6

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

roundup/configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2660,7 +2660,7 @@ def init_logging(self):
26602660
"Error loading logging config from %(file)s.\n\n"
26612661
" %(msg)s\n\n%(context)s\n" % {
26622662
"file": _file,
2663-
"msg": e.args[0],
2663+
"msg": type(e).__name__ + ": " + str(e),
26642664
"context": " ".join(context),
26652665
}
26662666
)

test/test_config.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ def testIniFileLoggerConfig(self):
17001700
self.assertEqual(
17011701
cm.exception.args[0].replace(r'\\','\\'),
17021702
('Error loading logging config from %s.\n\n'
1703-
" Unknown level: 'DEBUF'\n\n"
1703+
" ValueError: Unknown level: 'DEBUF'\n\n"
17041704
'Inappropriate argument value (of correct type).\n' %
17051705
log_config_filename)
17061706
)
@@ -1718,16 +1718,31 @@ def testIniFileLoggerConfig(self):
17181718
# verify that logging was reset
17191719
# default log config doesn't define handlers for roundup.http
17201720
self.assertEqual(len(logging.getLogger('roundup.http').handlers), 0)
1721+
1722+
output = cm.exception.args[0].replace(r'\\','\\')
1723+
1724+
if sys.version_info >= (3, 12, 0):
1725+
expected = (
1726+
"Error loading logging config from %(filename)s.\n\n"
1727+
" %(filename)s is invalid: Source contains parsing errors: "
1728+
"'%(filename)s'\n\t[line 9]: '=foo\\n'\n\n"
1729+
"Source contains parsing errors: '%(filename)s'\n"
1730+
"\t[line 9]: '=foo\\n' Unspecified run-time error.\n" %
1731+
{"filename": log_config_filename})
1732+
1733+
else: # 3.7 <= x < 3.12.0
1734+
1735+
expected = (
1736+
"Error loading logging config from %(filename)s.\n\n"
1737+
" ParsingError: Source contains parsing errors: "
1738+
"'%(filename)s'\n"
1739+
"\t[line 9]: '=foo\\n'\n\n"
1740+
"Raised when a configuration file does not follow legal "
1741+
"syntax.\n" % {"filename": log_config_filename})
1742+
1743+
print(output)
17211744

1722-
self.assertEqual(
1723-
cm.exception.args[0].replace(r'\\','\\'),
1724-
("Error loading logging config from %(filename)s.\n\n"
1725-
" %(filename)s is invalid: Source contains parsing errors: "
1726-
"'%(filename)s'\n\t[line 9]: '=foo\\n'\n\n"
1727-
"Source contains parsing errors: '%(filename)s'\n"
1728-
"\t[line 9]: '=foo\\n' Unspecified run-time error.\n" %
1729-
{"filename": log_config_filename})
1730-
)
1745+
self.assertEqual(output, expected)
17311746
self.reset_logging()
17321747

17331748
# handler = basic to handler = basi
@@ -1745,7 +1760,7 @@ def testIniFileLoggerConfig(self):
17451760
self.assertEqual(
17461761
cm.exception.args[0].replace(r'\\','\\'),
17471762
("Error loading logging config from %(filename)s.\n\n"
1748-
" basi\n\n"
1763+
" KeyError: 'basi'\n\n"
17491764
"Mapping key not found. No section found with this name.\n" %
17501765
{"filename": log_config_filename})
17511766
)
@@ -1767,7 +1782,7 @@ def testIniFileLoggerConfig(self):
17671782
self.assertEqual(
17681783
cm.exception.args[0].replace(r'\\','\\'),
17691784
("Error loading logging config from %(filename)s.\n\n"
1770-
" No module named 'SHAndler'\n\n"
1785+
" ModuleNotFoundError: No module named 'SHAndler'\n\n"
17711786
"name 'SHAndler' is not defined Module not found.\n" %
17721787
{"filename": log_config_filename})
17731788
)

0 commit comments

Comments
 (0)