gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / pylint / test / test_func.py @ 745
History | View | Annotate | Download (2.5 KB)
1 |
# Copyright (c) 2003-2014 LOGILAB S.A. (Paris, FRANCE).
|
---|---|
2 |
# http://www.logilab.fr/ -- mailto:contact@logilab.fr
|
3 |
#
|
4 |
# This program is free software; you can redistribute it and/or modify it under
|
5 |
# the terms of the GNU General Public License as published by the Free Software
|
6 |
# Foundation; either version 2 of the License, or (at your option) any later
|
7 |
# version.
|
8 |
#
|
9 |
# This program is distributed in the hope that it will be useful, but WITHOUT
|
10 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
11 |
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
12 |
#
|
13 |
# You should have received a copy of the GNU General Public License along with
|
14 |
# this program; if not, write to the Free Software Foundation, Inc.,
|
15 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
16 |
"""functional/non regression tests for pylint"""
|
17 |
|
18 |
import unittest |
19 |
import sys |
20 |
import re |
21 |
|
22 |
from os import getcwd |
23 |
from os.path import abspath, dirname, join |
24 |
|
25 |
from pylint.testutils import (make_tests, LintTestUsingModule, LintTestUsingFile, |
26 |
LintTestUpdate, cb_test_gen, linter, test_reporter) |
27 |
|
28 |
PY3K = sys.version_info >= (3, 0) |
29 |
|
30 |
# Configure paths
|
31 |
INPUT_DIR = join(dirname(abspath(__file__)), 'input')
|
32 |
MSG_DIR = join(dirname(abspath(__file__)), 'messages')
|
33 |
|
34 |
# Classes
|
35 |
|
36 |
quote = "'" if sys.version_info >= (3, 3) else '' |
37 |
|
38 |
class LintTestNonExistentModuleTC(LintTestUsingModule): |
39 |
module = 'nonexistent'
|
40 |
_get_expected = lambda self: 'F: 1: No module named %snonexistent%s\n' % (quote, quote) |
41 |
|
42 |
|
43 |
def gen_tests(filter_rgx): |
44 |
if UPDATE:
|
45 |
callbacks = [cb_test_gen(LintTestUpdate)] |
46 |
else:
|
47 |
callbacks = [cb_test_gen(LintTestUsingModule)] |
48 |
tests = make_tests(INPUT_DIR, MSG_DIR, filter_rgx, callbacks) |
49 |
if UPDATE:
|
50 |
return tests
|
51 |
|
52 |
if filter_rgx:
|
53 |
is_to_run = re.compile(filter_rgx).search |
54 |
else:
|
55 |
is_to_run = lambda x: 1 |
56 |
|
57 |
if is_to_run('nonexistent'): |
58 |
tests.append(LintTestNonExistentModuleTC) |
59 |
|
60 |
assert len(tests) < 196, "Please do not add new test cases here." |
61 |
return tests
|
62 |
|
63 |
# Create suite
|
64 |
|
65 |
FILTER_RGX = None
|
66 |
UPDATE = False
|
67 |
|
68 |
def suite(): |
69 |
return unittest.TestSuite([unittest.makeSuite(test, suiteClass=unittest.TestSuite)
|
70 |
for test in gen_tests(FILTER_RGX)]) |
71 |
|
72 |
|
73 |
def load_tests(loader, tests, pattern): |
74 |
return suite()
|
75 |
|
76 |
|
77 |
if __name__=='__main__': |
78 |
if '-u' in sys.argv: |
79 |
UPDATE = True
|
80 |
sys.argv.remove('-u')
|
81 |
|
82 |
if len(sys.argv) > 1: |
83 |
FILTER_RGX = sys.argv[1]
|
84 |
del sys.argv[1] |
85 |
unittest.main(defaultTest='suite')
|