+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
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.
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)