Skip to content

Commit

Permalink
testing multi-line output
Browse files Browse the repository at this point in the history
  • Loading branch information
lnxpy committed May 15, 2024
1 parent 6eba1f0 commit 5d620a9
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions tests/io_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

from pyaction import io
from pyaction.consts import MULTILINE_OUTPUT
from pyaction.exceptions import WorkflowParameterNotFound

test_env_vars = [
Expand All @@ -13,6 +14,8 @@
("INPUT_QUX", "qux", "2020.05.03"),
]

test_stream = str(os.path.join(tempfile.tempdir, "GITHUB_OUTPUT_TEST.txt"))


@pytest.mark.parametrize("var,name,val", test_env_vars)
def test_io_read(monkeypatch, var, name, val):
Expand All @@ -36,8 +39,29 @@ def test_io_read_missing_parameters():

@pytest.mark.parametrize("context,expected", test_env_var_context)
def test_write_to_stream(context, expected):
test_stream = os.path.join(tempfile.tempdir, "GITHUB_OUTPUT_TEST.txt")
io.write(context, str(test_stream))
io.write(context, test_stream)

with open(test_stream, "r+") as file:
content = file.read()

assert content == expected


test_multi_line_env_var_context = [
(
{"message": "Hello\nworld"},
MULTILINE_OUTPUT.format(variable="message", value="Hello\nworld"),
),
(
{"phrase": "How\nAre\nYou?!"},
MULTILINE_OUTPUT.format(variable="phrase", value="How\nAre\nYou?!"),
),
]


@pytest.mark.parametrize("context,expected", test_multi_line_env_var_context)
def test_write_multiline_to_stream(context, expected):
io.write(context, test_stream)

with open(test_stream, "r+") as file:
content = file.read()
Expand Down

0 comments on commit 5d620a9

Please sign in to comment.