File: test_setup.py

package info (click to toggle)
mysql-connector-python 2.1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 12,968 kB
  • ctags: 4,120
  • sloc: python: 23,410; ansic: 2,621; makefile: 27; cpp: 1
file content (142 lines) | stat: -rw-r--r-- 5,093 bytes parent folder | download
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
141
142
# MySQL Connector/Python - MySQL driver written in Python.
# Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.

# MySQL Connector/Python is licensed under the terms of the GPLv2
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
# MySQL Connectors. There are special exceptions to the terms and
# conditions of the GPLv2 as it is applied to this software, see the
# FOSS License Exception
# <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

"""Unit tests for the setup script of Connector/Python
"""

import sys
import tests
import imp

import setupinfo


class VersionTests(tests.MySQLConnectorTests):

    """Testing the version of Connector/Python"""

    def test_version(self):
        """Test validity of version"""
        vs = setupinfo.VERSION
        self.assertTrue(all(
            [isinstance(vs[0], int),
             isinstance(vs[1], int),
             isinstance(vs[2], int),
             isinstance(vs[3], str),
             isinstance(vs[4], int)]))

    def test___version__(self):
        """Test module __version__ and __version_info__"""
        import mysql.connector
        self.assertTrue(hasattr(mysql.connector, '__version__'))
        self.assertTrue(hasattr(mysql.connector, '__version_info__'))
        self.assertTrue(isinstance(mysql.connector.__version__, str))
        self.assertTrue(isinstance(mysql.connector.__version_info__, tuple))
        self.assertEqual(setupinfo.VERSION_TEXT, mysql.connector.__version__)
        self.assertEqual(setupinfo.VERSION, mysql.connector.__version_info__)


class SetupInfoTests(tests.MySQLConnectorTests):

    """Testing meta setup information

    We are importing the setupinfo module insite the unit tests
    to be able to actually do tests.
    """

    def setUp(self):
        # we temper with version_info, play safe, keep copy
        self._sys_version_info = sys.version_info

    def tearDown(self):
        # we temper with version_info, play safe, restore copy
        sys.version_info = self._sys_version_info

    def test_name(self):
        """Test the name of Connector/Python"""
        import setupinfo
        self.assertEqual('mysql-connector-python', setupinfo.name)

    def test_dev_statuses(self):
        """Test the development statuses"""
        import setupinfo
        exp = {
            'a': '3 - Alpha',
            'b': '4 - Beta',
            'rc': '4 - Beta',
            '': '5 - Production/Stable'
        }
        self.assertEqual(exp, setupinfo.DEVELOPMENT_STATUSES)

    def test_package_dir(self):
        """Test the package directory"""
        import setupinfo
        exp = {
            '': 'lib',
        }
        self.assertEqual(exp, setupinfo.package_dir)

    def test_unsupported_python(self):
        """Test if old Python version are unsupported"""
        import setupinfo
        tmp = sys.version_info
        sys.version_info = (3, 0, 0, 'final', 0)
        try:
            imp.reload(setupinfo)
        except RuntimeError:
            pass
        else:
            self.fail("RuntimeError not raised with unsupported Python")
        sys.version_info = tmp

    def test_version(self):
        """Test the imported version information"""
        import setupinfo
        ver = setupinfo.VERSION
        exp = '{0}.{1}.{2}'.format(*ver[0:3])
        self.assertEqual(exp, setupinfo.version)

    def test_misc_meta(self):
        """Test miscellaneous data such as URLs"""
        import setupinfo
        self.assertEqual(
            'http://dev.mysql.com/doc/connector-python/en/index.html',
            setupinfo.url)
        self.assertEqual(
            'http://dev.mysql.com/downloads/connector/python/',
            setupinfo.download_url)

    def test_classifiers(self):
        """Test Trove classifiers"""
        import setupinfo
        for clsfr in setupinfo.classifiers:
            if 'Programming Language :: Python' in clsfr:
                ver = clsfr.replace('Programming Language :: Python :: ', '')
                if ver not in ('2.6', '2.7', '3', '3.1', '3.2', '3.3', '3.4',
                               '3.5'):
                    self.fail('Unsupported version in classifiers')
            if 'Development Status ::' in clsfr:
                status = clsfr.replace('Development Status :: ', '')
                self.assertEqual(
                    setupinfo.DEVELOPMENT_STATUSES[setupinfo.VERSION[3]],
                    status)