summaryrefslogtreecommitdiff
path: root/test/utils.py
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2013-12-20 15:12:50 +0100
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2013-12-20 15:12:50 +0100
commitf24227aae012740653e8708379b7e9c22f938400 (patch)
treed334468d560e36f3c2cf04d16da386e3e108c05e /test/utils.py
parent7ecac59ebc534e869a772efa6dbd973fb8843f44 (diff)
downloadpylint-f24227aae012740653e8708379b7e9c22f938400.tar.gz
[pyreverse] more refactoring to get actually predicable results (take 2)
simplify pyreverse related test code on the way.
Diffstat (limited to 'test/utils.py')
-rw-r--r--test/utils.py98
1 files changed, 0 insertions, 98 deletions
diff --git a/test/utils.py b/test/utils.py
deleted file mode 100644
index e7f80e8..0000000
--- a/test/utils.py
+++ /dev/null
@@ -1,98 +0,0 @@
-# Copyright (c) 2003-2013 LOGILAB S.A. (Paris, FRANCE).
-# http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# 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.
-"""some pylint test utilities
-"""
-
-import os
-import sys
-import codecs
-from os.path import join, dirname, abspath
-from difflib import unified_diff
-
-from logilab.common.testlib import TestCase
-from astroid import MANAGER
-
-
-def _astroid_wrapper(func, modname):
- return func(modname)
-
-def _file_lines(path):
- # we don't care about the actual encoding, but python3 forces us to pick one
- lines = [line.strip() for line in codecs.open(path, encoding='latin1').readlines()
- if (line.find('squeleton generated by ') == -1 and
- not line.startswith('__revision__ = "$Id:'))]
- return [line for line in lines if line]
-
-def get_project(module, name=None):
- """return a astroid project representation
- """
- manager = MANAGER
- # flush cache
- manager._modules_by_name = {}
- return manager.project_from_files([module], _astroid_wrapper,
- project_name=name)
-
-DEFAULTS = {'all_ancestors': None, 'show_associated': None,
- 'module_names': None,
- 'output_format': 'dot', 'diadefs_file': None, 'quiet': 0,
- 'show_ancestors': None, 'classes': (), 'all_associated': None,
- 'mode': 'PUB_ONLY', 'show_builtin': False, 'only_classnames': False}
-
-class Config(object):
- """config object for tests"""
- def __init__(self):
- for attr, value in DEFAULTS.items():
- setattr(self, attr, value)
-
-class FileTC(TestCase):
- """base test case for testing file output"""
-
- generated_files = ()
- sort = True
-
- def setUp(self):
- self.expected_files = [join(dirname(abspath(__file__)), 'data', file)
- for file in self.generated_files]
-
- def tearDown(self):
- for fname in self.generated_files:
- try:
- os.remove(fname)
- except:
- continue
-
- def _test_same_file(self, index):
- generated_file = self.generated_files[index]
- expected_file = self.expected_files[index]
- generated = _file_lines(generated_file)
- expected = _file_lines(expected_file)
- if self.sort:
- generated = sorted(generated)
- expected = sorted(expected)
- generated = '\n'.join(generated)
- expected = '\n'.join(expected)
- files = "\n *** expected : %s, generated : %s \n" % (
- expected_file, generated_file)
- self.assertEqual(expected, generated, '%s%s' % (
- files, '\n'.join(line for line in unified_diff(
- expected.splitlines(), generated.splitlines() ))) )
- os.remove(generated_file)
-
-
-def build_file_case(filetc):
- for i in range(len(filetc.generated_files)):
- setattr(filetc, 'test_same_file_%s' %i,
- lambda self, index=i: self._test_same_file(index))