Skip to content

Commit

Permalink
fix: get_multiline_input not trimming whitespace (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme committed Jan 15, 2022
1 parent fb28278 commit 3997042
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion actions_toolkit/core.py
Expand Up @@ -97,7 +97,9 @@ def get_multiline_input(name: str, **options) -> List[str]:
"""
Gets the values of an multiline input. Each value is also trimmed.
"""
return list(filter(lambda x: x != '', get_input(name, **options).split("\n")))
inputs = list(filter(lambda x: x != '', get_input(name, **options).split("\n")))
options = InputOptions(**options)
return [x.strip() for x in inputs] if options.trim_whitespace else inputs


def get_boolean_input(name: str, **options) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -5,7 +5,7 @@

setup(
name='actions-toolkit',
version='0.1.12',
version='0.1.13',
description='🛠 The GitHub ToolKit for developing GitHub Actions in Python.',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down
12 changes: 10 additions & 2 deletions tests/test_core.py
Expand Up @@ -31,6 +31,7 @@
'INPUT_WITH_TRAILING_WHITESPACE': ' some val ',

'INPUT_MY_INPUT_LIST': 'val1\nval2\nval3',
'INPUT_LIST_WITH_TRAILING_WHITESPACE': ' val1 \n val2 \n ',

# Save inputs
'STATE_TEST_1': 'state_val',
Expand Down Expand Up @@ -135,8 +136,6 @@ def verify_file_command(command: str, expected_contents: str):

assert core.get_input('multiple spaces variable') == 'I have multiple spaces'

assert core.get_multiline_input('my input list') == ['val1', 'val2', 'val3']

assert core.get_input('with trailing whitespace') == 'some val'

assert core.get_input('with trailing whitespace', trim_whitespace=True) == 'some val'
Expand All @@ -154,6 +153,15 @@ def verify_file_command(command: str, expected_contents: str):
assert core.get_boolean_input('boolean input false2') is False
assert core.get_boolean_input('boolean input false3') is False

assert core.get_multiline_input('my input list') == ['val1', 'val2', 'val3']

assert core.get_multiline_input('list with trailing whitespace') == ['val1', 'val2']

assert core.get_multiline_input('list with trailing whitespace', trim_whitespace=True) == ['val1', 'val2']

assert core.get_multiline_input('list with trailing whitespace', trim_whitespace=False) == [' val1 ', ' val2 ',
' ']

try:
core.get_boolean_input('wrong boolean input')
except Exception as e:
Expand Down

0 comments on commit 3997042

Please sign in to comment.