Skip to content
Snippets Groups Projects
Commit 05ffbc11 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

TST(converters): added first test for loading .eln files

parent 7cf8f3c8
No related branches found
No related tags found
2 merge requests!198REL: Release 0.10.0,!193ROCrate-Converter (also for .eln-files)
Pipeline #57148 failed
......@@ -23,6 +23,7 @@
from .. import utils
from .converters import *
from .xml_converter import *
from .rocrate import *
try:
from .spss import SPSSConverter
......
......@@ -230,13 +230,13 @@ class ROCrateElement(StructureElement):
"""
Initializes this ROCrateElement.
The name of the structure element is automatically set from the file path
and the name of the ro-crate separated with a "/".
The name of the structure element is automatically set from the
name of the ro-crate.
Arguments:
----------
rocrate: ROCrate
The rocrate that was loaded from a file.
"""
super().__init__(element.getroottree().getelementpath(element) + "/" + rocrate.name)
super().__init__(rocrate.name)
self.rocrate = rocrate
File added
File added
#!/usr/bin/env python3
# encoding: utf-8
#
# This file is a part of the LinkAhead Project.
#
# Copyright (C) 2024 Indiscale GmbH <info@indiscale.com>
# Copyright (C) 2024 Alexander Schlemmer <a.schlemmer@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
"""
test the XML converters
"""
import importlib
import json
import pytest
import sys
import yaml
import os
from lxml.etree import fromstring
from pathlib import Path
from rocrate.rocrate import ROCrate
from caoscrawler.converters import (ELNFileConverter,)
from caoscrawler.scanner import load_definition
from caoscrawler.stores import GeneralStore
from caoscrawler.structure_elements import ROCrateElement, File
UNITTESTDIR = Path(__file__).parent
@pytest.fixture
def converter_registry():
converter_registry: dict[str, dict[str, str]] = {
"ELNFile": {
"converter": "ELNFileConverter",
"package": "caoscrawler.converters"},
}
for key, value in converter_registry.items():
module = importlib.import_module(value["package"])
value["class"] = getattr(module, value["converter"])
return converter_registry
@pytest.fixture
def basic_eln_converter(converter_registry):
return ELNFileConverter(yaml.safe_load("""
type: ELNFile
match: .*\\.eln
"""), "TestELNConverter", converter_registry)
def test_load_pasta(basic_eln_converter):
"""
Test for loading the .eln example export from PASTA.
"""
f_pasta = File("PASTA.eln", os.path.join(UNITTESTDIR, "eln_files", "PASTA.eln"))
match = basic_eln_converter.match(f_pasta)
assert match is not None
crates = basic_eln_converter.create_children(GeneralStore(), f_pasta)
assert len(crates) == 1
assert isinstance(crates[0], ROCrateElement)
assert isinstance(crates[0].rocrate, ROCrate)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment