kindle manager

This commit is contained in:
gavin
2021-08-25 17:58:31 +08:00
parent 5f0c0a9724
commit 6b3c0f3b6b
303 changed files with 87829 additions and 42537 deletions

38
mobimaster/tests/test_mobi.py Executable file
View File

@@ -0,0 +1,38 @@
import os
import shutil
from os.path import abspath, join, exists, dirname, splitext
import mobi
from mobi.extract import extract, extracttest
from loguru import logger
logger.add("logfile.log")
TEST_DIR = dirname(abspath(__file__))
def test_extract():
for fname in os.listdir(TEST_DIR):
ext = splitext(fname)[-1].upper()
if ext in [".MOBI", ".PRC", ".AZW", ".AZW3", ".AZW4"]:
tempdir, filepath = extract(join(TEST_DIR, fname))
assert exists(tempdir)
assert exists(filepath)
shutil.rmtree(tempdir)
def test_extract_file_like():
bn = 'youxi.mobi'
#bn = 'xiaodao.mobi'
with open(join(TEST_DIR, bn), "rb") as infile:
tempdir, filepath = extracttest(infile)
print('infile {} tempdir {}, filepath {}'.format(infile, tempdir, filepath ))
# infile <_io.BufferedReader name='/Users/mark/mobiparse/mobimaster/tests/youxi.mobi'>
# tempdir ./t/, filepath ./t/mobi8/8x2vf7yv.epub
assert exists(tempdir)
assert exists(filepath)
#shutil.rmtree(tempdir)
if __name__=='__main__':
test_extract_file_like()