Fix unit test parametrize order on Python 3.5.

(cherry picked from commit 53b230ca74)
pull/45713/merge
Matt Clay 6 years ago committed by Toshio Kuratomi
parent 09e61f29e9
commit 6d07cec588

@ -55,21 +55,23 @@ class TestAnsibleModuleLogSmokeTest:
class TestAnsibleModuleLogSyslog: class TestAnsibleModuleLogSyslog:
"""Test the AnsibleModule Log Method""" """Test the AnsibleModule Log Method"""
PY2_OUTPUT_DATA = { PY2_OUTPUT_DATA = [
u'Text string': b'Text string', (u'Text string', b'Text string'),
u'Toshio くらとみ non-ascii test': u'Toshio くらとみ non-ascii test'.encode('utf-8'), (u'Toshio くらとみ non-ascii test', u'Toshio くらとみ non-ascii test'.encode('utf-8')),
b'Byte string': b'Byte string', (b'Byte string', b'Byte string'),
u'Toshio くらとみ non-ascii test'.encode('utf-8'): u'Toshio くらとみ non-ascii test'.encode('utf-8'), (u'Toshio くらとみ non-ascii test'.encode('utf-8'), u'Toshio くらとみ non-ascii test'.encode('utf-8')),
b'non-utf8 :\xff: test': b'non-utf8 :\xff: test'.decode('utf-8', 'replace').encode('utf-8'), (b'non-utf8 :\xff: test', b'non-utf8 :\xff: test'.decode('utf-8', 'replace').encode('utf-8')),
} ]
PY3_OUTPUT_DATA = { PY3_OUTPUT_DATA = [
u'Text string': u'Text string', (u'Text string', u'Text string'),
u'Toshio くらとみ non-ascii test': u'Toshio くらとみ non-ascii test', (u'Toshio くらとみ non-ascii test', u'Toshio くらとみ non-ascii test'),
b'Byte string': u'Byte string', (b'Byte string', u'Byte string'),
u'Toshio くらとみ non-ascii test'.encode('utf-8'): u'Toshio くらとみ non-ascii test', (u'Toshio くらとみ non-ascii test'.encode('utf-8'), u'Toshio くらとみ non-ascii test'),
b'non-utf8 :\xff: test': b'non-utf8 :\xff: test'.decode('utf-8', 'replace') (b'non-utf8 :\xff: test', b'non-utf8 :\xff: test'.decode('utf-8', 'replace')),
} ]
OUTPUT_DATA = PY3_OUTPUT_DATA if PY3 else PY2_OUTPUT_DATA
@pytest.mark.parametrize('no_log, stdin', (product((True, False), [{}])), indirect=['stdin']) @pytest.mark.parametrize('no_log, stdin', (product((True, False), [{}])), indirect=['stdin'])
def test_no_log(self, am, mocker, no_log): def test_no_log(self, am, mocker, no_log):
@ -85,8 +87,7 @@ class TestAnsibleModuleLogSyslog:
# pylint bug: https://github.com/PyCQA/pylint/issues/511 # pylint bug: https://github.com/PyCQA/pylint/issues/511
@pytest.mark.parametrize('msg, param, stdin', @pytest.mark.parametrize('msg, param, stdin',
((m, p, {}) for m, p in ((m, p, {}) for m, p in OUTPUT_DATA), # pylint: disable=undefined-variable
(PY3_OUTPUT_DATA.items() if PY3 else PY2_OUTPUT_DATA.items())), # pylint: disable=undefined-variable
indirect=['stdin']) indirect=['stdin'])
def test_output_matches(self, am, mocker, msg, param): def test_output_matches(self, am, mocker, msg, param):
"""Check that log messages are sent correctly""" """Check that log messages are sent correctly"""
@ -101,13 +102,13 @@ class TestAnsibleModuleLogSyslog:
class TestAnsibleModuleLogJournal: class TestAnsibleModuleLogJournal:
"""Test the AnsibleModule Log Method""" """Test the AnsibleModule Log Method"""
OUTPUT_DATA = { OUTPUT_DATA = [
u'Text string': u'Text string', (u'Text string', u'Text string'),
u'Toshio くらとみ non-ascii test': u'Toshio くらとみ non-ascii test', (u'Toshio くらとみ non-ascii test', u'Toshio くらとみ non-ascii test'),
b'Byte string': u'Byte string', (b'Byte string', u'Byte string'),
u'Toshio くらとみ non-ascii test'.encode('utf-8'): u'Toshio くらとみ non-ascii test', (u'Toshio くらとみ non-ascii test'.encode('utf-8'), u'Toshio くらとみ non-ascii test'),
b'non-utf8 :\xff: test': b'non-utf8 :\xff: test'.decode('utf-8', 'replace') (b'non-utf8 :\xff: test', b'non-utf8 :\xff: test'.decode('utf-8', 'replace')),
} ]
@pytest.mark.parametrize('no_log, stdin', (product((True, False), [{}])), indirect=['stdin']) @pytest.mark.parametrize('no_log, stdin', (product((True, False), [{}])), indirect=['stdin'])
def test_no_log(self, am, mocker, no_log): def test_no_log(self, am, mocker, no_log):
@ -127,7 +128,7 @@ class TestAnsibleModuleLogJournal:
# pylint bug: https://github.com/PyCQA/pylint/issues/511 # pylint bug: https://github.com/PyCQA/pylint/issues/511
@pytest.mark.parametrize('msg, param, stdin', @pytest.mark.parametrize('msg, param, stdin',
((m, p, {}) for m, p in OUTPUT_DATA.items()), # pylint: disable=undefined-variable ((m, p, {}) for m, p in OUTPUT_DATA), # pylint: disable=undefined-variable
indirect=['stdin']) indirect=['stdin'])
def test_output_matches(self, am, mocker, msg, param): def test_output_matches(self, am, mocker, msg, param):
journal_send = mocker.patch('systemd.journal.send') journal_send = mocker.patch('systemd.journal.send')

@ -73,8 +73,8 @@ HOW_MANY_DOTS = (
'PostgreSQL does not support column with more than 4 dots'), 'PostgreSQL does not support column with more than 4 dots'),
) )
VALID_QUOTES = ((test, VALID[test]) for test in VALID) VALID_QUOTES = ((test, VALID[test]) for test in sorted(VALID))
INVALID_QUOTES = ((test[0], test[1], INVALID[test]) for test in INVALID) INVALID_QUOTES = ((test[0], test[1], INVALID[test]) for test in sorted(INVALID))
@pytest.mark.parametrize("identifier, quoted_identifier", VALID_QUOTES) @pytest.mark.parametrize("identifier, quoted_identifier", VALID_QUOTES)

@ -85,19 +85,19 @@ URLS = {
} }
@pytest.mark.parametrize('url, is_ssh_url', ((k, v['is_ssh_url']) for k, v in URLS.items())) @pytest.mark.parametrize('url, is_ssh_url', ((k, URLS[k]['is_ssh_url']) for k in sorted(URLS)))
def test_is_ssh_url(url, is_ssh_url): def test_is_ssh_url(url, is_ssh_url):
assert known_hosts.is_ssh_url(url) == is_ssh_url assert known_hosts.is_ssh_url(url) == is_ssh_url
@pytest.mark.parametrize('url, fqdn, port', ((k, v['get_fqdn'], v['port']) for k, v in URLS.items())) @pytest.mark.parametrize('url, fqdn, port', ((k, URLS[k]['get_fqdn'], URLS[k]['port']) for k in sorted(URLS)))
def test_get_fqdn_and_port(url, fqdn, port): def test_get_fqdn_and_port(url, fqdn, port):
assert known_hosts.get_fqdn_and_port(url) == (fqdn, port) assert known_hosts.get_fqdn_and_port(url) == (fqdn, port)
@pytest.mark.parametrize('fqdn, port, add_host_key_cmd, stdin', @pytest.mark.parametrize('fqdn, port, add_host_key_cmd, stdin',
((v['get_fqdn'], v['port'], v['add_host_key_cmd'], {}) ((URLS[k]['get_fqdn'], URLS[k]['port'], URLS[k]['add_host_key_cmd'], {})
for v in URLS.values() if v['is_ssh_url']), for k in sorted(URLS) if URLS[k]['is_ssh_url']),
indirect=['stdin']) indirect=['stdin'])
def test_add_host_key(am, mocker, fqdn, port, add_host_key_cmd): def test_add_host_key(am, mocker, fqdn, port, add_host_key_cmd):
get_bin_path = mocker.MagicMock() get_bin_path = mocker.MagicMock()

Loading…
Cancel
Save