Antoine Pitrou committed 5d81ead

Issue #18: fix iterating over .parents to observe the sequence length

Comments (0)

Files changed (2)

             return len(self._parts)
+    def __iter__(self):
+        for i in range(len(self)):
+            yield self[i]
     def __getitem__(self, idx):
         if idx < 0:
             raise IndexError(idx)
         self.assertEqual(par[1], P('a'))
         self.assertEqual(par[2], P('.'))
         self.assertEqual(par[3], P('.'))
+        self.assertEqual(list(par), [P('a/b'), P('a'), P('.')])
         with self.assertRaises(IndexError):
         with self.assertRaises(TypeError):
         self.assertEqual(par[1], P('/a'))
         self.assertEqual(par[2], P('/'))
         self.assertEqual(par[3], P('/'))
+        self.assertEqual(list(par), [P('/a/b'), P('/a'), P('/')])
     def test_drive_common(self):
         P = self.cls
         self.assertEqual(par[0], P('z:a'))
         self.assertEqual(par[1], P('z:'))
         self.assertEqual(par[2], P('z:'))
+        self.assertEqual(list(par), [P('z:a'), P('z:')])
         p = P('z:/a/b/')
         par = p.parents
         self.assertEqual(len(par), 2)
         self.assertEqual(par[0], P('z:/a'))
         self.assertEqual(par[1], P('z:/'))
         self.assertEqual(par[2], P('z:/'))
+        self.assertEqual(list(par), [P('z:/a'), P('z:/')])
         p = P('//a/b/c/d')
         par = p.parents
         self.assertEqual(len(par), 2)
         self.assertEqual(par[0], P('//a/b/c'))
         self.assertEqual(par[1], P('//a/b'))
         self.assertEqual(par[2], P('//a/b'))
+        self.assertEqual(list(par), [P('//a/b/c'), P('//a/b')])
     def test_drive(self):
         P = self.cls
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.