Michael Merickel
2018-10-15 2b024920847481592b1a13d4006d2a9fa8881d72
commit | author | age
b210ce 1 import unittest
CM 2
3 class TestPDistReportCommand(unittest.TestCase):
4     def _callFUT(self, **kw):
5         argv = []
6         from pyramid.scripts.pdistreport import main
7         return main(argv, **kw)
8
9     def test_no_dists(self):
10         def platform():
11             return 'myplatform'
12         pkg_resources = DummyPkgResources()
13         L = []
14         def out(*args):
15             L.extend(args)
16         result = self._callFUT(pkg_resources=pkg_resources, platform=platform,
17                                out=out)
18         self.assertEqual(result, None)
19         self.assertEqual(
20             L,
21             ['Pyramid version:', '1',
22              'Platform:', 'myplatform',
23              'Packages:']
24             )
25
26     def test_with_dists(self):
27         def platform():
28             return 'myplatform'
29         working_set = (DummyDistribution('abc'), DummyDistribution('def'))
30         pkg_resources = DummyPkgResources(working_set)
31         L = []
32         def out(*args):
33             L.extend(args)
34         result = self._callFUT(pkg_resources=pkg_resources, platform=platform,
35                                out=out)
36         self.assertEqual(result, None)
37         self.assertEqual(
38             L,
39             ['Pyramid version:',
40              '1',
41              'Platform:',
42              'myplatform',
43              'Packages:',
44              ' ',
45              'abc',
46              '1',
47              '   ',
48              '/projects/abc',
49              ' ',
50              'def',
51              '1',
52              '   ',
53              '/projects/def']
54             )
55
56 class DummyPkgResources(object):
57     def __init__(self, working_set=()):
58         self.working_set = working_set
59
60     def get_distribution(self, name):
61         return Version('1')
62
63 class Version(object):
64     def __init__(self, version):
65         self.version = version
66
67 class DummyDistribution(object):
68     def __init__(self, name):
69         self.project_name = name
70         self.version = '1'
71         self.location = '/projects/%s' % name
72         
73