diff options
| author | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2013-12-20 13:59:32 +0100 |
|---|---|---|
| committer | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2013-12-20 13:59:32 +0100 |
| commit | 2abeffd87e23fefd70a09c2a687bbd905bf83190 (patch) | |
| tree | 5b5491496e00683f2b046c4b0e87c4ff87ec552a /test/utils.py | |
| parent | 6d8c13d20d02e6feb43ba98cb6a2c7429913f2f3 (diff) | |
| download | pylint-git-2abeffd87e23fefd70a09c2a687bbd905bf83190.tar.gz | |
[test/pyreverse] make test predictable and stop sorting file content in this case
Diffstat (limited to 'test/utils.py')
| -rw-r--r-- | test/utils.py | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/test/utils.py b/test/utils.py index 34e1d4449..e7f80e869 100644 --- a/test/utils.py +++ b/test/utils.py @@ -1,10 +1,26 @@ +# 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 -from os.path import join, dirname, abspath import codecs +from os.path import join, dirname, abspath +from difflib import unified_diff from logilab.common.testlib import TestCase from astroid import MANAGER @@ -13,15 +29,12 @@ from astroid import MANAGER def _astroid_wrapper(func, modname): return func(modname) - -def _sorted_file(path): +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:'))] - lines = [line for line in lines if line] - lines.sort() - return '\n'.join(lines) + return [line for line in lines if line] def get_project(module, name=None): """return a astroid project representation @@ -48,6 +61,7 @@ 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) @@ -63,10 +77,13 @@ class FileTC(TestCase): def _test_same_file(self, index): generated_file = self.generated_files[index] expected_file = self.expected_files[index] - generated = _sorted_file(generated_file) - expected = _sorted_file(expected_file) - - from difflib import unified_diff + 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' % ( |
