Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: implement simple sugar test #25

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions test/test_sugar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import pytest

from otk.parse.document import Omnifest
from otk.transform.context import Context
from otk.transform import resolve
from otk.error import TransformDirectiveTypeError


def test_simple_sugar():
data = """
otk.version: 1
otk.define:
variable: "foo"
my_var: ${variable}
"""

context = Context()
omnifest_under_test = Omnifest.from_yaml_bytes(data).to_tree()

omnifest_result = resolve(context, omnifest_under_test)

assert omnifest_result['my_var'] == "foo"


def test_simple_sugar_tree():
data = """
otk.version: 1
otk.define:
variable:
- 1
- 2
my_var: ${variable}
"""

context = Context()
omnifest_under_test = Omnifest.from_yaml_bytes(data).to_tree()

omnifest_result = resolve(context, omnifest_under_test)

assert omnifest_result['my_var'] == [1, 2]


def test_simple_sugar_tree_fail():
data = """
otk.version: 1
otk.define:
variable:
- 1
- 2
my_var: my_prefix_${variable}
"""
expected_error = 'string sugar resolves to an incorrect type, expected int, float, or str but got %r'

context = Context()
omnifest_under_test = Omnifest.from_yaml_bytes(data).to_tree()

with pytest.raises(TransformDirectiveTypeError, match=expected_error):
resolve(context, omnifest_under_test)