leveldir

Multi-level directory structure data stores in python3
git clone git://git.defalsify.org/python-leveldir.git
Log | Files | Refs | LICENSE

commit 610a1668ed8ea0903d5c02c70c43dca9a16dfd1c
parent ec7301333f436eea1f5ebd532f7cbc31021e0b0c
Author: nolash <dev@holbrook.no>
Date:   Sun, 27 Jun 2021 10:06:15 +0200

Add actual dir creation tests

Diffstat:
Mleveldir/numeric.py | 8++++++--
Arun_tests.sh | 8++++++++
Mtests/test_numdir.py | 25++++++++++++++++++++++++-
3 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/leveldir/numeric.py b/leveldir/numeric.py @@ -44,10 +44,14 @@ class NumDir(LevelDir): def add(self, n, content, prefix=b''): - path = to_filepath(n) + path = self.to_filepath(n) + + os.makedirs(os.path.dirname(path), exist_ok=True) + f = open(path, 'wb') f.write(content) + f.close() f = open(self.master_file, 'ab') - f.write(n.to_bytes(8, byteorder('big'))) + f.write(n.to_bytes(8, byteorder='big')) f.close() diff --git a/run_tests.sh b/run_tests.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set +x +export PYTHONPATH=. +for f in `ls tests/*.py`; do + python $f +done +set -x diff --git a/tests/test_numdir.py b/tests/test_numdir.py @@ -8,7 +8,6 @@ import os # local imports from leveldir.numeric import NumDir - logging.basicConfig(level=logging.DEBUG) logg = logging.getLogger() @@ -47,6 +46,30 @@ class NumDirTest(unittest.TestCase): self.numdir = NumDir(os.path.join(self.dir, 'n'), []) + def test_single_level(self): + self.numdir = NumDir(os.path.join(self.dir, 'n'), [1000]) + b = os.urandom(32) + self.numdir.add(1337, b) + b = os.urandom(32) + self.numdir.add(666, b) + b = os.urandom(32) + self.numdir.add(100000, b) + + self.assertEqual(self.numdir.count(), 3) + + + def test_multilevel(self): + logg.debug('using dir {}'.format(self.dir)) + self.numdir = NumDir(os.path.join(self.dir, 'n'), [1000, 100, 10]) + b = os.urandom(32) + self.numdir.add(1337, b) + b = os.urandom(32) + self.numdir.add(666, b) + b = os.urandom(32) + self.numdir.add(100000, b) + + self.assertEqual(self.numdir.count(), 3) + if __name__ == '__main__': unittest.main()