Source

fsnix / tests / test_fswlib.py

Diff from to

tests/test_fswlib.py

             self.assertRaises(StopIteration, diriter.next)
             dlist.sort()
             self.assertEqual(dlist, ['antelope', 'bear', 'copperhead'])
-            self.assertRaises(select.error, select.select, [d2], [], [])
             # do it again
             select.select([dh], [], [])
-            d3 = os.dup(dh)
-            diriter = fswlib.fditerdir(d3)
-            select.select([d3], [], [])
+            diriter = fswlib.fditerdir(d2)
+            select.select([d2], [], [])
             dlist = []
             dlist.append(diriter.next())
             dlist.append(diriter.next())
             self.assertRaises(StopIteration, diriter.next)
             dlist.sort()
             self.assertEqual(dlist, ['antelope', 'bear', 'copperhead'])
-            self.assertRaises(select.error, select.select, [d3], [], [])
+            os.close(d2)
+            self.assertRaises(select.error, select.select, [d2], [], [])
+            self.assertRaises(OSError, fswlib.fditerdir, d2)
 
     def test_fditerdir_closeearly(self):
         import select
         import gc
         f1 = os.path.join(self.tdir, 'antelope')
-        #f2 = os.path.join(self.tdir, 'bear')
-        #f3 = os.path.join(self.tdir, 'copperhead')
-        with open(f1, 'w') as fh:
-            fh.write('foo\n')
-        #with open(f2, 'w') as fh:
-        #    fh.write('bar\n')
-        #with open(f3, 'w') as fh:
-        #    fh.write('baz\n')
+        f2 = os.path.join(self.tdir, 'bear')
+        f3 = os.path.join(self.tdir, 'copperhead')
+        for fn in [f1, f2, f3]:
+            with open(fn, 'w') as fh:
+                fh.write('foo\n')
         with self.getdir() as dh:
             d2 = os.dup(dh)
             with fswlib.fditerdir(d2) as diriter:
-                self.assertEqual(diriter.next(), 'antelope')
+                self.assertTrue(diriter.next() in ['antelope', 'bear', 'copperhead'])
+            self.assertRaises(StopIteration, diriter.next)
+
+            items = []
+            diriter = fswlib.fditerdir(d2)
+            items.append(diriter.next())
+            os.close(d2)
             self.assertRaises(select.error, select.select, [d2], [], [])
-            d3 = os.dup(dh)
-            select.select([d3], [], [])
-            diriter = fswlib.fditerdir(d3)
-            self.assertEqual(diriter.next(), 'antelope')
-            del diriter
-            gc.collect()
-            self.assertRaises(select.error, select.select, [d3], [], [])
+            items.append(diriter.next())
+            items.append(diriter.next())
+            self.assertRaises(StopIteration, diriter.next)
 
 
     def test_flags(self):