| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
"""Test the configuration options.""" |
| 18 |
|
| 19 |
from xml.etree import ElementTree as ET |
| 20 |
|
| 21 |
import pytest |
| 22 |
|
| 23 |
try: |
| 24 |
import lxml |
| 25 |
|
| 26 |
LXML = True |
| 27 |
except ImportError: |
| 28 |
LXML = False |
| 29 |
|
| 30 |
from fastkml import config |
| 31 |
|
| 32 |
|
| 33 |
def test_set_etree_implementation_xml() -> None: |
| 34 |
config.set_etree_implementation(ET) |
| 35 |
|
| 36 |
assert config.etree.__name__ == "xml.etree.ElementTree" |
| 37 |
|
| 38 |
|
| 39 |
@pytest.mark.skipif(not LXML, reason="lxml not installed") |
| 40 |
def test_set_etree_implementation_lxml() -> None: |
| 41 |
config.set_etree_implementation(lxml.etree) |
| 42 |
|
| 43 |
assert config.etree.__name__ == "lxml.etree" |
| 44 |
|
| 45 |
|
| 46 |
def test_register_namespaces() -> None: |
| 47 |
"""Register namespaces for use in etree.""" |
| 48 |
config.set_etree_implementation(ET) |
| 49 |
ns = { |
| 50 |
"real_person": "http://people.example.com", |
| 51 |
"role": "http://characters.example.com", |
| 52 |
} |
| 53 |
|
| 54 |
config.register_namespaces(**ns) |
| 55 |
|
| 56 |
for k, v in ns.items(): |
| 57 |
assert config.etree._namespace_map[v] == k |
| 58 |
|
| 59 |
|
| 60 |
def test_default_registered_namespaces() -> None: |
| 61 |
assert config.DEFAULT_NAME_SPACES == { |
| 62 |
"kml": "http://www.opengis.net/kml/2.2", |
| 63 |
"atom": "http://www.w3.org/2005/Atom", |
| 64 |
"gx": "http://www.google.com/kml/ext/2.2", |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
def test_set_default_namespaces() -> None: |
| 69 |
"""Set the default namespaces.""" |
| 70 |
config.set_etree_implementation(ET) |
| 71 |
config.etree._namespace_map = {} |
| 72 |
|
| 73 |
config.set_default_namespaces() |
| 74 |
|
| 75 |
for k, v in config.DEFAULT_NAME_SPACES.items(): |
| 76 |
assert config.etree._namespace_map[v] == k |