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