File: test_deps.py

package info (click to toggle)
mopidy 3.4.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,616 kB
  • sloc: python: 16,656; sh: 159; makefile: 126
file content (140 lines) | stat: -rw-r--r-- 4,652 bytes parent folder | download | duplicates (4)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import platform
import sys
import unittest
from unittest import mock

import pkg_resources

from mopidy.internal import deps
from mopidy.internal.gi import Gst, gi


class DepsTest(unittest.TestCase):
    def test_format_dependency_list(self):
        adapters = [
            lambda: dict(name="Python", version="FooPython 2.7.3"),
            lambda: dict(name="Platform", version="Loonix 4.0.1"),
            lambda: dict(
                name="Pykka", version="1.1", path="/foo/bar", other="Quux"
            ),
            lambda: dict(name="Foo"),
            lambda: dict(
                name="Mopidy",
                version="0.13",
                dependencies=[
                    dict(
                        name="pylast",
                        version="0.5",
                        dependencies=[dict(name="setuptools", version="0.6")],
                    )
                ],
            ),
        ]

        result = deps.format_dependency_list(adapters)

        assert "Python: FooPython 2.7.3" in result

        assert "Platform: Loonix 4.0.1" in result

        assert "Pykka: 1.1 from /foo/bar" in result
        assert "/baz.py" not in result
        assert "Detailed information: Quux" in result

        assert "Foo: not found" in result

        assert "Mopidy: 0.13" in result
        assert "  pylast: 0.5" in result
        assert "    setuptools: 0.6" in result

    def test_executable_info(self):
        result = deps.executable_info()

        assert "Executable" == result["name"]
        assert sys.argv[0] in result["version"]

    def test_platform_info(self):
        result = deps.platform_info()

        assert "Platform" == result["name"]
        assert platform.platform() in result["version"]

    def test_python_info(self):
        result = deps.python_info()

        assert "Python" == result["name"]
        assert platform.python_implementation() in result["version"]
        assert platform.python_version() in result["version"]
        assert "python" in result["path"]
        assert "platform.py" not in result["path"]

    def test_gstreamer_info(self):
        result = deps.gstreamer_info()

        assert "GStreamer" == result["name"]
        assert ".".join(map(str, Gst.version())) == result["version"]
        assert "gi" in result["path"]
        assert "__init__.py" not in result["path"]
        assert "Python wrapper: python-gi" in result["other"]
        assert gi.__version__ in result["other"]
        assert "Relevant elements:" in result["other"]

    @mock.patch("pkg_resources.get_distribution")
    def test_pkg_info(self, get_distribution_mock):
        dist_setuptools = mock.Mock()
        dist_setuptools.project_name = "setuptools"
        dist_setuptools.version = "0.6"
        dist_setuptools.location = "/tmp/example/setuptools"
        dist_setuptools.requires.return_value = []

        dist_pykka = mock.Mock()
        dist_pykka.project_name = "Pykka"
        dist_pykka.version = "1.1"
        dist_pykka.location = "/tmp/example/pykka"
        dist_pykka.requires.return_value = [dist_setuptools]

        dist_mopidy = mock.Mock()
        dist_mopidy.project_name = "Mopidy"
        dist_mopidy.version = "0.13"
        dist_mopidy.location = "/tmp/example/mopidy"
        dist_mopidy.requires.return_value = [dist_pykka]

        get_distribution_mock.side_effect = [
            dist_mopidy,
            dist_pykka,
            dist_setuptools,
        ]

        result = deps.pkg_info()

        assert "Mopidy" == result["name"]
        assert "0.13" == result["version"]
        assert "mopidy" in result["path"]

        dep_info_pykka = result["dependencies"][0]
        assert "Pykka" == dep_info_pykka["name"]
        assert "1.1" == dep_info_pykka["version"]

        dep_info_setuptools = dep_info_pykka["dependencies"][0]
        assert "setuptools" == dep_info_setuptools["name"]
        assert "0.6" == dep_info_setuptools["version"]

    @mock.patch("pkg_resources.get_distribution")
    def test_pkg_info_for_missing_dist(self, get_distribution_mock):
        get_distribution_mock.side_effect = pkg_resources.DistributionNotFound

        result = deps.pkg_info()

        assert "Mopidy" == result["name"]
        assert "version" not in result
        assert "path" not in result

    @mock.patch("pkg_resources.get_distribution")
    def test_pkg_info_for_wrong_dist_version(self, get_distribution_mock):
        get_distribution_mock.side_effect = pkg_resources.VersionConflict

        result = deps.pkg_info()

        assert "Mopidy" == result["name"]
        assert "version" not in result
        assert "path" not in result