Commits

Anonymous committed 50ec892

Began writting out tests for the get_distributions function. Currently the tests fails because the Distribution instances are empty. Next step is to test the Distribution class.

Comments (0)

Files changed (14)

src/distutils2/_backport/pkgutil.py

 
     def get_distinfo_files(self, local=False):
         """
-        Iterates over the RECORD entries and returns paths for each line if the path is pointing to a file located in the ``.dist-info`` directory or one of its subdirectories.
-        
+        Iterates over the RECORD entries and returns paths for each line if the 
+        path is pointing to a file located in the ``.dist-info`` directory or 
+        one of its subdirectories.
+
         :parameter local: If *local* is ``True``, each returned path is
                           transformed into a local absolute path. Otherwise the
                           raw value from RECORD is returned.
     them.
 
     :rtype: iterator of :class:`Distribution` instances"""
-    pass
+    for path in sys.path:
+        realpath = os.path.realpath(path)
+        if not os.path.isdir(realpath):
+            continue
+        for dir in os.listdir(realpath):
+            if dir.endswith('.dist-info'):
+                dist = Distribution(os.path.join(realpath, dir))
+                yield dist
 
 def get_distribution(name):
     """
Add a comment to this file

src/distutils2/_backport/tests/fake_dists/choxie-2009.dist-info/INSTALLER

Empty file added.

Add a comment to this file

src/distutils2/_backport/tests/fake_dists/choxie-2009.dist-info/METADATA

Empty file added.

Add a comment to this file

src/distutils2/_backport/tests/fake_dists/choxie-2009.dist-info/RECORD

Empty file added.

Add a comment to this file

src/distutils2/_backport/tests/fake_dists/choxie-2009.dist-info/REQUESTED

Empty file added.

Add a comment to this file

src/distutils2/_backport/tests/fake_dists/grammar-1.0a4.dist-info/INSTALLER

Empty file added.

Add a comment to this file

src/distutils2/_backport/tests/fake_dists/grammar-1.0a4.dist-info/METADATA

Empty file added.

Add a comment to this file

src/distutils2/_backport/tests/fake_dists/grammar-1.0a4.dist-info/RECORD

Empty file added.

Add a comment to this file

src/distutils2/_backport/tests/fake_dists/grammar-1.0a4.dist-info/REQUESTED

Empty file added.

Add a comment to this file

src/distutils2/_backport/tests/fake_dists/towel_stuff-0.1.dist-info/INSTALLER

Empty file added.

Add a comment to this file

src/distutils2/_backport/tests/fake_dists/towel_stuff-0.1.dist-info/METADATA

Empty file added.

Add a comment to this file

src/distutils2/_backport/tests/fake_dists/towel_stuff-0.1.dist-info/RECORD

Empty file added.

Add a comment to this file

src/distutils2/_backport/tests/fake_dists/towel_stuff-0.1.dist-info/REQUESTED

Empty file added.

src/distutils2/_backport/tests/test_pkgutil.py

             dirname = distinfo_dirname(name, version)
             self.assertEqual(dirname, standard_dirname)
 
+    def test_get_distributions(self):
+        """Lookup all distributions found in the ``sys.path``."""
+        # This test could potentially pick up other installed distributions
+        fake_dists = [('grammar', '1.0a4'), ('choxie', '2009'),
+            ('towel-stuff', '0.1')]
+        found_dists = []
+
+        # Setup the path environment with our fake distributions
+        current_path = os.path.abspath(os.path.dirname(__file__))
+        sys.path[0:0] = [os.path.join(current_path, 'fake_dists')]
+
+        # Import the function in question
+        from distutils2._backport.pkgutil import get_distributions, Distribution
+
+        # Verify the fake dists have been found.
+        dists = [ dist for dist in get_distributions() ]
+        for dist in dists:
+            if not isinstance(dist, Distribution):
+                self.fail("item received was not a Distribution instance: "
+                    "%s" % type(dist))
+            if dist.name in dict(fake_dists).keys():
+                found_dists.append((dist.name, dist.metadata.version,))
+            # otherwise we don't care what other distributions are found
+
+        # Finally, test that we found all that we were looking for
+        self.assertListEqual(found_dists, dict(fake_dists).keys())
+
+
 
 def test_suite():
     return unittest2.makeSuite(TestPkgUtil)
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 ProjectModifiedEvent.java.
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.