mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 12:21:26 -07:00
parent
9d9a451b34
commit
8a184381af
2 changed files with 81 additions and 12 deletions
|
@ -33,6 +33,8 @@ try:
|
|||
except ImportError:
|
||||
import __builtin__ as builtins
|
||||
|
||||
from nose.tools import eq_, raises
|
||||
|
||||
from ansible.release import __version__ as ansible_version
|
||||
from ansible import constants as C
|
||||
from ansible.compat.six import text_type
|
||||
|
@ -630,3 +632,42 @@ class TestActionBase(unittest.TestCase):
|
|||
play_context.make_become_cmd.assert_called_once_with("ECHO SAME", executable=None)
|
||||
finally:
|
||||
C.BECOME_ALLOW_SAME_USER = become_allow_same_user
|
||||
|
||||
# Note: Using nose's generator test cases here so we can't inherit from
|
||||
# unittest.TestCase
|
||||
class TestFilterNonJsonLines(object):
|
||||
parsable_cases = (
|
||||
(u'{"hello": "world"}', u'{"hello": "world"}'),
|
||||
(u'{"hello": "world"}\n', u'{"hello": "world"}'),
|
||||
(u'{"hello": "world"} ', u'{"hello": "world"} '),
|
||||
(u'{"hello": "world"} \n', u'{"hello": "world"} '),
|
||||
(u'Message of the Day\n{"hello": "world"}', u'{"hello": "world"}'),
|
||||
(u'{"hello": "world"}\nEpilogue', u'{"hello": "world"}'),
|
||||
(u'Several\nStrings\nbefore\n{"hello": "world"}\nAnd\nAfter\n', u'{"hello": "world"}'),
|
||||
(u'{"hello": "world",\n"olá": "mundo"}', u'{"hello": "world",\n"olá": "mundo"}'),
|
||||
(u'\nPrecedent\n{"hello": "world",\n"olá": "mundo"}\nAntecedent', u'{"hello": "world",\n"olá": "mundo"}'),
|
||||
)
|
||||
|
||||
unparsable_cases = (
|
||||
u'No json here',
|
||||
u'"olá": "mundo"',
|
||||
u'{"No json": "ending"',
|
||||
u'{"wrong": "ending"]',
|
||||
u'["wrong": "ending"}',
|
||||
)
|
||||
|
||||
def check_filter_non_json_lines(self, stdout_line, parsed):
|
||||
eq_(parsed, ActionBase._filter_non_json_lines(stdout_line))
|
||||
|
||||
def test_filter_non_json_lines(self):
|
||||
for stdout_line, parsed in self.parsable_cases:
|
||||
yield self.check_filter_non_json_lines, stdout_line, parsed
|
||||
|
||||
@raises(ValueError)
|
||||
def check_unparsable_filter_non_json_lines(self, stdout_line):
|
||||
ActionBase._filter_non_json_lines(stdout_line)
|
||||
|
||||
def test_unparsable_filter_non_json_lines(self):
|
||||
for stdout_line in self.unparsable_cases:
|
||||
yield self.check_unparsable_filter_non_json_lines, stdout_line
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue