summaryrefslogtreecommitdiff
path: root/test/smoketest.py
blob: 25f30fd95d92b8decb2b6e4bc527796156875c11 (plain)
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
# 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; either version 2 of the License, or (at your option) any later
# version.

# 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.,
# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

import sys
from os.path import join, dirname, abspath
from cStringIO import StringIO
import tempfile

from logilab.common.testlib import TestCase, unittest_main, tag

from pylint.lint import Run
from pylint.reporters.text import *
from pylint.reporters.html import HTMLReporter

HERE = abspath(dirname(__file__))

class RunTC(TestCase):

    def _runtest(self, args, reporter=None, out=None, code=28):
        if out is None:
            out = StringIO()
        if args and args[-1].startswith('pylint.lint'):
            try:
                import cProfile, pstats
            except ImportError:
                code += 1
        try:
            sys.stderr = sys.stdout = out
            try:
                Run(args, reporter=reporter)
            except SystemExit, ex:
                self.assertEqual(ex.code, code)
            else:
                self.fail('expected system exit')
        finally:
            sys.stderr = sys.__stderr__
            sys.stdout = sys.__stdout__

    @tag('smoke')
    def test0(self):
        """make pylint checking itself"""
        self._runtest(['pylint.__pkginfo__'], reporter=TextReporter(StringIO()),
                      code=0)

    @tag('smoke')
    def test1(self):
        """make pylint checking itself"""
        self._runtest(['pylint.lint'], reporter=TextReporter(StringIO()))

    @tag('smoke')
    def test2(self):
        """make pylint checking itself"""
        self._runtest(['pylint.lint'], reporter=HTMLReporter(StringIO()))

    @tag('smoke')
    def test3(self):
        """make pylint checking itself"""
        self._runtest(['pylint.lint'], reporter=ColorizedTextReporter(StringIO()))

    @tag('smoke')
    def test_no_ext_file(self):
        self._runtest([join(HERE, 'input', 'noext')], code=0)

    @tag('smoke')
    def test_generated_members(self):
        # XXX dual end quotation since optparse buggily remove one...
        self._runtest(['--generated-members=objects,DoesNotExist,delay,retry,"[a-zA-Z]+_set{1,2}""', 'pylint.lint'])

    @tag('smoke')
    def test_w0704_ignored(self):
        self._runtest([join(HERE, 'input', 'ignore_except_pass_by_default.py')], code=0)

    @tag('smoke', 'help', 'config')
    def test_generate_config_option(self):
        """make pylint checking itself"""
        self._runtest(['--generate-rcfile'], reporter=HTMLReporter(StringIO()),
                      code=0)

    @tag('smoke', 'help')
    def test_help_message_option(self):
        """make pylint checking itself"""
        self._runtest(['--help-msg', 'W0101'], reporter=HTMLReporter(StringIO()),
                      code=0)

    @tag('smoke', 'help')
    def test_error_help_message_option(self):
        self._runtest(['--help-msg', 'WX101'], reporter=HTMLReporter(StringIO()),
                      code=0)

    @tag('smoke', 'usage')
    def test_error_missing_arguments(self):
        self._runtest([], reporter=HTMLReporter(StringIO()),
                      code=32)

    @tag('smoke', 'encoding')
    def test_no_out_encoding(self):
        """test redirection of stdout with non ascii caracters
        """
        #This test reproduces bug #48066 ; it happens when stdout is redirected
        # through '>' : the sys.stdout.encoding becomes then None, and if the
        # output contains non ascii, pylint will crash
        if sys.version_info < (3, 0):
            strio = tempfile.TemporaryFile()
        else:
            strio = StringIO()
        assert strio.encoding is None
        self._runtest([join(HERE, 'regrtest_data/no_stdout_encoding.py')],
                      out=strio)


if __name__ == '__main__':
    unittest_main()