From ddf7c3e82899975458fb4620667099c24014fa78 Mon Sep 17 00:00:00 2001
From: Joscha Schmiedt <joscha@schmiedt.dev>
Date: Tue, 12 Mar 2024 19:59:25 +0100
Subject: [PATCH] TST: Extend Container slicing test

- include check for TypeError when using bad keys
---
 src/linkahead/common/models.py | 3 ++-
 unittests/test_container.py    | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/linkahead/common/models.py b/src/linkahead/common/models.py
index 9644485a..a2aeb440 100644
--- a/src/linkahead/common/models.py
+++ b/src/linkahead/common/models.py
@@ -3002,9 +3002,10 @@ class Container(list):
         return xml2str(self.to_xml())
 
     def __getitem__(self, key):
-        # Construct new Container from list slice
+        
         self_as_list_slice = super().__getitem__(key)
         if isinstance(self_as_list_slice, list):
+            # Construct new Container from list slice
             return Container().extend(self_as_list_slice)
         else:
             return self_as_list_slice
diff --git a/unittests/test_container.py b/unittests/test_container.py
index cfada7cc..6e0f096e 100644
--- a/unittests/test_container.py
+++ b/unittests/test_container.py
@@ -192,3 +192,9 @@ def test_container_slicing():
             f"element in slice was not Record, but {type(element)}"
     assert len(container_slice) == 2
     assert cont[-1].name == "TestRec5"
+
+    with pytest.raises(TypeError):
+        cont["stringkey"]
+
+    with pytest.raises(TypeError):
+        cont[[0,2,3]]
-- 
GitLab