|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import jinjanator_plugins |
| 4 | +import pytest |
| 5 | + |
| 6 | +from . import ( |
| 7 | + FilePairFactory, |
| 8 | + render_file, |
| 9 | +) |
| 10 | + |
| 11 | + |
| 12 | +def test_mapping_normal(make_file_pair: FilePairFactory) -> None: |
| 13 | + files = make_file_pair("{{ foo }}", '{"foo": "bar"}', "json") |
| 14 | + |
| 15 | + assert "bar" == render_file(files, []) |
| 16 | + |
| 17 | + |
| 18 | +def test_mapping_with_array_name_option(make_file_pair: FilePairFactory) -> None: |
| 19 | + files = make_file_pair("{{ foo }}", '{"foo": "bar"}', "json") |
| 20 | + |
| 21 | + with pytest.raises(jinjanator_plugins.FormatOptionUnsupportedError): |
| 22 | + assert render_file(files, ["--format-option", "array-name=seq"]) |
| 23 | + |
| 24 | + |
| 25 | +def test_array_normal(make_file_pair: FilePairFactory) -> None: |
| 26 | + files = make_file_pair("{{ seq[0] }}", "[1,2,3]", "json") |
| 27 | + |
| 28 | + assert "1" == render_file(files, ["--format-option", "array-name=seq"]) |
| 29 | + |
| 30 | + |
| 31 | +def test_array_without_array_name_option(make_file_pair: FilePairFactory) -> None: |
| 32 | + files = make_file_pair("{{ seq[0] }}", "[1,2,3]", "json") |
| 33 | + |
| 34 | + with pytest.raises(jinjanator_plugins.FormatOptionUnsupportedError): |
| 35 | + assert render_file(files, []) |
| 36 | + |
| 37 | + |
| 38 | +def test_array_invalid_name(make_file_pair: FilePairFactory) -> None: |
| 39 | + files = make_file_pair("{{ seq[0] }}", "[1,2,3]", "json") |
| 40 | + |
| 41 | + with pytest.raises(jinjanator_plugins.FormatOptionValueError): |
| 42 | + render_file(files, ["--format-option", "array-name=334seq"]) |
| 43 | + |
| 44 | + |
| 45 | +def test_array_invalid_value(make_file_pair: FilePairFactory) -> None: |
| 46 | + files = make_file_pair("{{ seq[0] }}", "[1,2,3]", "json") |
| 47 | + |
| 48 | + with pytest.raises(jinjanator_plugins.FormatOptionValueError): |
| 49 | + render_file(files, ["--format-option", "array-name=abc=def"]) |
| 50 | + |
| 51 | + |
| 52 | +def test_array_keyword_name(make_file_pair: FilePairFactory) -> None: |
| 53 | + files = make_file_pair("{{ seq[0] }}", "[1,2,3]", "json") |
| 54 | + |
| 55 | + with pytest.raises(jinjanator_plugins.FormatOptionValueError): |
| 56 | + render_file(files, ["--format-option", "array-name=raise"]) |
0 commit comments