kindle manager
This commit is contained in:
135
unitest.kman.py
135
unitest.kman.py
@@ -13,6 +13,8 @@ import json
|
||||
from collections import defaultdict
|
||||
|
||||
from kman import *
|
||||
from parseweb import *
|
||||
from mtable import *
|
||||
|
||||
# log info
|
||||
logger = logging.getLogger()
|
||||
@@ -31,7 +33,7 @@ class TestKman(unittest.TestCase):
|
||||
DELIMITER= '|'
|
||||
|
||||
self.km = kMan()
|
||||
self.util = util()
|
||||
self.util = Util()
|
||||
|
||||
global t_bm_sec
|
||||
global t_hl_sec
|
||||
@@ -167,7 +169,7 @@ class TestKman(unittest.TestCase):
|
||||
print("与预期匹配,sidx 3 重复被删除,抛出: %s" % 'keyerror')
|
||||
|
||||
t_secd.clear()
|
||||
|
||||
|
||||
# test function format_time()
|
||||
def test_format_time(self):
|
||||
t_ds = '2020年1月13日 星期一 下午 8:11:05'
|
||||
@@ -217,7 +219,7 @@ class TestKman(unittest.TestCase):
|
||||
logger.debug('========== 2 ==========\n')
|
||||
logger.debug(json.dumps(bn, indent=2, ensure_ascii=False))
|
||||
bn = {}
|
||||
|
||||
|
||||
# by author
|
||||
bn = self.km.filter_clips(t_books, '贾雷德·戴蒙德', 2)
|
||||
logger.debug('========== 3 ==========\n')
|
||||
@@ -228,14 +230,62 @@ class TestKman(unittest.TestCase):
|
||||
def test_import_words(self):
|
||||
import pprint
|
||||
[bookinfo, lookups, words] = self.km.import_words()
|
||||
# how to beauty print to logger file
|
||||
# how to beauty print to logger file
|
||||
logger.debug('========== 4 ==========\n')
|
||||
logger.debug(json.dumps(bookinfo, indent=2, ensure_ascii=False))
|
||||
logger.debug('========== 5 ==========\n')
|
||||
logger.debug('========== 5 ==========\n')
|
||||
logger.debug(json.dumps(lookups, indent=2, ensure_ascii=False))
|
||||
logger.debug('========== 6 ==========\n')
|
||||
logger.debug(json.dumps(words, indent=2, ensure_ascii=False))
|
||||
|
||||
# test filter_words()
|
||||
logger.debug('========== 7 ==========\n')
|
||||
self.km.filter_words(self.km.import_words(), '中国历史风云录 (陈舜臣作品)', tp=0)
|
||||
|
||||
logger.debug('========== 8 ==========\n')
|
||||
self.km.filter_words(self.km.import_words(), 'zh:闾', tp=1)
|
||||
|
||||
def test_util(self):
|
||||
logger.debug( 'test get_app_path: {}'.format( self.util.get_app_path()))
|
||||
|
||||
def test_mtable(self):
|
||||
print('\n---------------------')
|
||||
data = [['Ohiox','Ohio','Ohio','Nevada','Nevada'],
|
||||
[2000,2001,2002,2001,2002],
|
||||
[1.5,1.7,3.6,2.4,2.9],
|
||||
[1.5,1.7,3.6,2.4,2.9],
|
||||
]
|
||||
|
||||
mt = mTable(data,
|
||||
index = ['one', 'two','three','four','five'],
|
||||
columns = ['year','state','pop','debt','xx'])
|
||||
|
||||
print('== frame\n', mt)
|
||||
print('== frame.iat[0, 0]\n', mt.get_iat(0, 0))
|
||||
print('== frame.iat[1, 1]\n', mt.get_iat(1, 1))
|
||||
print('== frame.iat[2, 2]\n', mt.get_iat(2, 2))
|
||||
print('== frame.iat[2, 1]\n', mt.get_iat(2, 1))
|
||||
print('== frame.shape[0]\n', mt.get_num_rows())
|
||||
print('== frame.shape[1]\n', mt.get_num_columns())
|
||||
print('== frame.columns\n', mt.get_columns())
|
||||
print('== frame.index\n', mt.get_index())
|
||||
|
||||
mt = mTable(data,
|
||||
columns = ['year','state','pop','debt','xx'])
|
||||
print('== frame\n', mt)
|
||||
print('== frame.iat[2, 1]\n', mt.get_iat(2, 1))
|
||||
print('== frame.shape[0]\n', mt.get_num_rows())
|
||||
print('== frame.shape[1]\n', mt.get_num_columns())
|
||||
print('== frame.columns\n', mt.get_columns())
|
||||
print('== frame.index\n', mt.get_index())
|
||||
|
||||
mt = mTable(data)
|
||||
mt.set_repr_width(20)
|
||||
print('== frame\n', mt)
|
||||
print('== frame.iat[2, 1]\n', mt.get_iat(2, 1))
|
||||
print('== frame.shape[0]\n', mt.get_num_rows())
|
||||
print('== frame.shape[1]\n', mt.get_num_columns())
|
||||
print('== frame.columns\n', mt.get_columns())
|
||||
print('== frame.index\n', mt.get_index())
|
||||
|
||||
mt = mTable()
|
||||
@@ -249,6 +299,80 @@ class TestKman(unittest.TestCase):
|
||||
"""
|
||||
def test_search_clip(self):
|
||||
pass
|
||||
def test_statistic(self):
|
||||
pass
|
||||
def test_dict2json(self):
|
||||
pass
|
||||
def test_json2dict(self):
|
||||
pass
|
||||
def test_import_clips(self):
|
||||
pass
|
||||
"""
|
||||
|
||||
def test_parseweb(self):
|
||||
spide = bookInfoSpide()
|
||||
|
||||
"""
|
||||
for bkname in testbooks:
|
||||
bkname = re.split(r'[\((\-\::_\s]',bkname.strip())[0]
|
||||
print(bkname)
|
||||
bkinfo = spide.grab_book_info(bkname)
|
||||
filter_bkinfo = spide.filter_spide_book(bkinfo)
|
||||
if filter_bkinfo: spide.down_book_img(filter_bkinfo)
|
||||
|
||||
logger.debug('================ {} ================'.format(bkname))
|
||||
logger.debug(json.dumps(bkinfo,indent=2, ensure_ascii=False))
|
||||
logger.debug(json.dumps(filter_bkinfo,indent=2, ensure_ascii=False))
|
||||
"""
|
||||
|
||||
def test_kman(self):
|
||||
#books = defaultdict(dict)
|
||||
km = kMan()
|
||||
books = km.import_clips()
|
||||
|
||||
# remove duplication
|
||||
km.drop_duplicate(books)
|
||||
|
||||
# test search note function
|
||||
searchnote = km.search_clip(books, '三大都市圈', 'ALL', 'CONTENT')
|
||||
if searchnote[0] > 0: km.export_notes(searchnote[1], 'searchcontent', ft='MD')
|
||||
searchnote = km.search_clip(books, '经济', 'ALL', 'TITLE')
|
||||
if searchnote[0] > 0: km.export_notes(searchnote[1], 'searchtitle', ft='MD')
|
||||
searchnote = km.search_clip(books, '巴曙松', 'ALL', 'AUTHOR')
|
||||
if searchnote[0] > 0: km.export_notes(searchnote[1], 'searchauthor', ft='MD')
|
||||
|
||||
#print(km.get_bookname_num(books))
|
||||
#print(km.get_author_num(books))
|
||||
|
||||
# add note content to hightlight, then delete note
|
||||
km.add_note_to_highlight(books)
|
||||
|
||||
# test dict json convert
|
||||
with open(os.path.join(CURRPATH,'xx'), 'w', encoding='utf8', errors='ignore') as fw:
|
||||
fw.write(km.dict2json(books))
|
||||
if km.json2dict(os.path.join(CURRPATH,'xx'))==books: print( 'test OK')
|
||||
|
||||
km.export_notes(books, OUTPREF, ft='MD')
|
||||
|
||||
# print data with json format
|
||||
logger.debug(json.dumps(books, indent=4, sort_keys=True, ensure_ascii=False))
|
||||
|
||||
def test_somepath(self):
|
||||
frozen = 'not'
|
||||
if getattr(sys, 'frozen', False):
|
||||
# we are running in a bundle
|
||||
frozen = 'ever so'
|
||||
bundle_dir = sys._MEIPASS
|
||||
else:
|
||||
# we are running in a normal Python environment
|
||||
bundle_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
print( 'we are',frozen,'frozen')
|
||||
print( 'bundle dir is', bundle_dir )
|
||||
print( 'sys.argv[0] is', sys.argv[0] )
|
||||
print( 'sys.executable is', sys.executable )
|
||||
print( 'os.getcwd is', os.getcwd() )
|
||||
|
||||
print('sys.path[0]', sys.path[0])
|
||||
print('sys.argv[0]', sys.argv[0])
|
||||
print('os.path.realpath(sys.executable)', os.path.realpath(sys.executable))
|
||||
print('os.path.realpath(sys.argv[0]))', os.path.realpath(sys.argv[0]))
|
||||
@@ -269,4 +393,3 @@ if __name__ == '__main__':
|
||||
suite = unittest.TestSuite ()
|
||||
suite.addTest(TestKman('test_parse_section'))
|
||||
suite.addTest(TestKman('test_format_time'))
|
||||
suite.addTest(TestKman('test_format_data'))
|
||||
|
||||
Reference in New Issue
Block a user