From 335e147d7d47d61740a40641a62014b5aed4b59b Mon Sep 17 00:00:00 2001 From: Dmitry Pribysh Date: Wed, 7 Oct 2015 02:39:38 +0300 Subject: Add functional tests for iterable hecker --- pylint/test/functional/iterable_context.py | 36 ++++++++++++++++++++++ pylint/test/functional/iterable_context.txt | 10 ++++++ pylint/test/functional/yield_from_iterable_py33.py | 7 +++++ pylint/test/functional/yield_from_iterable_py33.rc | 2 ++ .../test/functional/yield_from_iterable_py33.txt | 1 + 5 files changed, 56 insertions(+) create mode 100644 pylint/test/functional/iterable_context.py create mode 100644 pylint/test/functional/iterable_context.txt create mode 100644 pylint/test/functional/yield_from_iterable_py33.py create mode 100644 pylint/test/functional/yield_from_iterable_py33.rc create mode 100644 pylint/test/functional/yield_from_iterable_py33.txt (limited to 'pylint/test') 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 -- cgit v1.2.1