Beispiel #1
0
    def testfile(self, filename, batchmode=False):
        """runs every test in `filename`

        :param filename: an absolute path pointing to a unittest file
        """
        here = os.getcwd()
        dirname = osp.dirname(filename)
        if dirname:
            os.chdir(dirname)
        self.load_django_settings(dirname)
        modname = osp.basename(filename)[:-3]
        print >>sys.stderr, ('  %s  ' % osp.basename(filename)).center(70, '=')
        try:
            try:
                tstart, cstart = time(), clock()
                self.before_testfile()
                testprog = testlib.unittest_main(modname, batchmode=batchmode, cvg=self.cvg)
                tend, cend = time(), clock()
                ttime, ctime = (tend - tstart), (cend - cstart)
                self.report.feed(filename, testprog.result, ttime, ctime)
                return testprog
            except SystemExit:
                raise
            except Exception, exc:
                import traceback
                traceback.print_exc()
                self.report.failed_to_test_module(filename)
                print 'unhandled exception occurred while testing', modname
                print 'error: %s' % exc
                return None
        finally:
            self.after_testfile()
            if dirname:
                os.chdir(here)
Beispiel #2
0
    def testfile(self, filename, batchmode=False):
        """runs every test in `filename`

        :param filename: an absolute path pointing to a unittest file
        """
        here = os.getcwd()
        dirname = osp.dirname(filename)
        if dirname:
            os.chdir(dirname)
        self.load_django_settings(dirname)
        modname = osp.basename(filename)[:-3]
        print >> sys.stderr, ('  %s  ' % osp.basename(filename)).center(
            70, '=')
        try:
            try:
                tstart, cstart = time(), clock()
                self.before_testfile()
                testprog = testlib.unittest_main(modname,
                                                 batchmode=batchmode,
                                                 cvg=self.cvg)
                tend, cend = time(), clock()
                ttime, ctime = (tend - tstart), (cend - cstart)
                self.report.feed(filename, testprog.result, ttime, ctime)
                return testprog
            except SystemExit:
                raise
            except Exception, exc:
                import traceback
                traceback.print_exc()
                self.report.failed_to_test_module(filename)
                print 'unhandled exception occurred while testing', modname
                print 'error: %s' % exc
                return None
        finally:
            self.after_testfile()
            if dirname:
                os.chdir(here)
Beispiel #3
0
        linter.check(join(REGR_DATA, 'module_global.py'))
        got = linter.reporter.finalize().strip()
        self.assertEqual(got, '')

    def test_decimal_inference(self):
        linter.check(join(REGR_DATA, 'decimal_inference.py'))
        got = linter.reporter.finalize().strip()
        self.assertEqual(got, "")

    def test_descriptor_crash(self):
        for fname in os.listdir(REGR_DATA):
            if fname.endswith('_crash.py'):
                linter.check(join(REGR_DATA, fname))
                linter.reporter.finalize().strip()

    def test_try_finally_disable_msg_crash(self):
        linter.check(join(REGR_DATA, 'try_finally_disable_msg_crash'))

    def test___path__(self):
        linter.check('pylint.checkers.__init__')
        messages = linter.reporter.finalize().strip()
        self.assertFalse('__path__' in messages, messages)

    def test_absolute_import(self):
        linter.check(join(REGR_DATA, 'absimp', 'string.py'))
        got = linter.reporter.finalize().strip()
        self.assertEqual(got, "W:  6: Uses of a deprecated module 'string'")

if __name__ == '__main__':
    unittest_main()
                     'a[newaxis,:]', 'del L[::2]', 'del A[1]', 'del Br[:]'):
            ast = abuilder.string_build(code).body[0]
            self.assertEqual(ast.as_string(), code)

    def test_slice_and_subscripts(self):
        code = """a[:1] = bord[2:]
a[:1] = bord[2:]
del bree[3:d]
bord[2:]
del av[d::f], a[df:]
a[:1] = bord[2:]
del SRC[::1,newaxis,1:]
tous[vals] = 1010
del thousand[key]
del a[::2], a[:-1:step]
del Fee.form[left:]
aout.vals = miles.of_stuff
del (ccok, (name.thing, foo.attrib.value)), Fee.form[left:]
if all[1] == bord[0:]:
    pass\n\n"""
        ast = abuilder.string_build(code)
        self.assertEqual(ast.as_string(), code)

class EllipsisNodeTC(testlib.TestCase):
    def test(self):
        ast = abuilder.string_build('a[...]').body[0]
        self.assertEqual(ast.as_string(), 'a[...]')

if __name__ == '__main__':
    testlib.unittest_main()
        class LintTestUsingFileTC(RLintTestUsingFile):
            module = module_file.replace('.py', '')
            output = exists(messages_file + '2') and (messages_file + '2') or messages_file
            depends = dependancies or None
        tests.append(LintTestUsingFileTC)
    
    if not filter_rgx:
        # test all features are tested :)    
        tests.append(TestTests)

    return tests

FILTER_RGX = None
MODULES_ONLY = False

def suite():
    return unittest.TestSuite([unittest.makeSuite(test)
                               for test in make_tests(FILTER_RGX)])

if __name__=='__main__':
    if '-m' in sys.argv:
        MODULES_ONLY = True
        sys.argv.remove('-m')
    
    if len(sys.argv) > 1:            
        FILTER_RGX = sys.argv[1]
        del sys.argv[1]
    testlib.unittest_main(defaultTest='suite')


Beispiel #6
0
                     'a[newaxis,:]', 'del L[::2]', 'del A[1]', 'del Br[:]'):
            ast = abuilder.string_build(code).body[0]
            self.assertEqual(ast.as_string(), code)

    def test_slice_and_subscripts(self):
        code = """a[:1] = bord[2:]
a[:1] = bord[2:]
del bree[3:d]
bord[2:]
del av[d::f], a[df:]
a[:1] = bord[2:]
del SRC[::1,newaxis,1:]
tous[vals] = 1010
del thousand[key]
del a[::2], a[:-1:step]
del Fee.form[left:]
aout.vals = miles.of_stuff
del (ccok, (name.thing, foo.attrib.value)), Fee.form[left:]
if all[1] == bord[0:]:
    pass\n\n"""
        ast = abuilder.string_build(code)
        self.assertEqual(ast.as_string(), code)

class EllipsisNodeTC(testlib.TestCase):
    def test(self):
        ast = abuilder.string_build('a[...]').body[0]
        self.assertEqual(ast.as_string(), 'a[...]')

if __name__ == '__main__':
    testlib.unittest_main()
Beispiel #7
0
            except Exception, e:
                print >> sys.__stderr__, "Error while overwriting \
succeeded test file :", osp.join(os.getcwd(), testlib.FILE_RESTART)
                raise e
        modname = osp.basename(filename)[:-3]
        try:
            print >> sys.stderr, ('  %s  ' % osp.basename(filename)).center(
                70, '=')
        except TypeError:  # < py 2.4 bw compat
            print >> sys.stderr, ('  %s  ' % osp.basename(filename)).center(70)
        try:
            tstart, cstart = time(), clock()
            try:
                testprog = testlib.unittest_main(modname,
                                                 batchmode=batchmode,
                                                 cvg=self.cvg,
                                                 options=self.options,
                                                 outstream=sys.stderr)
            except KeyboardInterrupt:
                raise
            except SystemExit, exc:
                self.errcode = exc.code
                raise
            except testlib.SkipTest:
                print "Module skipped:", filename
                self.report.skip_module(filename)
                return None
            except Exception:
                self.report.failed_to_test_module(filename)
                print >> sys.stderr, 'unhandled exception occurred while testing', modname
                import traceback
Beispiel #8
0
        tests.append(TestTests)

    return tests


# Create suite

FILTER_RGX = None
MODULES_ONLY = False


def suite():
    return testlib.TestSuite([
        unittest.makeSuite(test, suiteClass=testlib.TestSuite)
        for test in gen_tests(FILTER_RGX)
    ])


del LintTestUsingModule
del LintTestUsingFile

if __name__ == '__main__':
    if '-m' in sys.argv:
        MODULES_ONLY = True
        sys.argv.remove('-m')

    if len(sys.argv) > 1:
        FILTER_RGX = sys.argv[1]
        del sys.argv[1]
    testlib.unittest_main(defaultTest='suite')
Beispiel #9
0
import unittest
from logilab.common import testlib
from pylint.testutils import make_tests, LintTestUsingModule, LintTestUsingFile, cb_test_gen, linter
import sys


INPUT_DIR = join(dirname(abspath(__file__)), "input")
MESSAGES_DIR = join(dirname(abspath(__file__)), "messages")
CALLBACKS = [cb_test_gen(LintTestUsingModule), cb_test_gen(LintTestUsingFile)]
FILTER_RGX = None


linter.load_plugin_modules(["pylint_common"])
linter.global_set_option("required-attributes", ())  # remove required __revision__


def suite():
    return testlib.TestSuite(
        [
            unittest.makeSuite(test, suiteClass=testlib.TestSuite)
            for test in make_tests(INPUT_DIR, MESSAGES_DIR, FILTER_RGX, CALLBACKS)
        ]
    )


if __name__ == "__main__":
    if len(sys.argv) > 1:
        FILTER_RGX = sys.argv[1]
        del sys.argv[1]
    testlib.unittest_main(defaultTest="suite")
Beispiel #10
0
            try:
                restartfile = open(testlib.FILE_RESTART, "w")
                restartfile.close()
            except Exception, e:
                print >> sys.__stderr__, "Error while overwriting \
succeeded test file :", osp.join(os.getcwd(),testlib.FILE_RESTART)
                raise e
        modname = osp.basename(filename)[:-3]
        try:
            print >> sys.stderr, ('  %s  ' % osp.basename(filename)).center(70, '=')
        except TypeError: # < py 2.4 bw compat
            print >> sys.stderr, ('  %s  ' % osp.basename(filename)).center(70)
        try:
            tstart, cstart = time(), clock()
            try:
                testprog = testlib.unittest_main(modname, batchmode=batchmode, cvg=self.cvg,
                                                 options=self.options, outstream=sys.stderr)
            except KeyboardInterrupt:
                raise
            except SystemExit, exc:
                self.errcode = exc.code
                raise
            except testlib.TestSkipped:
                print "Module skipped:", filename
                self.report.skip_module(filename)
                return None
            except Exception:
                self.report.failed_to_test_module(filename)
                print >> sys.stderr, 'unhandled exception occurred while testing', modname
                import traceback
                traceback.print_exc(file=sys.stderr)
                return None