Add test for verify existing dir

This commit is contained in:
nolash 2021-06-01 11:46:17 +02:00
parent 245832235d
commit f8c1deb752
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 7 additions and 5 deletions

View File

@ -21,9 +21,7 @@ class HexDir:
fi = os.stat(self.path)
self.__verify_directory()
except FileNotFoundError:
HexDir.__setup_directory(self.path)
if not stat.S_ISDIR(fi.st_mode):
raise ValueError('{} is not a directory'.format(self.path))
HexDir.__prepare_directory(self.path)
self.master_file = os.path.join(self.path, 'master')
@ -92,6 +90,10 @@ class HexDir:
def __verify_directory(self):
#if not stat.S_ISDIR(fi.st_mode):
# raise ValueError('{} is not a directory'.format(self.path))
f = opendir(self.path)
f.close()
return True

View File

@ -16,7 +16,7 @@ class HexDirTest(unittest.TestCase):
def setUp(self):
self.dir = tempfile.mkdtemp()
self.hexdir = HexDir(self.dir, 4, 3, 2)
self.hexdir = HexDir(os.path.join(self.dir, 'q'), 4, 3, 2)
logg.debug('setup hexdir root {}'.format(self.dir))
@ -30,7 +30,7 @@ class HexDirTest(unittest.TestCase):
prefix = b'ab'
label = b'\xde\xad\xbe\xef'
self.hexdir.add(label, content, prefix=prefix)
file_path = os.path.join(self.dir, 'DE', 'AD', 'BE', label.hex().upper())
file_path = os.path.join(self.dir, 'q', 'DE', 'AD', 'BE', label.hex().upper())
f = open(file_path, 'rb')
r = f.read()