Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(34202)

Delta Between Two Patch Sets: Lib/test/test_os.py

Issue 25994: File descriptor leaks in os.scandir()
Left Patch Set: Created 3 years, 8 months ago
Right Patch Set: Created 3 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« Doc/whatsnew/3.6.rst ('K') | « Lib/os.py ('k') | Misc/NEWS » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 # As a test suite for the os module, this is woefully inadequate, but this 1 # As a test suite for the os module, this is woefully inadequate, but this
2 # does add tests for a few functions which have been determined to be more 2 # does add tests for a few functions which have been determined to be more
3 # portable than they had been thought to be. 3 # portable than they had been thought to be.
4 4
5 import asynchat 5 import asynchat
6 import asyncore 6 import asyncore
7 import codecs 7 import codecs
8 import contextlib 8 import contextlib
9 import decimal 9 import decimal
10 import errno 10 import errno
(...skipping 3012 matching lines...) Expand 10 before | Expand all | Expand 10 after
3023 self.assertEqual(len(entries), 1, entries) 3023 self.assertEqual(len(entries), 1, entries)
3024 3024
3025 # check than consuming the iterator twice doesn't raise exception 3025 # check than consuming the iterator twice doesn't raise exception
3026 entries2 = list(iterator) 3026 entries2 = list(iterator)
3027 self.assertEqual(len(entries2), 0, entries2) 3027 self.assertEqual(len(entries2), 0, entries2)
3028 3028
3029 def test_bad_path_type(self): 3029 def test_bad_path_type(self):
3030 for obj in [1234, 1.234, {}, []]: 3030 for obj in [1234, 1.234, {}, []]:
3031 self.assertRaises(TypeError, os.scandir, obj) 3031 self.assertRaises(TypeError, os.scandir, obj)
3032 3032
3033 def test_close(self):
3034 self.create_file("file.txt")
3035 self.create_file("file2.txt")
3036 iterator = os.scandir(self.path)
3037 next(iterator)
3038 iterator.close()
3039 # multiple closes
3040 iterator.close()
3041 # check that there is no warnings
3042 with warnings.catch_warnings(record=True) as w:
3043 warnings.filterwarnings("always", category=ResourceWarning)
3044 del iterator
3045 support.gc_collect()
3046 self.assertEqual(w, [])
3047
3048 def test_context_manager(self):
3049 self.create_file("file.txt")
3050 self.create_file("file2.txt")
3051 with os.scandir(self.path) as iterator:
3052 next(iterator)
3053 # check that there is no warnings
3054 with warnings.catch_warnings(record=True) as w:
3055 warnings.filterwarnings("always", category=ResourceWarning)
3056 del iterator
3057 support.gc_collect()
3058 self.assertEqual(w, [])
3059
3060 def test_context_manager_close(self):
3061 self.create_file("file.txt")
3062 self.create_file("file2.txt")
3063 with os.scandir(self.path) as iterator:
3064 next(iterator)
3065 iterator.close()
3066
3067 def test_context_manager_exception(self):
3068 self.create_file("file.txt")
3069 self.create_file("file2.txt")
3070 with self.assertRaises(ZeroDivisionError):
3071 with os.scandir(self.path) as iterator:
3072 next(iterator)
3073 1/0
3074 # check that there is no warnings
3075 with warnings.catch_warnings(record=True) as w:
3076 warnings.filterwarnings("always", category=ResourceWarning)
3077 del iterator
3078 support.gc_collect()
3079 self.assertEqual(w, [])
3080
3081 def test_resource_warning(self):
3082 self.create_file("file.txt")
3083 self.create_file("file2.txt")
3084 iterator = os.scandir(self.path)
3085 next(iterator)
3086 with self.assertWarns(ResourceWarning):
3087 del iterator
3088 support.gc_collect()
3089 # exhausted iterator
3090 iterator = os.scandir(self.path)
3091 list(iterator)
3092 # check that there is no warnings
3093 with warnings.catch_warnings(record=True) as w:
3094 warnings.filterwarnings("always", category=ResourceWarning)
3095 del iterator
3096 support.gc_collect()
3097 self.assertEqual(w, [])
haypo 2016/02/10 10:25:12 It looks like the code it duplicated 4 times. Why
storchaka 2016/02/10 10:28:54 Well, now may be worth to use it.
3098
3033 3099
3034 if __name__ == "__main__": 3100 if __name__ == "__main__":
3035 unittest.main() 3101 unittest.main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+