summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Pribysh <dmand@yandex.ru>2015-10-07 02:39:38 +0300
committerDmitry Pribysh <dmand@yandex.ru>2015-10-07 02:39:38 +0300
commit335e147d7d47d61740a40641a62014b5aed4b59b (patch)
tree27d7fb71ef840c80b23957af68a18cc37654f791
parentaa68ce1b13aed050373c1953e6b92987633d4777 (diff)
downloadpylint-335e147d7d47d61740a40641a62014b5aed4b59b.tar.gz
Add functional tests for iterable hecker
-rw-r--r--pylint/test/functional/iterable_context.py36
-rw-r--r--pylint/test/functional/iterable_context.txt10
-rw-r--r--pylint/test/functional/yield_from_iterable_py33.py7
-rw-r--r--pylint/test/functional/yield_from_iterable_py33.rc2
-rw-r--r--pylint/test/functional/yield_from_iterable_py33.txt1
5 files changed, 56 insertions, 0 deletions
diff --git a/pylint/test/functional/iterable_context.py b/pylint/test/functional/iterable_context.py
new file mode 100644
index 0000000..8282683
--- /dev/null
+++ b/pylint/test/functional/iterable_context.py
@@ -0,0 +1,36 @@
+"""
+Checks that primitive values are not used in an
+iterating/mapping context.
+"""
+# pylint: disable=missing-docstring,invalid-name
+from __future__ import print_function
+
+# for-statement
+for i in 42: # [not-an-iterable]
+ pass
+
+for i in True: # [not-an-iterable]
+ pass
+
+# funcall-starargs
+def test(*args, **kwargs):
+ print(args, kwargs)
+
+test(*1) # [not-an-iterable]
+test(*False) # [not-an-iterable]
+
+# funcall-kwargs
+test(**1) # [not-a-mapping]
+test(**None) # [not-a-mapping]
+
+# list-comprehension
+test([3 ** x for x in 10]) # [not-an-iterable]
+
+# dict-comprehension
+test({k: chr(k) for k in 128}) # [not-an-iterable]
+
+# set-comprehension
+test({x for x in 32}) # [not-an-iterable]
+
+# generator-expression
+test(str(x) for x in 10) # [not-an-iterable]
diff --git a/pylint/test/functional/iterable_context.txt b/pylint/test/functional/iterable_context.txt
new file mode 100644
index 0000000..8c9f098
--- /dev/null
+++ b/pylint/test/functional/iterable_context.txt
@@ -0,0 +1,10 @@
+not-an-iterable:9::Non-iterable value 42 is used in an iterating context
+not-an-iterable:12::Non-iterable value True is used in an iterating context
+not-an-iterable:19::Non-iterable value 1 is used in an iterating context
+not-an-iterable:20::Non-iterable value False is used in an iterating context
+not-a-mapping:23::Non-mapping value 1 is used in a mapping context
+not-a-mapping:24::Non-mapping value None is used in a mapping context
+not-an-iterable:27::Non-iterable value 10 is used in an iterating context
+not-an-iterable:30::Non-iterable value 128 is used in an iterating context
+not-an-iterable:33::Non-iterable value 32 is used in an iterating context
+not-an-iterable:36::Non-iterable value 10 is used in an iterating context
diff --git a/pylint/test/functional/yield_from_iterable_py33.py b/pylint/test/functional/yield_from_iterable_py33.py
new file mode 100644
index 0000000..7803936
--- /dev/null
+++ b/pylint/test/functional/yield_from_iterable_py33.py
@@ -0,0 +1,7 @@
+"""
+Check that `yield from`-statement takes an iterable.
+"""
+# pylint: disable=missing-docstring
+
+def to_ten():
+ yield from 10 # [not-an-iterable]
diff --git a/pylint/test/functional/yield_from_iterable_py33.rc b/pylint/test/functional/yield_from_iterable_py33.rc
new file mode 100644
index 0000000..3330edd
--- /dev/null
+++ b/pylint/test/functional/yield_from_iterable_py33.rc
@@ -0,0 +1,2 @@
+[testoptions]
+min_pyver=3.3 \ No newline at end of file
diff --git a/pylint/test/functional/yield_from_iterable_py33.txt b/pylint/test/functional/yield_from_iterable_py33.txt
new file mode 100644
index 0000000..906ee93
--- /dev/null
+++ b/pylint/test/functional/yield_from_iterable_py33.txt
@@ -0,0 +1 @@
+not-an-iterable:7:to_ten:Non-iterable value 10 is used in an iterating context