]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/test/test_version.py
Don't show scary diagnostic warnings from --version[-and-path] (corrected). refs...
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / test / test_version.py
index 9433e36598538a40550b07ddd1be8a385a85a977..8c60530376d90ccc4c4f5531bee1deafc8178db6 100644 (file)
@@ -1,9 +1,12 @@
 
+import sys
+import pkg_resources
 from pkg_resources import Requirement
 
 from twisted.trial import unittest
 
-from allmydata import check_requirement, cross_check, extract_openssl_version, PackagingError
+from allmydata import check_requirement, cross_check, get_package_versions_and_locations, \
+     extract_openssl_version, PackagingError
 from allmydata.util.verlib import NormalizedVersion as V, \
                                   IrrationalVersionError, \
                                   suggest_normalized_version as suggest
@@ -69,6 +72,25 @@ class CheckRequirement(unittest.TestCase):
         for pkg, ver in vers_and_locs.items():
             self.failIf(ver[0] in Requirement.parse(req), str((ver, req)))
 
+    def test_packages_from_pkg_resources(self):
+        if hasattr(sys, 'frozen'):
+            raise unittest.SkipTest("This test doesn't apply to frozen builds.")
+
+        class MockPackage(object):
+            def __init__(self, project_name, version, location):
+                self.project_name = project_name
+                self.version = version
+                self.location = location
+
+        def call_pkg_resources_require(*args):
+            return [MockPackage("Foo", "1.0", "/path")]
+        self.patch(pkg_resources, 'require', call_pkg_resources_require)
+
+        (packages, errors) = get_package_versions_and_locations()
+        self.failUnlessIn(("foo", ("1.0", "/path", "according to pkg_resources")), packages)
+        self.failIfEqual(errors, [])
+        self.failUnlessEqual([e for e in errors if "was not found by pkg_resources" not in e], [])
+
     def test_cross_check_ticket_1355(self):
         # The bug in #1355 is triggered when a version string from either pkg_resources or import
         # is not parseable at all by normalized_version.
@@ -89,8 +111,7 @@ class CheckRequirement(unittest.TestCase):
         self.failUnlessEqual(res, [])
 
         res = cross_check({"foo": ("unparseable", "")}, [])
-        self.failUnlessEqual(len(res), 1)
-        self.failUnlessIn("not found by import", res[0])
+        self.failUnlessEqual(res, [])
 
         res = cross_check({"argparse": ("unparseable", "")}, [])
         self.failUnlessEqual(len(res), 0)