diff options
author | Charles Hebert <charles.hebert@logilab.fr> | 2009-11-27 15:57:49 +0100 |
---|---|---|
committer | Charles Hebert <charles.hebert@logilab.fr> | 2009-11-27 15:57:49 +0100 |
commit | 71ec3b15799abe69963151b08ad38d7f185b0121 (patch) | |
tree | af44e7b1131796e1b83153311364b8eac8eeb150 /test | |
parent | 38038da6b50cff9779d80575a7d2ce7124a31497 (diff) | |
download | pylint-git-71ec3b15799abe69963151b08ad38d7f185b0121.tar.gz |
Add a checker verifying string formatting (James Lingard's patch) + tests
Diffstat (limited to 'test')
-rw-r--r-- | test/input/func_e99xx.py | 21 | ||||
-rw-r--r-- | test/messages/func_e99xx.txt | 13 | ||||
-rw-r--r-- | test/unittest_lint.py | 2 |
3 files changed, 35 insertions, 1 deletions
diff --git a/test/input/func_e99xx.py b/test/input/func_e99xx.py new file mode 100644 index 000000000..427eb71e9 --- /dev/null +++ b/test/input/func_e99xx.py @@ -0,0 +1,21 @@ +"""test string format error +""" + +__revision__ = 1 + +PARG_1 = PARG_2 = PARG_3 = 1 + +def pprint(): + """Test string format + """ + print "%s %s" % {'PARG_1': 1, 'PARG_2': 2} # E9906 + print "%s" % (PARG_1, PARG_2) # E9905 + print "%(PARG_1)d %d" % {'PARG_1': 1, 'PARG_2': 2} # E9902 + print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1} # E9904 + print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1, 'PARG_2':2, 'PARG_3':3} # W9901 + print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1, 2:3} # W9900 E9904 + print "%(PARG_1)d %(PARG_2)d" % (2, 3) # 9903 + print "%(PARG_1)d %(PARG_2)d" % [2, 3] # 9903 + print "%2z" % PARG_1 + print "strange format %2" % PARG_2 + diff --git a/test/messages/func_e99xx.txt b/test/messages/func_e99xx.txt new file mode 100644 index 000000000..b0754b9f7 --- /dev/null +++ b/test/messages/func_e99xx.txt @@ -0,0 +1,13 @@ +C: 15: Line too long (81/80) +E: 11:pprint: Not enough arguments for format string +E: 12:pprint: Too many arguments for format string +E: 13:pprint: Mixing named and unnamed conversion specifiers in format string +E: 14:pprint: Missing key 'PARG_2' in format string dictionary +E: 16:pprint: Missing key 'PARG_2' in format string dictionary +E: 17:pprint: Expected mapping for format string, not Tuple +E: 18:pprint: Expected mapping for format string, not List +E: 19:pprint: Unsupported format character 'z' (0x7a) at index 2 +E: 20:pprint: Format string ends in middle of conversion specifier +W: 15:pprint: Unused key 'PARG_3' in format string dictionary +W: 16:pprint: Format string dictionary key should be a string, not 2 + diff --git a/test/unittest_lint.py b/test/unittest_lint.py index 9b50c36ac..1820a7cca 100644 --- a/test/unittest_lint.py +++ b/test/unittest_lint.py @@ -220,7 +220,7 @@ class PyLinterTC(TestCase): if c.is_enabled()]), ['basic', 'classes', 'exceptions', 'format', 'imports', 'logging', 'master', 'metrics', 'miscellaneous', 'newstyle', - 'similarities', 'typecheck', 'variables']) + 'similarities', 'string_format', 'typecheck', 'variables']) def test_enable_checkers2(self): self.linter.enable_checkers(['design'], True) |