JMComic-Crawler-Python/tests/test_jmcomic/test_jm_custom.py

101 lines
2.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from test_jmcomic import *
class Test_Custom(JmTestConfigurable):
def test_custom_entity(self):
"""
测试自定义属性
"""
dic = {1: 'd', 2: 'e'}
class MyAlbum(JmAlbumDetail):
@property
def aname(self):
return dic[int(self.album_id)]
class MyPhoto(JmPhotoDetail):
@property
def pname(self):
return dic[int(self.photo_id)]
JmModuleConfig.CLASS_ALBUM = MyAlbum
JmModuleConfig.CLASS_PHOTO = MyPhoto
base_dir: str = workspace()
dir_rule = DirRule('Bd_Aaname_Ppname', base_dir)
# noinspection PyTypeChecker
save_dir = dir_rule.deside_image_save_dir(
MyAlbum('1', '0', '0', [], *['0'] * 10),
MyPhoto('2', *['0'] * 7)
)
self.assertEqual(
os.path.abspath(save_dir),
os.path.abspath(base_dir + dic[1] + '/' + dic[2]),
)
def test_extends_api_client(self):
class MyClient(JmApiClient):
pass
JmModuleConfig.register_client(MyClient)
self.assertListEqual(
JmModuleConfig.DOMAIN_API_LIST,
self.option.new_jm_client(domain=[], impl=MyClient.client_key).get_domain_list()
)
def test_extends_html_client(self):
class MyClient(JmHtmlClient):
pass
JmModuleConfig.register_client(MyClient)
html_domain = self.client.get_html_domain()
JmModuleConfig.DOMAIN_HTML_LIST = [html_domain]
self.assertListEqual(
JmModuleConfig.DOMAIN_HTML_LIST,
self.option.new_jm_client(domain=[], impl=MyClient.client_key).get_domain_list()
)
def test_client_key_missing(self):
class MyClient(JmcomicClient):
pass
# '不重写 client_key'
self.assertRaises(
JmModuleConfig.CLASS_EXCEPTION,
JmModuleConfig.register_client,
MyClient,
)
def test_custom_client_empty_domain(self):
class MyClient(JmcomicClient):
client_key = 'myclient'
pass
JmModuleConfig.register_client(MyClient)
# '自定义client不配置域名'
self.assertRaises(
JmModuleConfig.CLASS_EXCEPTION,
self.option.new_jm_client,
domain_list=[],
impl=MyClient.client_key,
)
def test_client_empty_domain(self):
class MyClient(JmApiClient):
client_key = 'myclient'
pass
JmModuleConfig.register_client(MyClient)
self.assertListEqual(
JmModuleConfig.DOMAIN_API_LIST,
self.option.new_jm_client(domain=[], impl=MyClient.client_key).get_domain_list(),
msg='继承client不配置域名',
)