test_uuiddir.py (1524B)
1 # standard imports 2 import uuid 3 import unittest 4 import tempfile 5 import shutil 6 import logging 7 import os 8 9 # local imports 10 from leveldir.uuid import UUIDDir 11 12 logging.basicConfig(level=logging.DEBUG) 13 logg = logging.getLogger() 14 15 16 class HexDirTest(unittest.TestCase): 17 18 def setUp(self): 19 self.dir = tempfile.mkdtemp() 20 self.uuiddir = UUIDDir(os.path.join(self.dir, 'q'), 3, 2) 21 logg.debug('setup uuiddir root {}'.format(self.dir)) 22 23 24 def tearDown(self): 25 shutil.rmtree(self.dir) 26 logg.debug('cleaned hexdir root {}'.format(self.dir)) 27 28 29 def test_add_types(self): 30 content = b'cdef' 31 prefix = b'ab' 32 label = uuid.uuid4() 33 (c, entry_path) = self.uuiddir.add(label, content, prefix=prefix) 34 35 label = uuid.uuid4() 36 label = label.hex 37 (c, entry_path) = self.uuiddir.add(label, content, prefix=prefix) 38 39 label = uuid.uuid4() 40 label = label.bytes 41 (c, entry_path) = self.uuiddir.add(label, content, prefix=prefix) 42 43 self.assertTrue(self.uuiddir.have(label)) 44 45 u = uuid.uuid4() 46 (c, entry_path) = self.uuiddir.add(u, content, prefix=prefix) 47 gotten_path = self.uuiddir.to_filepath(u) 48 self.assertEqual(entry_path, gotten_path) 49 50 gotten_path = self.uuiddir.to_filepath(u.bytes) 51 self.assertEqual(entry_path, gotten_path) 52 53 gotten_path = self.uuiddir.to_filepath(u.hex) 54 self.assertEqual(entry_path, gotten_path) 55 56 57 if __name__ == '__main__': 58 unittest.main()