commit 426f8f3cd3469b4c993dab9e2df4332715752ebb
parent ad22db488923dc8cbefd5c678ad0b1688aa1c93e
Author: lash <dev@holbrook.no>
Date:   Tue, 29 Aug 2023 22:30:03 +0100
Add filepath generator for uuid
Diffstat:
2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/leveldir/uuid.py b/leveldir/uuid.py
@@ -42,3 +42,7 @@ class UUIDDir(HexDir):
         key = self.__convert(key, as_hex=True)
         return super(UUIDDir, self).have(key)
 
+    
+    def to_filepath(self, key):
+        key = self.__convert(key, as_hex=True)
+        return super(UUIDDir, self).to_filepath(key)
diff --git a/tests/test_uuiddir.py b/tests/test_uuiddir.py
@@ -42,6 +42,16 @@ class HexDirTest(unittest.TestCase):
 
         self.assertTrue(self.uuiddir.have(label))
 
+        u = uuid.uuid4()
+        (c, entry_path) = self.uuiddir.add(u, content, prefix=prefix)
+        gotten_path = self.uuiddir.to_filepath(u)
+        self.assertEqual(entry_path, gotten_path)
+
+        gotten_path = self.uuiddir.to_filepath(u.bytes)
+        self.assertEqual(entry_path, gotten_path)
+
+        gotten_path = self.uuiddir.to_filepath(u.hex)
+        self.assertEqual(entry_path, gotten_path)
 
 
 if __name__ == '__main__':