Skip to content
Snippets Groups Projects
Commit 514245b1 authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

FIX: Use correct imports in unit tests

parent f85b5af3
Branches
Tags
2 merge requests!181Release 0.9.0,!180F converter submodule
Pipeline #54929 passed with warnings
from . import converters, utils, xml_converter from . import converters, utils
from .crawl import Crawler, SecurityMode from .crawl import Crawler, SecurityMode
from .version import CfoodRequiredVersionError, get_caoscrawler_version from .version import CfoodRequiredVersionError, get_caoscrawler_version
......
...@@ -22,11 +22,11 @@ ...@@ -22,11 +22,11 @@
from .. import utils from .. import utils
from .converters import * from .converters import *
from .xml_converter import *
try: try:
from .converters.spss import SPSSConverter from .spss import SPSSConverter
except ImportError as err: except ImportError as err:
SPSSConverter: type = utils.MissingImport( SPSSConverter: type = utils.MissingImport(
name="SPSSConverter", hint="Try installing with the `spss` extra option.", name="SPSSConverter", hint="Try installing with the `spss` extra option.",
err=err) err=err)
...@@ -43,9 +43,9 @@ from jsonschema import ValidationError, validate ...@@ -43,9 +43,9 @@ from jsonschema import ValidationError, validate
from ..stores import GeneralStore, RecordStore from ..stores import GeneralStore, RecordStore
from ..structure_elements import (BooleanElement, DictElement, Directory, File, from ..structure_elements import (BooleanElement, DictElement, Directory, File,
FloatElement, IntegerElement, JSONFile, FloatElement, IntegerElement, JSONFile,
ListElement, NoneElement, StructureElement, ListElement, NoneElement, StructureElement,
TextElement) TextElement)
from ..utils import has_parent from ..utils import has_parent
# These are special properties which are (currently) treated differently # These are special properties which are (currently) treated differently
......
...@@ -28,8 +28,7 @@ import pandas as pd ...@@ -28,8 +28,7 @@ import pandas as pd
import pyreadstat import pyreadstat
import yaml import yaml
import .converters from . import converters
from ..stores import GeneralStore from ..stores import GeneralStore
from ..structure_elements import (File, StructureElement) from ..structure_elements import (File, StructureElement)
from typing import Optional, Any from typing import Optional, Any
......
...@@ -35,12 +35,12 @@ from typing import Any, Callable, Optional, Union ...@@ -35,12 +35,12 @@ from typing import Any, Callable, Optional, Union
import linkahead as db import linkahead as db
from jsonschema import ValidationError, validate from jsonschema import ValidationError, validate
from .stores import GeneralStore, RecordStore from ..stores import GeneralStore, RecordStore
from .structure_elements import (BooleanElement, DictElement, Directory, File, from ..structure_elements import (BooleanElement, DictElement, Directory, File,
FloatElement, IntegerElement, JSONFile, FloatElement, IntegerElement, JSONFile,
ListElement, NoneElement, StructureElement, ListElement, NoneElement, StructureElement,
TextElement, XMLTagElement, XMLTextNode, XMLAttributeNode) TextElement, XMLTagElement, XMLTextNode, XMLAttributeNode)
from .utils import has_parent from ..utils import has_parent
import lxml.etree import lxml.etree
from .converters import SimpleFileConverter, ConverterValidationError, Converter from .converters import SimpleFileConverter, ConverterValidationError, Converter
......
...@@ -102,12 +102,12 @@ XLSXTableConverter: ...@@ -102,12 +102,12 @@ XLSXTableConverter:
XMLFile: XMLFile:
converter: XMLFileConverter converter: XMLFileConverter
package: caoscrawler.xml_converter package: caoscrawler.converters
XMLTag: XMLTag:
converter: XMLTagConverter converter: XMLTagConverter
package: caoscrawler.xml_converter package: caoscrawler.converters
XMLTextNode: XMLTextNode:
converter: XMLTextNodeConverter converter: XMLTextNodeConverter
package: caoscrawler.xml_converter package: caoscrawler.converters
...@@ -5,16 +5,16 @@ metadata: ...@@ -5,16 +5,16 @@ metadata:
Converters: Converters:
H5Dataset: H5Dataset:
converter: H5DatasetConverter converter: H5DatasetConverter
package: caoscrawler.hdf5_converter package: caoscrawler.converters.hdf5_converter
H5File: H5File:
converter: H5FileConverter converter: H5FileConverter
package: caoscrawler.hdf5_converter package: caoscrawler.converters.hdf5_converter
H5Group: H5Group:
converter: H5GroupConverter converter: H5GroupConverter
package: caoscrawler.hdf5_converter package: caoscrawler.converters.hdf5_converter
H5Ndarray: H5Ndarray:
converter: H5NdarrayConverter converter: H5NdarrayConverter
package: caoscrawler.hdf5_converter package: caoscrawler.converters.hdf5_converter
# Top-level, we have just the HDF5 file. # Top-level, we have just the HDF5 file.
ParentDirectory: ParentDirectory:
type: Directory type: Directory
......
...@@ -46,8 +46,8 @@ from caoscrawler.converters import (Converter, ConverterValidationError, ...@@ -46,8 +46,8 @@ from caoscrawler.converters import (Converter, ConverterValidationError,
ListElementConverter, MarkdownFileConverter, ListElementConverter, MarkdownFileConverter,
PropertiesFromDictConverter, PropertiesFromDictConverter,
YAMLFileConverter, YAMLFileConverter,
_AbstractScalarValueElementConverter,
handle_value, replace_variables) handle_value, replace_variables)
from caoscrawler.converters.converters import _AbstractScalarValueElementConverter
from caoscrawler.crawl import Crawler from caoscrawler.crawl import Crawler
from caoscrawler.scanner import (_load_definition_from_yaml_dict, from caoscrawler.scanner import (_load_definition_from_yaml_dict,
create_converter_registry, create_converter_registry,
...@@ -648,10 +648,7 @@ def test_load_converters(): ...@@ -648,10 +648,7 @@ def test_load_converters():
# All of them are contained in caoscrawler.converters # All of them are contained in caoscrawler.converters
# except for the xml converters: # except for the xml converters:
for conv_key, conv in converter_registry.items(): for conv_key, conv in converter_registry.items():
if conv_key in ("XMLTag", "XMLFile", "XMLTextNode"): assert conv["package"] == "caoscrawler.converters"
assert conv["package"] == "caoscrawler.xml_converter"
else:
assert conv["package"] == "caoscrawler.converters"
# ... and their names all end in "Converter" # ... and their names all end in "Converter"
assert conv["converter"].endswith("Converter") assert conv["converter"].endswith("Converter")
......
...@@ -26,9 +26,9 @@ from pytest import fixture, importorskip ...@@ -26,9 +26,9 @@ from pytest import fixture, importorskip
import linkahead as db import linkahead as db
from caoscrawler.debug_tree import DebugTree from caoscrawler.debug_tree import DebugTree
from caoscrawler.hdf5_converter import (convert_basic_element_with_nd_array, from caoscrawler.converters.hdf5_converter import (convert_basic_element_with_nd_array,
convert_h5_element, H5GroupElement, convert_h5_element, H5GroupElement,
H5DatasetElement, H5NdarrayElement) H5DatasetElement, H5NdarrayElement)
from caoscrawler.scanner import scan_directory from caoscrawler.scanner import scan_directory
from caoscrawler.structure_elements import (FloatElement, ListElement, from caoscrawler.structure_elements import (FloatElement, ListElement,
TextElement) TextElement)
......
...@@ -21,40 +21,22 @@ ...@@ -21,40 +21,22 @@
# #
""" """
test the converters module test the XML converters
""" """
import datetime
import importlib import importlib
import json import json
import logging import pytest
import os
import sys import sys
from itertools import product import yaml
from lxml.etree import fromstring
from pathlib import Path from pathlib import Path
import pytest from caoscrawler.converters import XMLTagConverter
import yaml from caoscrawler.scanner import load_definition
from caoscrawler.converters import (Converter, ConverterValidationError,
DateElementConverter, DictElementConverter,
DictIntegerElementConverter,
DirectoryConverter, FloatElementConverter,
IntegerElementConverter, JSONFileConverter,
ListElementConverter,
MarkdownFileConverter, YAMLFileConverter,
_AbstractScalarValueElementConverter,
handle_value, replace_variables)
from caoscrawler.crawl import Crawler
from caoscrawler.scanner import (_load_definition_from_yaml_dict,
create_converter_registry,
create_transformer_registry, load_definition)
from caoscrawler.stores import GeneralStore from caoscrawler.stores import GeneralStore
from caoscrawler.structure_elements import (BooleanElement, DictElement, from caoscrawler.structure_elements import XMLTagElement
Directory, File, FloatElement,
IntegerElement, ListElement,
TextElement, XMLTagElement)
from caoscrawler.xml_converter import XMLTagConverter
from lxml.etree import fromstring
UNITTESTDIR = Path(__file__).parent UNITTESTDIR = Path(__file__).parent
...@@ -62,19 +44,13 @@ UNITTESTDIR = Path(__file__).parent ...@@ -62,19 +44,13 @@ UNITTESTDIR = Path(__file__).parent
@pytest.fixture @pytest.fixture
def converter_registry(): def converter_registry():
converter_registry: dict[str, dict[str, str]] = { converter_registry: dict[str, dict[str, str]] = {
"Directory": {
"converter": "DirectoryConverter",
"package": "caoscrawler.converters"},
"TextElement": {
"converter": "TextElementConverter",
"package": "caoscrawler.converters"},
"XMLTag": { "XMLTag": {
"converter": "XMLTagConverter", "converter": "XMLTagConverter",
"package": "caoscrawler.xml_converter"}, "package": "caoscrawler.converters"},
"XMLTextNode": { "XMLTextNode": {
"converter": "XMLTextNodeConverter", "converter": "XMLTextNodeConverter",
"package": "caoscrawler.xml_converter"}, "package": "caoscrawler.converters"},
} }
for key, value in converter_registry.items(): for key, value in converter_registry.items():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment