Skip to content

Commit

Permalink
Tidy layout_nnnn_uuid_quadtree
Browse files Browse the repository at this point in the history
  • Loading branch information
zimeon committed Dec 12, 2024
1 parent 64c9c3c commit 8fbd175
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
42 changes: 36 additions & 6 deletions ocfl/layout_nnnn_uuid_quadtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,56 @@ def config(self):
def check_prefix(self, value):
"""Check prefix paremeter.
Any string is allowed.
Argument:
value (str): prefix string
Raises:
LayoutException: if the prefix is not allowed
Any non-empty string is allowed. Sets the prefix property as a side-effect.
"""
if value is None:
raise LayoutException("prefix parameter must be specified")
if not isinstance(value, str):
raise LayoutException("prefix parameter must be a string")
if not isinstance(value, str) or value == "":
raise LayoutException("prefix parameter must be a non-empty string")
self.prefix = value

def encode(self, identifier):
"""NOOP encode identifier."""
"""NOOP encode identifier.
Arguments:
identifier (str): identifier
Returns:
str: unchanged identifier
"""
return identifier

def decode(self, identifier):
"""NOOP decode identifier."""
"""NOOP decode identifier.
Arguments:
identifier (str): identifier
Returns:
str: unchanged identifier
"""
return identifier

def identifier_to_path(self, identifier):
"""Convert identifier to path relative to root.
Must match prefix:6ba7b810-9dad-11d1-80b4-00c04fd430c8
Argument:
identifier (str): object identifier
Returns:
str: object path for this layout
Raises:
LayoutException: if the identifier cannot be converted to a valid
object path.
Format is "prefix:6ba7b810-9dad-11d1-80b4-00c04fd430c8"
"""
if identifier.startswith(self.prefix):
identifier = identifier[len(self.prefix):]
Expand Down
19 changes: 17 additions & 2 deletions tests/test_layout_nnnn_uuid_quadtree.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
"""Digest tests."""
import unittest
from ocfl.layout import LayoutException
from ocfl.layout_nnnn_uuid_quadtree import Layout_NNNN_UUID_Quadtree


class TestAll(unittest.TestCase):
"""TestAll class to run tests."""

def test01_encode(self):
def test_config(self):
"""Test config property."""
layout = Layout_NNNN_UUID_Quadtree()
self.assertEqual(set(layout.config.keys()), set(("extensionName", "prefix")))

def test_check_prefix(self):
"""Test check_prefix method."""
layout = Layout_NNNN_UUID_Quadtree()
self.assertRaises(LayoutException, layout.check_prefix, None)
self.assertRaises(LayoutException, layout.check_prefix, 53)
self.assertRaises(LayoutException, layout.check_prefix, "") # stil not!
self.assertEqual(layout.check_prefix("Pref"), None)
self.assertEqual(layout.prefix, "Pref")

def test_encode(self):
"""Test NOOP encode."""
uuqt = Layout_NNNN_UUID_Quadtree()
self.assertEqual(uuqt.encode(""), "")
self.assertEqual(uuqt.encode("a"), "a")
self.assertEqual(uuqt.encode("a/b:?"), "a/b:?")

def test02_decode(self):
def test_decode(self):
"""Test NOOP decode."""
uuqt = Layout_NNNN_UUID_Quadtree()
self.assertEqual(uuqt.decode(""), "")
Expand Down

0 comments on commit 8fbd175

Please sign in to comment.