forked from Pylons/pyramid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import sys | ||
import platform | ||
import pkg_resources | ||
import optparse | ||
from operator import itemgetter | ||
|
||
def out(*args): # pragma: no cover | ||
for arg in args: | ||
sys.stdout.write(arg) | ||
sys.stdout.write(' ') | ||
sys.stdout.write('\n') | ||
|
||
def main(argv=sys.argv, pkg_resources=pkg_resources, platform=platform.platform, | ||
out=out): | ||
# all args except argv are for unit testing purposes only | ||
description = "Show Python distribution versions and locations in use" | ||
usage = "usage: %prog" | ||
parser = optparse.OptionParser(usage, description=description) | ||
parser.parse_args(argv[1:]) | ||
packages = [] | ||
for distribution in pkg_resources.working_set: | ||
name = distribution.project_name | ||
packages.append( | ||
{'version': distribution.version, | ||
'lowername': name.lower(), | ||
'name': name, | ||
'location':distribution.location} | ||
) | ||
packages = sorted(packages, key=itemgetter('lowername')) | ||
pyramid_version = pkg_resources.get_distribution('pyramid').version | ||
plat = platform() | ||
out('Pyramid version:', pyramid_version) | ||
out('Platform:', plat) | ||
out('Packages:') | ||
for package in packages: | ||
out(' ', package['name'], package['version']) | ||
out(' ', package['location']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import unittest | ||
from pyramid.tests.test_scripts import dummy | ||
|
||
class TestPDistReportCommand(unittest.TestCase): | ||
def _callFUT(self, **kw): | ||
argv = [] | ||
from pyramid.scripts.pdistreport import main | ||
return main(argv, **kw) | ||
|
||
def test_no_dists(self): | ||
def platform(): | ||
return 'myplatform' | ||
pkg_resources = DummyPkgResources() | ||
L = [] | ||
def out(*args): | ||
L.extend(args) | ||
result = self._callFUT(pkg_resources=pkg_resources, platform=platform, | ||
out=out) | ||
self.assertEqual(result, None) | ||
self.assertEqual( | ||
L, | ||
['Pyramid version:', '1', | ||
'Platform:', 'myplatform', | ||
'Packages:'] | ||
) | ||
|
||
def test_with_dists(self): | ||
def platform(): | ||
return 'myplatform' | ||
working_set = (DummyDistribution('abc'), DummyDistribution('def')) | ||
pkg_resources = DummyPkgResources(working_set) | ||
L = [] | ||
def out(*args): | ||
L.extend(args) | ||
result = self._callFUT(pkg_resources=pkg_resources, platform=platform, | ||
out=out) | ||
self.assertEqual(result, None) | ||
self.assertEqual( | ||
L, | ||
['Pyramid version:', | ||
'1', | ||
'Platform:', | ||
'myplatform', | ||
'Packages:', | ||
' ', | ||
'abc', | ||
'1', | ||
' ', | ||
'/projects/abc', | ||
' ', | ||
'def', | ||
'1', | ||
' ', | ||
'/projects/def'] | ||
) | ||
|
||
class DummyPkgResources(object): | ||
def __init__(self, working_set=()): | ||
self.working_set = working_set | ||
|
||
def get_distribution(self, name): | ||
return Version('1') | ||
|
||
class Version(object): | ||
def __init__(self, version): | ||
self.version = version | ||
|
||
class DummyDistribution(object): | ||
def __init__(self, name): | ||
self.project_name = name | ||
self.version = '1' | ||
self.location = '/projects/%s' % name | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters