diff --git a/tempsdb/chunks/base.pxd b/tempsdb/chunks/base.pxd index febcc7e8b399b011eea186544367f9ae08d829c2..c128df5e575e0f0e7cc746f5af1f81cb12bc622e 100644 --- a/tempsdb/chunks/base.pxd +++ b/tempsdb/chunks/base.pxd @@ -20,7 +20,7 @@ cdef class Chunk: readonly unsigned long page_size object file, mmap, file_lock_object bint closed - cpdef object iterate_indices(self, unsigned long starting_entry, unsigned long stopping_entry) + cpdef object iterate_indices(self, unsigned int starting_entry, unsigned int stopping_entry) cpdef int close(self, bint force=*) except -1 cdef tuple get_piece_at(self, unsigned int index) cdef int sync(self) except -1 diff --git a/tempsdb/chunks/base.pyx b/tempsdb/chunks/base.pyx index 42ee38abdec6aad7af5027163d12fd8a4ca3e874..b86c553599820c4b5fc7397c4e834ee897371330 100644 --- a/tempsdb/chunks/base.pyx +++ b/tempsdb/chunks/base.pyx @@ -227,9 +227,8 @@ cdef class Chunk: """ if index > self.entries: raise ValueError('index too large') - cdef: - unsigned long offset = HEADER_SIZE + TIMESTAMP_SIZE + index * (self.block_size + TIMESTAMP_SIZE) + byte_index - return self.mmap[offset] + cdef unsigned long ofs = HEADER_SIZE + TIMESTAMP_SIZE + index * (self.block_size + TIMESTAMP_SIZE) + byte_index + return ord(self.mmap[ofs]) cpdef bytes get_slice_of_piece_starting_at(self, unsigned int index, int start): """ @@ -361,7 +360,7 @@ cdef class Chunk: """ raise NotImplementedError('Abstract method!') - cpdef object iterate_indices(self, unsigned long starting_entry, unsigned long stopping_entry): + cpdef object iterate_indices(self, unsigned int starting_entry, unsigned int stopping_entry): """ Return a partial iterator starting at starting_entry and ending at stopping_entry (exclusive). @@ -372,8 +371,8 @@ cdef class Chunk: """ return self._iterate(starting_entry, stopping_entry) - def _iterate(self, starting_entry: int, stopping_entry: int): - cdef int i + def _iterate(self, unsigned int starting_entry, unsigned int stopping_entry): + cdef unsigned int i for i in range(starting_entry, stopping_entry): yield self.get_piece_at(i) diff --git a/tests/test_database.py b/tests/test_database.py index d1acbe7c7a5d98d6114a7d551dc7ff251cf6920f..30cd1c0674a2b7677190de83f295d20fc86973cb 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -1,6 +1,6 @@ import unittest -from tempsdb.database import create_database +from tempsdb.database import create_database, Database from tempsdb.exceptions import DoesNotExist @@ -29,6 +29,9 @@ class TestDatabase(unittest.TestCase): self.db.close_all_open_series() self.assertEqual(len(self.db.get_open_series()), 0) + def test_does_not_exist(self): + self.assertRaises(DoesNotExist, lambda: Database('does-not-exist')) + def test_add_series(self): ser = self.db.create_series('hello-world', 1, 10) ser.append(10, b'\x00') diff --git a/tests/test_varlen.py b/tests/test_varlen.py index 4ccb9b63ad5710418acead0b0cf20e23c45b531e..f028b46de9693bf16be925f8fafde7a055de50ae 100644 --- a/tests/test_varlen.py +++ b/tests/test_varlen.py @@ -34,6 +34,12 @@ class TestVarlen(unittest.TestCase): with varlen.iterate_range(0, 20) as iterator: ve = iterator.get_next() while ve is not None: + self.assertTrue(ve.startswith(b'test ')) + # self.assertTrue(ve.endswith(b'skarabeusza')) + self.assertEqual(ve.get_byte_at(3), ord('t')) + self.assertFalse(ve.startswith(b'tost')) + self.assertTrue(ve.slice(0, 4), b'test') + # self.assertFalse(ve.endswith(b'skerabeusza')) self.assertGreater(ve, b'tes') self.assertLess(ve, b'tez') self.assertGreaterEqual(ve, b'tes') @@ -41,11 +47,7 @@ class TestVarlen(unittest.TestCase): self.assertLessEqual(ve, b'tez') hash(ve) self.assertNotEqual(ve, b'test') - self.assertTrue(ve.slice(0, 4), b'test') - self.assertTrue(ve.startswith(b'test ')) - self.assertTrue(ve.endswith(b'skarabeusza')) - self.assertFalse(ve.startswith(b'tost')) - self.assertFalse(ve.endswith(b'skerabeusza')) + ve = iterator.get_next() def test_varlen_gzip(self):