Skip to content

Commit

Permalink
Run the tests for the jaml filter
Browse files Browse the repository at this point in the history
  • Loading branch information
mdellweg authored and ggainey committed Oct 14, 2024
1 parent ca4c693 commit 28cb339
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ tests/cli.toml:
@echo "In order to configure the tests to talk to your test server, you might need to edit $@ ."

test: | tests/cli.toml
python3 -m pytest -v tests pulp-glue/tests
python3 -m pytest -v tests pulp-glue/tests cookiecutter/pulp_filter_extension.py

docs:
pulp-docs build
Expand Down
1 change: 1 addition & 0 deletions cookiecutter/ci/{{ cookiecutter.__project_name }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ tests/cli.toml:

test: | tests/cli.toml
python3 -m pytest -v tests {%- if cookiecutter.glue %} pulp-glue{{ cookiecutter.__app_label_suffix }}/tests {%- endif %}
{%- if cookiecutter.__app_label_suffix == "" %} cookiecutter/pulp_filter_extension.py {%- endif %}
{%- if cookiecutter.docs %}

docs:
Expand Down
18 changes: 12 additions & 6 deletions cookiecutter/pulp_filter_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ def to_jaml(data: t.Any, level: int = 0, embed_in: str = "") -> str:
else:
raise NotImplementedError("This object is not serializable.")
if nl:
return "\n" + " " * level + result
result = "\n" + " " * level + result
elif embed_in in ("dict", "list"):
return " " + result
result = " " + result
elif embed_in == "document":
if level != 0:
warnings.warn("jaml: Level should be 0 when embedding in 'document'.")
return result
else:
if level != 0:
warnings.warn("jaml: Level should be 0 when serializing a docoment.")
result = "---\n" + result + "\n...\n"
return result


def to_toml_value(value: t.Any) -> str:
Expand Down Expand Up @@ -108,14 +113,14 @@ def __init__(self, environment: Environment):
[
([], 0, "", "---\n[]\n...\n"),
({}, 0, "", "---\n{}\n...\n"),
("test", 0, "", '---\n"test\n...\n"'),
("test", 0, "", '---\n"test"\n...\n'),
("test", 0, "document", '"test"'),
({}, 1, "dict", " {}"),
([], 1, "list", " []"),
({}, 1, "list", " {}"),
([], 1, "dict", " []"),
([{}], 0, "", "- {}"),
([[[]]], 0, "", "- - []"),
([{}], 0, "", "---\n- {}\n...\n"),
([[[]]], 0, "document", "- - []"),
(
{"a": [], "b": "test", "c": [True, False]},
2,
Expand All @@ -126,7 +131,8 @@ def __init__(self, environment: Environment):
- true
- false""",
),
({"b": 1, "a": 0}, 0, "", "a: 0\nb: 1"),
({"b": 1, "a": 0}, 0, "document", "a: 0\nb: 1"),
({"b": 1, "a": 0}, 0, "", "---\na: 0\nb: 1\n...\n"),
],
)
def test_to_jaml(value, level, embed_in, out):
Expand Down
1 change: 1 addition & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pytest>=7.0.0,<8.4
pytest-subtests>=0.12.0,<0.14
python-gnupg>=0.5.0,<0.6
trustme>=1.1.0,<1.3
jinja2>=3.1.4,<3.2

# No pinning here, because we only switch on optional dependencies here.
pygments
Expand Down

0 comments on commit 28cb339

Please sign in to comment.