This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Fix ResourceWarning in test_pulldom
Type: resource usage Stage: resolved
Components: Tests Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Trundle, beardedp, brett.cannon, nadeem.vawda, python-dev
Priority: normal Keywords: patch

Created on 2011-03-15 05:02 by beardedp, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_pulldom_resource_warning.patch beardedp, 2011-03-15 05:33 Patch to silence resource warning on the test_pulldom test. review
Messages (5)
msg130956 - (view) Author: Ben Hayden (beardedp) * Date: 2011-03-15 05:02
When running the test_pulldom test with a latest checkout of cpython from hg.python.org on Ubuntu 10.10 x64, the following ResourceWarning is thrown:

test_parse (test.test_pulldom.PullDOMTestCase)
Minimal test of DOMEventStream.parse() ... /home/benhayden/Documents/cpython/Lib/test/test_pulldom.py:35: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/benhayden/Documents/cpython/Lib/test/xmltestdata/test.xml' mode='r' encoding='UTF-8'>
  list(pulldom.parse(tstfile))
ok

This is because pulldom.parse returns an open file object if the argument it is passed is a string & not a file object. Attached is a patch that makes sure that file is closed.
msg130969 - (view) Author: Andreas Stührk (Trundle) * Date: 2011-03-15 13:11
Any reason why the patch removes the `list()` calls? Without them, no parsing happens at all.
msg130975 - (view) Author: Ben Hayden (beardedp) * Date: 2011-03-15 14:01
I was unclear as to why the list() calls were there. I thought it would just change the iterator into a list - I didn't know that actually was needed for the test - my mistake. I'll change it back to the list() - but I'll need to loop over the first list to make sure and close the stream.
msg131038 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-03-15 21:23
New changeset aa000dd4287f by Brett Cannon in branch 'default':
Close a stream properly in test.test_pulldom.
http://hg.python.org/cpython/rev/aa000dd4287f
msg131039 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2011-03-15 21:24
Fixed in [aa000dd4287f]. I went with a simpler solution than Ben's, but it did help figure out what to do.
History
Date User Action Args
2022-04-11 14:57:14adminsetgithub: 55759
2011-03-15 21:24:52brett.cannonsetstatus: open -> closed

nosy: + brett.cannon
messages: + msg131039

resolution: fixed
stage: resolved
2011-03-15 21:23:29python-devsetnosy: + python-dev
messages: + msg131038
2011-03-15 20:20:17nadeem.vawdasetnosy: + nadeem.vawda
2011-03-15 14:01:37beardedpsetmessages: + msg130975
2011-03-15 13:11:55Trundlesetnosy: + Trundle
messages: + msg130969
2011-03-15 05:33:51beardedpsetfiles: + test_pulldom_resource_warning.patch
versions: - Python 3.3, Python 3.4
2011-03-15 05:33:24beardedpsetfiles: - test_pulldom_resource_warning.patch
2011-03-15 05:02:30beardedpcreate