~ubuntu-branches/ubuntu/vivid/pylint/vivid-proposed

« back to all changes in this revision

Viewing changes to test/utils.py

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2011-03-29 19:27:47 UTC
  • mfrom: (1.3.1 upstream) (12.1.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20110329192747-fwcizgk9vg1wi0tv
Tags: 0.23.0-1
* New upstream release
  - provides manpages for epylint, pylint-gui, symilar; Closes: #575679
* debian/control
  - mention pyreverse, symilar, epylint, pylint-gui additional commands in
    long description
  - update versioned Depends and b-d-i on logilab-{common, astng}
  - added python-unittest2 to b-d-i, needed to run tests
* debian/pylint.manpages
  - install all the available manpages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
"""some pylint test utilities
2
2
"""
 
3
import sys
3
4
from glob import glob
4
 
from os.path import join, abspath, dirname, basename, exists
 
5
from os.path import join, abspath, dirname, basename, exists, splitext
5
6
from cStringIO import StringIO
6
7
 
7
8
from pylint.interfaces import IReporter
10
11
PREFIX = abspath(dirname(__file__))
11
12
 
12
13
def fix_path():
13
 
    import sys
14
14
    sys.path.insert(0, PREFIX)
15
15
 
16
 
import sys
17
 
MSGPREFIXES = ['2.%s_'%i for i in range(5, 2, -1) if i <= sys.version_info[1]]
18
 
MSGPREFIXES.append('')
 
16
SYS_VERS_STR = '%d%d' % sys.version_info[:2]
19
17
 
20
 
def get_tests_info(prefix=None, suffix=None, inputdir='input', msgdir='messages'):
21
 
    pattern = '*'
22
 
    if prefix:
23
 
        pattern = prefix + pattern
24
 
    if suffix:
25
 
        pattern = pattern + suffix
 
18
def get_tests_info(prefix, suffix):
 
19
    """get python input examples and output messages
 
20
    
 
21
    We use following conventions for input files and messages:
 
22
    for different inputs:
 
23
        don't test for python  <   x.y    ->  input   =  <name>_pyxy.py
 
24
        don't test for python  >=  x.y    ->  input   =  <name>_py_xy.py
 
25
    for one input and different messages:
 
26
        message for python     <=  x.y    ->  message =  <name>_pyxy.txt
 
27
        higher versions                   ->  message with highest num
 
28
    """
26
29
    result = []
27
 
    for file in glob(join(PREFIX, inputdir, pattern)):
28
 
        infile = basename(file)
29
 
        for msgprefix in MSGPREFIXES:
30
 
            outfile = join(PREFIX, msgdir, msgprefix + infile.replace(suffix, '.txt'))
31
 
            if exists(outfile):
32
 
                break
 
30
    for fname in glob(join(PREFIX, 'input', prefix + '*' + suffix)):
 
31
        infile = basename(fname)
 
32
        fbase = splitext(infile)[0]
 
33
        # filter input files :
 
34
        pyrestr = fbase.rsplit('_py', 1)[-1] # like _26 or 26
 
35
        if pyrestr.isdigit(): # '24', '25'...
 
36
            if SYS_VERS_STR < pyrestr:
 
37
                continue
 
38
        if pyrestr.startswith('_') and  pyrestr[1:].isdigit():
 
39
            # skip test for higher python versions
 
40
            if SYS_VERS_STR >= pyrestr[1:]:
 
41
                continue
 
42
        messages = glob(join(PREFIX, 'messages', fbase + '*.txt'))
 
43
        # the last one will be without ext, i.e. for all or upper versions:
 
44
        if messages:
 
45
            for outfile in sorted(messages, reverse=True):
 
46
                py_rest = outfile.rsplit('_py', 1)[-1][:-4]
 
47
                if py_rest.isdigit() and SYS_VERS_STR >= py_rest:
 
48
                    break
 
49
        else:
 
50
            outfile = None
33
51
        result.append((infile, outfile))
34
52
    return result
35
53
 
73
91
 
74
92
# # # # #  pyreverse unittest utilities  # # # # # #
75
93
 
76
 
 
77
 
import unittest
 
94
from logilab.common.testlib import TestCase
78
95
import os
79
96
import sys
80
97
from os.path import join
116
133
        for attr, value in DEFAULTS.items():
117
134
            setattr(self, attr, value)
118
135
 
119
 
class FileTC(unittest.TestCase):
 
136
class FileTC(TestCase):
120
137
    """base test case for testing file output"""
121
138
 
122
139
    generated_files = ()
123
140
 
124
141
    def setUp(self):
125
 
        self.expected_files = [join('data', file)
 
142
        self.expected_files = [join(dirname(abspath(__file__)), 'data', file)
126
143
                               for file in self.generated_files]
127
144
 
128
145
    def tearDown(self):