move files into a package structure

This commit is contained in:
2022-02-06 16:02:54 +01:00
parent 8bb4ca0563
commit 5428553a1e
28 changed files with 23 additions and 26 deletions

View File

@@ -0,0 +1,76 @@
import tempfile
import unittest
from os.path import join
from raven.util.int2intmap import Int2IntMap
class Int2IntMapLike(unittest.TestCase):
def setUp(self):
self.test_dir = tempfile.TemporaryDirectory()
self.tmpfile = join(self.test_dir.name, "my.log")
self.map = Int2IntMap(self.tmpfile)
def tearDown(self):
self.map.close()
self.test_dir.cleanup()
def test_empty_map(self):
map = self.map
self.assertEqual(None, map.find(0))
def test_one_line_one_byte(self):
map = self.map
map.add(10, 1) # add the key 10
self.assertEqual(None, map.find(9)) # directly before
self.assertEqual(1, map.find(10))
self.assertEqual(None, map.find(11)) # directly after
def test_one_line_two_bytes(self):
map = self.map
map.add(10, 1) # added key 10
map.add(11, 2) # added key 11
self.assertEqual(None, map.find(9)) # directly before
self.assertEqual(1, map.find(10))
self.assertEqual(2, map.find(11))
self.assertEqual(None, map.find(12)) # directly after
def test_two_lines(self):
map = self.map
map.add(10, 1) # added key 10
map.add(12, 2) # added key 12
self.assertEqual(None, map.find(9)) # directly before
self.assertEqual(1, map.find(10))
self.assertEqual(None, map.find(11)) # between
self.assertEqual(2, map.find(12))
self.assertEqual(None, map.find(13)) # directly after
def test_fill_map(self):
map = self.map
map.blocksize = 64
# fill map with
# 10,5,1
# 20,5,2
# 30,5,3
# ...
#
# range(1,50) results in 6 blocks a 64 byte
for i in range(1, 50):
# print("add %d"%(i*10))
map.add(i * 10, i)
# print("%d -> blocks: %d" %(i, map.total_blocks()))
for j in range(1, i * 10):
if j % 10 == 0:
# values that are in the map
# print("check %d" % (j * 10))
self.assertEqual(j / 10, map.find(j))
else:
# values that are not in the map
self.assertEqual(None, map.find(j))
if __name__ == '__main__':
unittest.main()