Debian Codegraph @

tests/base.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 """Base classes to run the tests both with the std library and lxml."""
18
19 import xml.etree.ElementTree as ET
20
21 import pytest
22
23 try: # pragma: no cover
24 import lxml
25
26 LXML = True
27 except ImportError: # pragma: no cover
28 LXML = False
29
30 from fastkml import config
31 from fastkml.validator import get_schema_parser
32
33
34 class StdLibrary:
35 """Configure test to run with the standard library."""
36
37 def setup_method(self) -> None:
38 """Ensure to always test with the standard library xml ElementTree parser."""
39 config.set_etree_implementation(ET)
40 config.set_default_namespaces()
41
42
43 @pytest.mark.skipif(not LXML, reason="lxml not installed")
44 class Lxml:
45 """
46 Configure test to run with lxml.
47
48 Use this mixin as the first base class in the test classes.
49 """
50
51 def setup_method(self) -> None:
52 """Ensure to always test with the lxml parse."""
53 config.set_etree_implementation(lxml.etree)
54 config.set_default_namespaces()
55 get_schema_parser()