-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure that collection file is closed. Resolves #186. #187
Conversation
Codecov Report
@@ Coverage Diff @@
## master #187 +/- ##
==========================================
+ Coverage 65.03% 65.03% +<.01%
==========================================
Files 37 37
Lines 5531 5532 +1
==========================================
+ Hits 3597 3598 +1
Misses 1934 1934
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #187 +/- ##
==========================================
+ Coverage 65.03% 65.03% +<.01%
==========================================
Files 37 37
Lines 5531 5532 +1
==========================================
+ Hits 3597 3598 +1
Misses 1934 1934
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a unit test that catches the bug, please?
@csadorf I'm not sure how I would do that. Would you want to somehow ensure that a |
Update: I found a way. This is an example of the warning filter I will add. https://stackoverflow.com/questions/24717027/convert-python-3-resourcewarnings-into-exception/25067818#25067818 |
I wasn't able to make this work. I imported def test_read(self):
with Collection.open(self._fn_collection, mode='r') as c:
self.assertEqual(len(list(c)), 3)
with open(self._fn_collection, 'a') as file:
file.write("{'a': 0}\n") # ill-formed JSON (single quotes instead of double quotes)
with self.assertRaises(JSONParseError):
with warnings.catch_warnings():
warnings.simplefilter('error', ResourceWarning)
with Collection.open(self._fn_collection, mode='r') as c:
pass I got the following output: $ python test_collection.py -v FileCollectionTestBadJson.test_read
test_read (__main__.FileCollectionTestBadJson) ... test_collection.py:617: ResourceWarning: unclosed file <_io.TextIOWrapper name='/tmp/signac_collection_7dr7s4cy/test.txt' mode='r' encoding='UTF-8'>
pass
ok
----------------------------------------------------------------------
Ran 1 test in 0.010s
OK I can't get this warning to raise an error even though I directed the |
I don't see why that wouldn't work either... :/ I'm ok with cutting our losses and merge as is. |
Motivation and Context
Resolves unclosed file error in #186.
Types of Changes
Checklist:
If necessary: