summaryrefslogtreecommitdiff
path: root/tests/functional/m/misplaced_format_function.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functional/m/misplaced_format_function.py')
-rw-r--r--tests/functional/m/misplaced_format_function.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/functional/m/misplaced_format_function.py b/tests/functional/m/misplaced_format_function.py
new file mode 100644
index 000000000..3520dc70b
--- /dev/null
+++ b/tests/functional/m/misplaced_format_function.py
@@ -0,0 +1,58 @@
+"""Test that format function is used only with string."""
+
+# pylint: disable=invalid-name, pointless-string-statement, line-too-long, no-member, blacklisted-name, undefined-variable, missing-docstring, too-few-public-methods
+
+print('value: {}').format(123) # [misplaced-format-function]
+print("value: {}").format(123) # [misplaced-format-function]
+print('value: {}'.format(123))
+print('{} Come Forth!'.format('Lazarus'))
+print('Der Hem ist mein Licht und mein Heil, vor wem sollte ich mich furchten? => {}'.format('Psalm 27, 1'))
+print('123')
+print()
+s = 'value: {}'.format(123)
+a = 'value: {}'
+a.format(123)
+
+def foo(arg):
+ """The World is Yours"""
+ return arg.format(123) # we don't know if arg is str or not, don't raise error.
+
+def goo(arg):
+ """The World is Yours"""
+ TextWriter.format(arg)
+
+def bar(arg, TextWriter):
+ """The World is Yours"""
+ TextWriter().format(arg)
+
+def foobar(arg, TextWriter):
+ """The World is Yours"""
+ TextWriter.format(arg)
+
+def barfoo(arg):
+ """The World is Yours"""
+ TextWriter().format(arg)
+
+def _display(self, layout):
+ """launch layouts display"""
+ print(file=self.out)
+ TextWriter().format(layout, self.out)
+
+
+class FakeClass:
+ def __init__(self, string):
+ self.string = string
+
+ def get_string(self):
+ return self.string
+
+ def format_string(self):
+ self.string.format()
+ self.get_string().format()
+ print(self.get_string()).format() # [misplaced-format-function]
+ print(self.get_string().format())
+
+obj = FakeClass('Voila!!!')
+obj.get_string().format()
+print(obj.get_string().format())
+print(obj.get_string()).format() # [misplaced-format-function]