File: test_pdistreport.py

package info (click to toggle)
python-pyramid 1.6%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 9,112 kB
  • ctags: 8,169
  • sloc: python: 41,764; makefile: 111; sh: 17
file content (73 lines) | stat: -rw-r--r-- 2,007 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import unittest

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