diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2022-02-21 13:53:19 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2022-02-21 13:53:19 +0000 |
| commit | efa553b5fe672040d95031dc2b713cc5c0bdc494 (patch) | |
| tree | e47fc64b9278090bf6e3ded2202e63b75cf1c502 /test/test_settings.py | |
| parent | b0cc68c55de7471cf9020f31e39e8885523b2c21 (diff) | |
| download | docutils-efa553b5fe672040d95031dc2b713cc5c0bdc494.tar.gz | |
Test error reporting for config file syntax errors.
Config file syntax errors should be reported with
position (file and section) also for errors
raised by validation with frontend.validate_*().
git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk/docutils@9010 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'test/test_settings.py')
| -rwxr-xr-x | test/test_settings.py | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/test/test_settings.py b/test/test_settings.py index 94babd1d0..83213757e 100755 --- a/test/test_settings.py +++ b/test/test_settings.py @@ -28,8 +28,10 @@ class ConfigFileTests(unittest.TestCase): 'two': fixpath('data/config_2.txt'), 'list': fixpath('data/config_list.txt'), 'list2': fixpath('data/config_list_2.txt'), - 'error': fixpath('data/config_error_handler.txt'), - 'error2': fixpath('data/config_error_handler_2.txt')} + 'error': fixpath('data/config_encoding.txt'), + 'error2': fixpath('data/config_encoding_2.txt'), + 'syntax_error': fixpath('data/config_syntax_error.txt'), + } # expected settings after parsing the equally named config_file: settings = { @@ -106,6 +108,8 @@ class ConfigFileTests(unittest.TestCase): def setUp(self): warnings.filterwarnings(action='ignore', category=frontend.ConfigDeprecationWarning) + warnings.filterwarnings(action='ignore', module='docutils.frontend', + category=PendingDeprecationWarning) self.option_parser = frontend.OptionParser( components=(pep_html.Writer, rst.Parser), read_config_files=None) @@ -146,14 +150,16 @@ class ConfigFileTests(unittest.TestCase): self.expected_settings()) def test_old(self): - with warnings.catch_warnings(record=True) as wngs: - warnings.simplefilter("always") # also deprecation warning - self.compare_output(self.files_settings('old'), - self.expected_settings('old')) - warnings.filterwarnings(action='ignore', - category=frontend.ConfigDeprecationWarning) - self.assertTrue(len(wngs) > 0, "Expected a FutureWarning.") - assert any(issubclass(wng.category, FutureWarning) for wng in wngs) + with self.assertWarnsRegex(FutureWarning, + 'The "\[option\]" section is deprecated.'): + self.files_settings('old') + + def test_syntax_error(self): + with self.assertRaisesRegex( + ValueError, + 'Error in config file ".*config_syntax_error.txt", ' + 'section "\[general\]"'): + self.files_settings('syntax_error') def test_one(self): self.compare_output(self.files_settings('one'), @@ -185,12 +191,12 @@ class ConfigFileTests(unittest.TestCase): self.compare_output(self.files_settings('list', 'list2'), self.expected_settings('list2')) - def test_error_handler(self): + def test_encoding_error_handler(self): # set error_encoding and error_encoding_error_handler (from affix) self.compare_output(self.files_settings('error'), self.expected_settings('error')) - def test_error_handler2(self): + def test_encoding_error_handler2(self): # second config file only changes encoding, not error_handler: self.compare_output(self.files_settings('error', 'error2'), self.expected_settings('error', 'error2')) @@ -217,6 +223,8 @@ class ConfigEnvVarFileTests(ConfigFileTests): def tearDown(self): os.environ = self.orig_environ + def test_old(self): pass # don't repreat this test + @unittest.skipUnless(os.name, 'posix') def test_get_standard_config_files(self): os.environ['HOME'] = '/home/parrot' @@ -339,11 +347,9 @@ class HelperFunctionsTests(unittest.TestCase): def test_set_conditions_deprecation_warning(self): reporter = utils.Reporter('test', 1, 4) - with warnings.catch_warnings(record=True) as wng: - warnings.simplefilter("always") + with self.assertWarnsRegex(DeprecationWarning, + 'Set attributes via configuration settings'): reporter.set_conditions('foo', 1, 4) # trigger warning - self.assertEqual(len(wng), 1, "Expected a DeprecationWarning.") - assert issubclass(wng[-1].category, DeprecationWarning) if __name__ == '__main__': unittest.main() |
