|
From: <mi...@us...> - 2022-01-06 00:26:22
|
Revision: 8933
http://sourceforge.net/p/docutils/code/8933
Author: milde
Date: 2022-01-06 00:26:19 +0000 (Thu, 06 Jan 2022)
Log Message:
-----------
Fix/silence DeprecationWarnings and RessourceWarnings.
Found by Tomasz K{U+0142}oczko running "pytest" (cf. feature-request #81)
and by running `python3 -W all alltests.py`.
Modified Paths:
--------------
trunk/docutils/docutils/parsers/rst/directives/images.py
trunk/docutils/docutils/writers/html4css1/__init__.py
trunk/docutils/test/DocutilsTestSupport.py
trunk/docutils/test/test_dependencies.py
trunk/docutils/test/test_parsers/test_recommonmark/test_misc.py
trunk/docutils/test/test_parsers/test_recommonmark/test_section_headers.py
trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py
trunk/docutils/test/test_settings.py
trunk/docutils/test/test_transforms/test_writer_aux.py
Modified: trunk/docutils/docutils/parsers/rst/directives/images.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/images.py 2022-01-05 14:59:31 UTC (rev 8932)
+++ trunk/docutils/docutils/parsers/rst/directives/images.py 2022-01-06 00:26:19 UTC (rev 8933)
@@ -129,15 +129,14 @@
if PIL and self.state.document.settings.file_insertion_enabled:
imagepath = url2pathname(image_node['uri'])
try:
- img = PIL.Image.open(
- imagepath.encode(sys.getfilesystemencoding()))
+ with PIL.Image.open(imagepath.encode(
+ sys.getfilesystemencoding())) as img:
+ figure_node['width'] = '%dpx' % img.size[0]
except (IOError, UnicodeEncodeError):
pass # TODO: warn?
else:
self.state.document.settings.record_dependencies.add(
imagepath.replace('\\', '/'))
- figure_node['width'] = '%dpx' % img.size[0]
- del img
elif figwidth is not None:
figure_node['width'] = figwidth
if figclasses:
Modified: trunk/docutils/docutils/writers/html4css1/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/html4css1/__init__.py 2022-01-05 14:59:31 UTC (rev 8932)
+++ trunk/docutils/docutils/writers/html4css1/__init__.py 2022-01-06 00:26:19 UTC (rev 8933)
@@ -564,8 +564,9 @@
and self.settings.file_insertion_enabled):
imagepath = url2pathname(uri)
try:
- img = PIL.Image.open(
- imagepath.encode(sys.getfilesystemencoding()))
+ with PIL.Image.open(imagepath.encode(
+ sys.getfilesystemencoding())) as img:
+ img_size = img.size
except (IOError, UnicodeEncodeError):
pass # TODO: warn?
else:
@@ -572,10 +573,9 @@
self.settings.record_dependencies.add(
imagepath.replace('\\', '/'))
if 'width' not in atts:
- atts['width'] = '%dpx' % img.size[0]
+ atts['width'] = '%dpx' % img_size[0]
if 'height' not in atts:
- atts['height'] = '%dpx' % img.size[1]
- del img
+ atts['height'] = '%dpx' % img_size[1]
for att_name in 'width', 'height':
if att_name in atts:
match = re.match(r'([0-9.]+)(\S*)$', atts[att_name])
Modified: trunk/docutils/test/DocutilsTestSupport.py
===================================================================
--- trunk/docutils/test/DocutilsTestSupport.py 2022-01-05 14:59:31 UTC (rev 8932)
+++ trunk/docutils/test/DocutilsTestSupport.py 2022-01-06 00:26:19 UTC (rev 8933)
@@ -538,8 +538,6 @@
import recommonmark
if recommonmark.__version__ != '0.4.0':
return
- # suppress UserWarnings from recommonmark parser
- warnings.filterwarnings('ignore', message='Unsupported.*type')
ParserTestSuite.generateTests(self, dict, dictname='totest')
Modified: trunk/docutils/test/test_dependencies.py
===================================================================
--- trunk/docutils/test/test_dependencies.py 2022-01-05 14:59:31 UTC (rev 8932)
+++ trunk/docutils/test/test_dependencies.py 2022-01-06 00:26:19 UTC (rev 8933)
@@ -49,7 +49,7 @@
encoding='utf8')
return record.read().splitlines()
- def test_dependencies(self):
+ def test_dependencies_xml(self):
# Note: currently, raw input files are read (and hence recorded) while
# parsing even if not used in the chosen output format.
# This should change (see parsers/rst/directives/misc.py).
Modified: trunk/docutils/test/test_parsers/test_recommonmark/test_misc.py
===================================================================
--- trunk/docutils/test/test_parsers/test_recommonmark/test_misc.py 2022-01-05 14:59:31 UTC (rev 8932)
+++ trunk/docutils/test/test_parsers/test_recommonmark/test_misc.py 2022-01-06 00:26:19 UTC (rev 8933)
@@ -15,6 +15,7 @@
import sys
import unittest
+import warnings
if __name__ == '__main__':
import __init__
@@ -62,6 +63,9 @@
@unittest.skipUnless(parser_class, skip_msg)
def test_raw_disabled(self):
+ # silence Warnings in recommonmark (unmaintained 3rd party module):
+ warnings.filterwarnings('ignore', category=DeprecationWarning,
+ module='recommonmark')
output = publish_string(sample_with_html, parser_name='recommonmark',
settings_overrides={'warning_stream': '',
'raw_enabled': False,
Modified: trunk/docutils/test/test_parsers/test_recommonmark/test_section_headers.py
===================================================================
--- trunk/docutils/test/test_parsers/test_recommonmark/test_section_headers.py 2022-01-05 14:59:31 UTC (rev 8932)
+++ trunk/docutils/test/test_parsers/test_recommonmark/test_section_headers.py 2022-01-06 00:26:19 UTC (rev 8933)
@@ -31,8 +31,7 @@
=========
Paragraph.
""",
-"""\
-<document source="test data">
+r"""<document source="test data">
<section ids="the-title" names="the\ title">
<title>
The Title
@@ -44,8 +43,7 @@
=====================
Paragraph (no blank line required).
""",
-"""\
-<document source="test data">
+r"""<document source="test data">
<section ids="another-section-title" names="another\ section\ title">
<title>
Another Section Title
@@ -158,7 +156,7 @@
### Title 5
""",
-"""\
+r"""
<document source="test data">
<paragraph>
Test bad subsection order.
Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py 2022-01-05 14:59:31 UTC (rev 8932)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py 2022-01-06 00:26:19 UTC (rev 8933)
@@ -47,8 +47,7 @@
with open(utf_16_csv, 'rb') as f:
csv_data = f.read()
csv_data = str(csv_data, 'latin1').splitlines()
- reader = csv.reader([tables.CSVTable.encode_for_csv(line + '\n')
- for line in csv_data])
+ reader = csv.reader([line + '\n' for line in csv_data])
next(reader)
null_bytes_exception = DocutilsTestSupport.exception_data(null_bytes)[0]
Modified: trunk/docutils/test/test_settings.py
===================================================================
--- trunk/docutils/test/test_settings.py 2022-01-05 14:59:31 UTC (rev 8932)
+++ trunk/docutils/test/test_settings.py 2022-01-06 00:26:19 UTC (rev 8933)
@@ -122,6 +122,8 @@
warnings.simplefilter("always") # check also for deprecation warning
self.compare_output(self.files_settings('old'),
self.expected_settings('old'))
+ warnings.filterwarnings(action='ignore',
+ category=frontend.ConfigDeprecationWarning)
self.assertEqual(len(wng), 1, "Expected a FutureWarning.")
assert issubclass(wng[-1].category, FutureWarning)
Modified: trunk/docutils/test/test_transforms/test_writer_aux.py
===================================================================
--- trunk/docutils/test/test_transforms/test_writer_aux.py 2022-01-05 14:59:31 UTC (rev 8932)
+++ trunk/docutils/test/test_transforms/test_writer_aux.py 2022-01-06 00:26:19 UTC (rev 8933)
@@ -23,34 +23,6 @@
totest = {}
-totest['compound'] = ((writer_aux.Compound,), [
-["""\
-.. class:: compound
-
-.. compound::
-
- .. class:: paragraph1
-
- Paragraph 1.
-
- .. class:: paragraph2
-
- Paragraph 2.
-
- Block quote.
-""",
-"""\
-<document source="test data">
- <paragraph classes="paragraph1 compound">
- Paragraph 1.
- <paragraph classes="paragraph2 continued">
- Paragraph 2.
- <block_quote classes="continued">
- <paragraph>
- Block quote.
-"""],
-])
-
totest['admonitions'] = ((writer_aux.Admonitions,), [
["""\
.. note::
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|