summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCharles Hebert <charles.hebert@logilab.fr>2009-11-27 15:57:49 +0100
committerCharles Hebert <charles.hebert@logilab.fr>2009-11-27 15:57:49 +0100
commitb390e94adce252f548c1b0ddfad63c7ded9b581b (patch)
tree14fb73f91a65b85362090becefe6b5450bf28258 /test
parent0af18b12382aaefbf7e9811ac5830386b0b4e102 (diff)
downloadpylint-b390e94adce252f548c1b0ddfad63c7ded9b581b.tar.gz
Add a checker verifying string formatting (James Lingard's patch) + tests
Diffstat (limited to 'test')
-rw-r--r--test/input/func_e99xx.py21
-rw-r--r--test/messages/func_e99xx.txt13
-rw-r--r--test/unittest_lint.py2
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 0000000..427eb71
--- /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 0000000..b0754b9
--- /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 9b50c36..1820a7c 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)