Debian Codegraph @

tests/config_test.py

raw symbols SCIP
1 # Copyright (C) 2021 Christian Ledermann
2 #
3 # This library is free software; you can redistribute it and/or modify it under
4 # the terms of the GNU Lesser General Public License as published by the Free
5 # Software Foundation; either version 2.1 of the License, or (at your option)
6 # any later version.
7 #
8 # This library is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 # details.
12 #
13 # You should have received a copy of the GNU Lesser General Public License
14 # along with this library; if not, write to the Free Software Foundation, Inc.,
15 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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