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()