comparison test/test_config.py @ 8456:9f7e863fd1cd

merge multiple fix: python < 3.12 returns ParsingError not RuntimeError; print exception
author John Rouillard <rouilj@ieee.org>
date Mon, 22 Sep 2025 14:08:36 -0400
parents e91ff70e4563
children f7fadbac5856
comparison
equal deleted inserted replaced
8454:588ae856cd57 8456:9f7e863fd1cd
1698 self.assertEqual(len(logging.getLogger('roundup.http').handlers), 0) 1698 self.assertEqual(len(logging.getLogger('roundup.http').handlers), 0)
1699 1699
1700 self.assertEqual( 1700 self.assertEqual(
1701 cm.exception.args[0].replace(r'\\','\\'), 1701 cm.exception.args[0].replace(r'\\','\\'),
1702 ('Error loading logging config from %s.\n\n' 1702 ('Error loading logging config from %s.\n\n'
1703 " Unknown level: 'DEBUF'\n\n" 1703 " ValueError: Unknown level: 'DEBUF'\n\n"
1704 'Inappropriate argument value (of correct type).\n' % 1704 'Inappropriate argument value (of correct type).\n' %
1705 log_config_filename) 1705 log_config_filename)
1706 ) 1706 )
1707 self.reset_logging() 1707 self.reset_logging()
1708 1708
1709 1709
1710 # add a syntax error "= foo" 1710 # add a syntax error "= foo"
1711 test_config = config1.replace("=DEBUG\n", "=DEBUG\n=foo\n", 1) 1711 test_config = config1.replace("=DEBUG\n", "=DEBUG\n=foo\n", 1)
1712 with open(log_config_filename, "w") as log_config_file:
1713 log_config_file.write(test_config)
1714
1715 with self.assertRaises(configuration.LoggingConfigError) as cm:
1716 config = self.db.config.init_logging()
1717
1718 # verify that logging was reset
1719 # default log config doesn't define handlers for roundup.http
1720 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)
1744
1745 self.assertEqual(output, expected)
1746 self.reset_logging()
1747
1748 # handler = basic to handler = basi
1749 test_config = config1.replace("handlers=basic\n", "handlers=basi\n", 1)
1712 with open(log_config_filename, "w") as log_config_file: 1750 with open(log_config_filename, "w") as log_config_file:
1713 log_config_file.write(test_config) 1751 log_config_file.write(test_config)
1714 1752
1715 with self.assertRaises(configuration.LoggingConfigError) as cm: 1753 with self.assertRaises(configuration.LoggingConfigError) as cm:
1716 config = self.db.config.init_logging() 1754 config = self.db.config.init_logging()
1720 self.assertEqual(len(logging.getLogger('roundup.http').handlers), 0) 1758 self.assertEqual(len(logging.getLogger('roundup.http').handlers), 0)
1721 1759
1722 self.assertEqual( 1760 self.assertEqual(
1723 cm.exception.args[0].replace(r'\\','\\'), 1761 cm.exception.args[0].replace(r'\\','\\'),
1724 ("Error loading logging config from %(filename)s.\n\n" 1762 ("Error loading logging config from %(filename)s.\n\n"
1725 " %(filename)s is invalid: Source contains parsing errors: " 1763 " KeyError: 'basi'\n\n"
1726 "'%(filename)s'\n\t[line 9]: '=foo\\n'\n\n" 1764 "Mapping key not found. No section found with this name.\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}) 1765 {"filename": log_config_filename})
1730 ) 1766 )
1731 self.reset_logging() 1767 self.reset_logging()
1732 1768
1733 # handler = basic to handler = basi 1769 # Change class to missing class
1734 test_config = config1.replace("handlers=basic\n", "handlers=basi\n", 1) 1770 test_config = config1.replace("class=StreamHandler\n",
1771 "class=SHAndler\n", 1)
1735 with open(log_config_filename, "w") as log_config_file: 1772 with open(log_config_filename, "w") as log_config_file:
1736 log_config_file.write(test_config) 1773 log_config_file.write(test_config)
1737 1774
1738 with self.assertRaises(configuration.LoggingConfigError) as cm: 1775 with self.assertRaises(configuration.LoggingConfigError) as cm:
1739 config = self.db.config.init_logging() 1776 config = self.db.config.init_logging()
1743 self.assertEqual(len(logging.getLogger('roundup.http').handlers), 0) 1780 self.assertEqual(len(logging.getLogger('roundup.http').handlers), 0)
1744 1781
1745 self.assertEqual( 1782 self.assertEqual(
1746 cm.exception.args[0].replace(r'\\','\\'), 1783 cm.exception.args[0].replace(r'\\','\\'),
1747 ("Error loading logging config from %(filename)s.\n\n" 1784 ("Error loading logging config from %(filename)s.\n\n"
1748 " basi\n\n" 1785 " ModuleNotFoundError: No module named 'SHAndler'\n\n"
1749 "Mapping key not found. No section found with this name.\n" %
1750 {"filename": log_config_filename})
1751 )
1752 self.reset_logging()
1753
1754 # Change class to missing class
1755 test_config = config1.replace("class=StreamHandler\n",
1756 "class=SHAndler\n", 1)
1757 with open(log_config_filename, "w") as log_config_file:
1758 log_config_file.write(test_config)
1759
1760 with self.assertRaises(configuration.LoggingConfigError) as cm:
1761 config = self.db.config.init_logging()
1762
1763 # verify that logging was reset
1764 # default log config doesn't define handlers for roundup.http
1765 self.assertEqual(len(logging.getLogger('roundup.http').handlers), 0)
1766
1767 self.assertEqual(
1768 cm.exception.args[0].replace(r'\\','\\'),
1769 ("Error loading logging config from %(filename)s.\n\n"
1770 " No module named 'SHAndler'\n\n"
1771 "name 'SHAndler' is not defined Module not found.\n" % 1786 "name 'SHAndler' is not defined Module not found.\n" %
1772 {"filename": log_config_filename}) 1787 {"filename": log_config_filename})
1773 ) 1788 )
1774 self.reset_logging() 1789 self.reset_logging()
1775 1790

Roundup Issue Tracker: http://roundup-tracker.org/