mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -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
|
@ -21,12 +21,11 @@ __metaclass__ = type
|
|||
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.compat.tests.mock import patch, mock_open
|
||||
from ansible.errors import AnsibleParserError
|
||||
from ansible.errors import yaml_strings
|
||||
from ansible.errors import AnsibleParserError, yaml_strings
|
||||
from ansible.module_utils.six import PY3
|
||||
|
||||
from ansible.parsing.dataloader import DataLoader
|
||||
|
||||
|
||||
class TestDataLoader(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -39,7 +38,7 @@ class TestDataLoader(unittest.TestCase):
|
|||
def test_parse_json_from_file(self, mock_def):
|
||||
mock_def.return_value = (b"""{"a": 1, "b": 2, "c": 3}""", True)
|
||||
output = self._loader.load_from_file('dummy_json.txt')
|
||||
self.assertEqual(output, dict(a=1,b=2,c=3))
|
||||
self.assertEqual(output, dict(a=1, b=2, c=3))
|
||||
|
||||
@patch.object(DataLoader, '_get_file_contents')
|
||||
def test_parse_yaml_from_file(self, mock_def):
|
||||
|
@ -49,7 +48,7 @@ class TestDataLoader(unittest.TestCase):
|
|||
c: 3
|
||||
""", True)
|
||||
output = self._loader.load_from_file('dummy_yaml.txt')
|
||||
self.assertEqual(output, dict(a=1,b=2,c=3))
|
||||
self.assertEqual(output, dict(a=1, b=2, c=3))
|
||||
|
||||
@patch.object(DataLoader, '_get_file_contents')
|
||||
def test_parse_fail_from_file(self, mock_def):
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.parsing.mod_args import ModuleArgsParser
|
||||
from ansible.errors import AnsibleParserError
|
||||
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.errors import AnsibleParserError
|
||||
from ansible.parsing.mod_args import ModuleArgsParser
|
||||
|
||||
|
||||
class TestModArgsDwim(unittest.TestCase):
|
||||
|
||||
|
@ -47,9 +47,9 @@ class TestModArgsDwim(unittest.TestCase):
|
|||
self._debug(mod, args, to)
|
||||
self.assertEqual(mod, 'command')
|
||||
self.assertEqual(args, dict(
|
||||
_raw_params = 'echo hi',
|
||||
_uses_shell = True,
|
||||
))
|
||||
_raw_params='echo hi',
|
||||
_uses_shell=True,
|
||||
))
|
||||
self.assertIsNone(to)
|
||||
|
||||
def test_basic_command(self):
|
||||
|
@ -58,8 +58,8 @@ class TestModArgsDwim(unittest.TestCase):
|
|||
self._debug(mod, args, to)
|
||||
self.assertEqual(mod, 'command')
|
||||
self.assertEqual(args, dict(
|
||||
_raw_params = 'echo hi',
|
||||
))
|
||||
_raw_params='echo hi',
|
||||
))
|
||||
self.assertIsNone(to)
|
||||
|
||||
def test_shell_with_modifiers(self):
|
||||
|
@ -68,11 +68,11 @@ class TestModArgsDwim(unittest.TestCase):
|
|||
self._debug(mod, args, to)
|
||||
self.assertEqual(mod, 'command')
|
||||
self.assertEqual(args, dict(
|
||||
creates = '/tmp/baz',
|
||||
removes = '/tmp/bleep',
|
||||
_raw_params = '/bin/foo',
|
||||
_uses_shell = True,
|
||||
))
|
||||
creates='/tmp/baz',
|
||||
removes='/tmp/bleep',
|
||||
_raw_params='/bin/foo',
|
||||
_uses_shell=True,
|
||||
))
|
||||
self.assertIsNone(to)
|
||||
|
||||
def test_normal_usage(self):
|
||||
|
@ -127,4 +127,3 @@ class TestModArgsDwim(unittest.TestCase):
|
|||
|
||||
m = ModuleArgsParser(dict(ping='data=hi', shell='echo hi'))
|
||||
self.assertRaises(AnsibleParserError, m.parse)
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import unittest
|
|||
|
||||
from ansible.parsing.utils.addresses import parse_address
|
||||
|
||||
|
||||
class TestParseAddress(unittest.TestCase):
|
||||
|
||||
tests = {
|
||||
|
|
|
@ -22,6 +22,7 @@ __metaclass__ = type
|
|||
from ansible.compat.tests import unittest
|
||||
from ansible.parsing.utils.jsonify import jsonify
|
||||
|
||||
|
||||
class TestJsonify(unittest.TestCase):
|
||||
def test_jsonify_simple(self):
|
||||
self.assertEqual(jsonify(dict(a=1, b=2, c=3)), '{"a": 1, "b": 2, "c": 3}')
|
||||
|
|
|
@ -77,11 +77,11 @@ class TestVaultIsEncrypted(unittest.TestCase):
|
|||
self.assertTrue(vault.is_encrypted(b_data))
|
||||
|
||||
def test_invalid_text_not_ascii(self):
|
||||
data = u"$ANSIBLE_VAULT;9.9;TEST\n%s"% u"ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク グ ケ "
|
||||
data = u"$ANSIBLE_VAULT;9.9;TEST\n%s" % u"ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク グ ケ "
|
||||
self.assertFalse(vault.is_encrypted(data))
|
||||
|
||||
def test_invalid_bytes_not_ascii(self):
|
||||
data = u"$ANSIBLE_VAULT;9.9;TEST\n%s"% u"ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク グ ケ "
|
||||
data = u"$ANSIBLE_VAULT;9.9;TEST\n%s" % u"ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク グ ケ "
|
||||
b_data = to_bytes(data, encoding='utf-8')
|
||||
self.assertFalse(vault.is_encrypted(b_data))
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ class TestVaultEditor(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
if self._test_dir:
|
||||
pass
|
||||
#shutil.rmtree(self._test_dir)
|
||||
# shutil.rmtree(self._test_dir)
|
||||
self._test_dir = None
|
||||
|
||||
def test_methods_exist(self):
|
||||
|
@ -361,7 +361,7 @@ class TestVaultEditor(unittest.TestCase):
|
|||
|
||||
self.assertEqual(src_file_plaintext, new_src_contents)
|
||||
|
||||
#self.assertEqual(src_file_plaintext, new_src_contents,
|
||||
# self.assertEqual(src_file_plaintext, new_src_contents,
|
||||
# 'The decrypted plaintext of the editted file is not the expected contents.')
|
||||
|
||||
@patch('ansible.parsing.vault.call')
|
||||
|
|
|
@ -26,15 +26,14 @@ try:
|
|||
except ImportError:
|
||||
from yaml.parser import ParserError
|
||||
|
||||
from ansible.parsing.yaml import dumper
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.parsing import vault
|
||||
from ansible.parsing.yaml import dumper, objects
|
||||
from ansible.parsing.yaml.loader import AnsibleLoader
|
||||
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.parsing.yaml import objects
|
||||
from ansible.parsing import vault
|
||||
|
||||
from units.mock.yaml_helper import YamlTestUtils
|
||||
|
||||
|
||||
class TestAnsibleDumper(unittest.TestCase, YamlTestUtils):
|
||||
def setUp(self):
|
||||
self.vault_password = "hunter42"
|
||||
|
@ -43,7 +42,7 @@ class TestAnsibleDumper(unittest.TestCase, YamlTestUtils):
|
|||
self.stream = self._build_stream()
|
||||
self.dumper = dumper.AnsibleDumper
|
||||
|
||||
def _build_stream(self,yaml_text=None):
|
||||
def _build_stream(self, yaml_text=None):
|
||||
text = yaml_text or u''
|
||||
stream = io.StringIO(text)
|
||||
return stream
|
||||
|
|
|
@ -341,16 +341,17 @@ class TestAnsibleLoaderPlay(unittest.TestCase):
|
|||
self.assertEqual(self.data[0][u'vars'][u'number'], 1)
|
||||
self.assertEqual(self.data[0][u'vars'][u'string'], u'Ansible')
|
||||
self.assertEqual(self.data[0][u'vars'][u'utf8_string'], u'Cafè Eñyei')
|
||||
self.assertEqual(self.data[0][u'vars'][u'dictionary'],
|
||||
{u'webster': u'daniel',
|
||||
u'oed': u'oxford'})
|
||||
self.assertEqual(self.data[0][u'vars'][u'dictionary'], {
|
||||
u'webster': u'daniel',
|
||||
u'oed': u'oxford'
|
||||
})
|
||||
self.assertEqual(self.data[0][u'vars'][u'list'], [u'a', u'b', 1, 2])
|
||||
|
||||
self.assertEqual(self.data[0][u'tasks'],
|
||||
[{u'name': u'Test case', u'ping': {u'data': u'{{ utf8_string }}'}},
|
||||
{u'name': u'Test 2', u'ping': {u'data': u'Cafè Eñyei'}},
|
||||
{u'name': u'Test 3', u'command': u'printf \'Cafè Eñyei\n\''},
|
||||
])
|
||||
self.assertEqual(self.data[0][u'tasks'], [
|
||||
{u'name': u'Test case', u'ping': {u'data': u'{{ utf8_string }}'}},
|
||||
{u'name': u'Test 2', u'ping': {u'data': u'Cafè Eñyei'}},
|
||||
{u'name': u'Test 3', u'command': u'printf \'Cafè Eñyei\n\''},
|
||||
])
|
||||
|
||||
def walk(self, data):
|
||||
# Make sure there's no str in the data
|
||||
|
|
|
@ -104,22 +104,22 @@ class TestAnsibleVaultEncryptedUnicode(unittest.TestCase, YamlTestUtils):
|
|||
def test_empty_string_init_from_plaintext(self):
|
||||
seq = ''
|
||||
avu = self._from_plaintext(seq)
|
||||
self.assert_values(avu,seq)
|
||||
self.assert_values(avu, seq)
|
||||
|
||||
def test_empty_unicode_init_from_plaintext(self):
|
||||
seq = u''
|
||||
avu = self._from_plaintext(seq)
|
||||
self.assert_values(avu,seq)
|
||||
self.assert_values(avu, seq)
|
||||
|
||||
def test_string_from_plaintext(self):
|
||||
seq = 'some letters'
|
||||
avu = self._from_plaintext(seq)
|
||||
self.assert_values(avu,seq)
|
||||
self.assert_values(avu, seq)
|
||||
|
||||
def test_unicode_from_plaintext(self):
|
||||
seq = u'some letters'
|
||||
avu = self._from_plaintext(seq)
|
||||
self.assert_values(avu,seq)
|
||||
self.assert_values(avu, seq)
|
||||
|
||||
def test_unicode_from_plaintext_encode(self):
|
||||
seq = u'some text here'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue