| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 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: |
| 24 |
import lxml |
| 25 |
|
| 26 |
LXML = True |
| 27 |
except ImportError: |
| 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() |