diff options
author | Emile Anclin <emile.anclin@logilab.fr> | 2010-12-15 18:08:34 +0100 |
---|---|---|
committer | Emile Anclin <emile.anclin@logilab.fr> | 2010-12-15 18:08:34 +0100 |
commit | 6def4f2e66906633a229f00e561ab7022f263d1f (patch) | |
tree | 4bb95790d1ff231b96a9b561e18030a2c0bbe228 | |
parent | 594a20d33bbbbcf3ad042d8872bb11228934dbe8 (diff) | |
download | pylint-git-6def4f2e66906633a229f00e561ab7022f263d1f.tar.gz |
symilar: ignore differences due to comments at the end of a line; reflect it in tests
-rw-r--r-- | checkers/similar.py | 13 | ||||
-rw-r--r-- | test/input/similar1 | 2 | ||||
-rw-r--r-- | test/test_similar.py | 17 |
3 files changed, 23 insertions, 9 deletions
diff --git a/checkers/similar.py b/checkers/similar.py index d8651b5b5..ae008b9be 100644 --- a/checkers/similar.py +++ b/checkers/similar.py @@ -139,9 +139,10 @@ def stripped_lines(lines, ignore_comments, ignore_docstrings): if line.endswith(docstring): docstring = None line = '' - # XXX cut when a line begins with code but end with a comment - if ignore_comments and line.startswith('#'): - line = '' + if ignore_comments: + # XXX should use regex in checkers/format to avoid cutting + # at a "#" in a string + line = line.split('#', 1)[0].strip() strippedlines.append(line) return strippedlines @@ -302,7 +303,7 @@ def usage(status=0): print "finds copy pasted blocks in a set of files" print print 'Usage: similar [-d|--duplicates min_duplicated_lines] \ -[--ignore-comments] file1...' +[-i|--ignore-comments] file1...' sys.exit(status) def run(argv=None): @@ -310,7 +311,7 @@ def run(argv=None): if argv is None: argv = sys.argv[1:] from getopt import getopt - s_opts = 'hd:' + s_opts = 'hdi' l_opts = ('help', 'duplicates=', 'ignore-comments') min_lines = 4 ignore_comments = False @@ -320,7 +321,7 @@ def run(argv=None): min_lines = int(val) elif opt in ('-h', '--help'): usage() - elif opt == '--ignore-comments': + elif opt in ('-i', '--ignore-comments'): ignore_comments = True if not args: usage(1) diff --git a/test/input/similar1 b/test/input/similar1 index bc881871c..d1604d306 100644 --- a/test/input/similar1 +++ b/test/input/similar1 @@ -6,7 +6,7 @@ see the similar2 file which is almost the same file as this one. more than 4 identical lines should -be +be # ignore comments ! detected diff --git a/test/test_similar.py b/test/test_similar.py index 9b9eb37f9..68aff835d 100644 --- a/test/test_similar.py +++ b/test/test_similar.py @@ -11,7 +11,8 @@ SIMILAR2 = join(dirname(abspath(__file__)), 'input', 'similar2') class SimilarTC(TestCase): """test the similar command line utility""" - def test(self): + + def test_ignore_comments(self): sys.stdout = StringIO() try: similar.run(['--ignore-comments', SIMILAR1, SIMILAR2]) @@ -31,7 +32,19 @@ class SimilarTC(TestCase): TOTAL lines=38 duplicates=7 percent=18.42 """ % (SIMILAR1, SIMILAR2)).strip()) - + + + def test_dont_ignore_comments(self): + sys.stdout = StringIO() + try: + similar.run([SIMILAR1, SIMILAR2]) + output = sys.stdout.getvalue() + finally: + sys.stdout = sys.__stdout__ + self.assertMultiLineEqual(output.strip(), """ +TOTAL lines=38 duplicates=0 percent=0.00 + """.strip()) + def test_help(self): sys.stdout = StringIO() try: |