From 04a411851cf6104285525474b6704ea5b4819a2b Mon Sep 17 00:00:00 2001
From: Daniel <d.hornung@indiscale.com>
Date: Wed, 15 May 2024 16:22:34 +0200
Subject: [PATCH] FIX: Correct datatype now.

---
 src/caoscrawler/conv_impl/spss.py     | 4 +++-
 src/caoscrawler/structure_elements.py | 3 +--
 unittests/test_converters.py          | 5 +++--
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/caoscrawler/conv_impl/spss.py b/src/caoscrawler/conv_impl/spss.py
index 903dea27..51528cc2 100644
--- a/src/caoscrawler/conv_impl/spss.py
+++ b/src/caoscrawler/conv_impl/spss.py
@@ -72,12 +72,14 @@ def spss_to_yaml(savfile: str, yamlfile: str) -> None:
             prop["description"] = desc
         # Handle categorial variables
         if var_label := meta.variable_to_label.get(name):
-            prop["datatype"] = var_label
             vvl = meta.variable_value_labels[name]
             # reproducible (and sensible) order
             label_values = [vvl[key] for key in sorted(vvl.keys())]
             if label_values not in enums.values():
                 enums[var_label] = label_values
+            else:
+                var_label = [key for key, value in enums.items() if value == label_values][0]
+            prop["datatype"] = var_label
         properties[name] = prop
 
     output = f"""# auto-generated data model from file "{savfile}".
diff --git a/src/caoscrawler/structure_elements.py b/src/caoscrawler/structure_elements.py
index ff070626..0efba91c 100644
--- a/src/caoscrawler/structure_elements.py
+++ b/src/caoscrawler/structure_elements.py
@@ -23,7 +23,6 @@
 # ** end header
 #
 
-from typing import Dict as tDict
 import warnings
 
 
@@ -39,7 +38,7 @@ name: str
 
     def __init__(self, name: str):
         # Used to store usage information for debugging:
-        self.metadata: tDict[str, set[str]] = {
+        self.metadata: dict[str, set[str]] = {
             "usage": set()
         }
 
diff --git a/unittests/test_converters.py b/unittests/test_converters.py
index 0e90fab3..2f62ef92 100644
--- a/unittests/test_converters.py
+++ b/unittests/test_converters.py
@@ -3,8 +3,9 @@
 #
 # This file is a part of the CaosDB Project.
 #
-# Copyright (C) 2021,2022 Indiscale GmbH <info@indiscale.com>
+# Copyright (C) 2021-2024 Indiscale GmbH <info@indiscale.com>
 # Copyright (C) 2021,2022 Henrik tom Wörden <h.tomwoerden@indiscale.com>
+# Copyright (C) 2024 Daniel Hornung <d.hornung@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
@@ -632,7 +633,7 @@ def test_load_converters():
     # converter classes can be loaded from their respective packages.
 
     # Please adapt, if defaults change!
-    assert len(converter_registry) == 22
+    assert len(converter_registry) == 23
 
     # All of them are contained in caoscrawler.converters
     for conv_key, conv in converter_registry.items():
-- 
GitLab