| 1 |
""" |
| 2 |
JinjaX |
| 3 |
Copyright (c) Juan-Pablo Scaletti <[email protected]> |
| 4 |
""" |
| 5 |
import pytest |
| 6 |
|
| 7 |
import jinjax |
| 8 |
|
| 9 |
|
| 10 |
def test_add_folder_with_default_prefix(): |
| 11 |
catalog = jinjax.Catalog() |
| 12 |
catalog.add_folder("file_path") |
| 13 |
|
| 14 |
assert "file_path" in catalog.prefixes[""].searchpath |
| 15 |
|
| 16 |
|
| 17 |
def test_add_folder_with_custom_prefix(): |
| 18 |
catalog = jinjax.Catalog() |
| 19 |
catalog.add_folder("file_path", prefix="custom") |
| 20 |
|
| 21 |
assert "file_path" in catalog.prefixes["custom"].searchpath |
| 22 |
|
| 23 |
|
| 24 |
def test_add_folder_with_dirty_prefix(): |
| 25 |
catalog = jinjax.Catalog() |
| 26 |
catalog.add_folder("file_path", prefix="/custom.") |
| 27 |
|
| 28 |
assert "/custom." not in catalog.prefixes |
| 29 |
assert "file_path" in catalog.prefixes["custom"].searchpath |
| 30 |
|
| 31 |
|
| 32 |
def test_add_folders_with_same_prefix(): |
| 33 |
catalog = jinjax.Catalog() |
| 34 |
catalog.add_folder("file_path1", prefix="custom") |
| 35 |
catalog.add_folder("file_path2", prefix="custom") |
| 36 |
|
| 37 |
assert "file_path1" in catalog.prefixes["custom"].searchpath |
| 38 |
assert "file_path2" in catalog.prefixes["custom"].searchpath |
| 39 |
|
| 40 |
|
| 41 |
def test_add_same_folder_in_same_prefix_does_nothing(): |
| 42 |
catalog = jinjax.Catalog() |
| 43 |
catalog.add_folder("file_path", prefix="custom") |
| 44 |
catalog.add_folder("file_path", prefix="custom") |
| 45 |
|
| 46 |
assert catalog.prefixes["custom"].searchpath.count("file_path") == 1 |
| 47 |
|
| 48 |
|
| 49 |
def test_add_module_legacy(): |
| 50 |
class Module: |
| 51 |
components_path = "legacy_path" |
| 52 |
|
| 53 |
catalog = jinjax.Catalog() |
| 54 |
module = Module() |
| 55 |
catalog.add_module(module, prefix="legacy") |
| 56 |
|
| 57 |
assert "legacy_path" in catalog.prefixes["legacy"].searchpath |
| 58 |
|
| 59 |
|
| 60 |
def test_add_module_legacy_with_default_prefix(): |
| 61 |
class Module: |
| 62 |
components_path = "legacy_path" |
| 63 |
|
| 64 |
catalog = jinjax.Catalog() |
| 65 |
module = Module() |
| 66 |
catalog.add_module(module) |
| 67 |
|
| 68 |
assert "legacy_path" in catalog.prefixes[""].searchpath |
| 69 |
|
| 70 |
|
| 71 |
def test_add_module_fails_with_other_modules(): |
| 72 |
class Module: |
| 73 |
pass |
| 74 |
|
| 75 |
catalog = jinjax.Catalog() |
| 76 |
module = Module() |
| 77 |
with pytest.raises(AttributeError): |
| 78 |
catalog.add_module(module) |