mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 20:01:25 -07:00
test/: PEP8 compliancy (#24803)
* test/: PEP8 compliancy - Make PEP8 compliant * Python3 chokes on casting int to bytes (#24952) But if we tell the formatter that the var is a number, it works
This commit is contained in:
parent
31c59ad5f9
commit
4efec414e7
110 changed files with 1702 additions and 1547 deletions
|
@ -36,12 +36,12 @@ VALID_STRINGS = (
|
|||
[("True", True)],
|
||||
[("False", False)],
|
||||
[("{}", {})],
|
||||
)
|
||||
)
|
||||
|
||||
# Passing things that aren't strings should just return the object
|
||||
NONSTRINGS = (
|
||||
[({'a':1}, {'a':1})],
|
||||
)
|
||||
[({'a': 1}, {'a': 1})],
|
||||
)
|
||||
|
||||
# These strings are not basic types. For security, these should not be
|
||||
# executed. We return the same string and get an exception for some
|
||||
|
@ -50,25 +50,29 @@ INVALID_STRINGS = (
|
|||
[("a.foo()", "a.foo()", None)],
|
||||
[("import foo", "import foo", None)],
|
||||
[("__import__('foo')", "__import__('foo')", ValueError)],
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def _check_simple_types(self, code, expected):
|
||||
# test some basic usage for various types
|
||||
self.assertEqual(self.am.safe_eval(code), expected)
|
||||
|
||||
|
||||
def _check_simple_types_with_exceptions(self, code, expected):
|
||||
# Test simple types with exceptions requested
|
||||
self.assertEqual(self.am.safe_eval(code, include_exceptions=True), (expected, None))
|
||||
|
||||
|
||||
def _check_invalid_strings(self, code, expected):
|
||||
self.assertEqual(self.am.safe_eval(code), expected)
|
||||
|
||||
|
||||
def _check_invalid_strings_with_exceptions(self, code, expected, exception):
|
||||
res = self.am.safe_eval("a=1", include_exceptions=True)
|
||||
self.assertEqual(res[0], "a=1")
|
||||
self.assertEqual(type(res[1]), SyntaxError)
|
||||
|
||||
|
||||
@add_method(_check_simple_types, *VALID_STRINGS)
|
||||
@add_method(_check_simple_types, *NONSTRINGS)
|
||||
@add_method(_check_simple_types_with_exceptions, *VALID_STRINGS)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue