Added manga-py source

This commit is contained in:
2019-12-14 22:33:14 -05:00
parent 9a4dd4b09b
commit 45067caea6
420 changed files with 18054 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
from .archive import TestArchive
from .base import TestBaseClass
from .gh_pages import TestGhPages
from .http import TestHttpClasses
from .init_provider import TestInitProvider
from .matrix import TestMatrix
from .web_driver import TestWebDriver
from .crypt import TestCrypt
from .std import TestStd

View File

@@ -0,0 +1,77 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import unittest
from os import path
from shutil import copyfile
from manga_py import fs
from manga_py.base_classes import Archive
root_path = path.dirname(path.realpath(__file__))
files_paths = [
['/files/img1.jpg', '/temp/img1.jpg'],
['/files/img2.png', '/temp/img2.png'],
['/files/img3.jpg', '/temp/img3.jpg'],
['/files/img4.jpg', '/temp/img4.jpg'],
['/files/img5.png', '/temp/img5.png'],
['/files/img6.gif', '/temp/img6.gif'],
['/files/img7.webp', '/temp/img7.webp'],
]
class TestArchive(unittest.TestCase):
def test_make_archive(self):
arc = Archive()
arc_path = root_path + '/temp/arc.zip'
fs.unlink(arc_path)
orig_size = 0
for idx, item in enumerate(files_paths):
fs.unlink(root_path + item[1])
copyfile(root_path + item[0], root_path + item[1])
orig_size += int(fs.file_size(root_path + item[1]))
arc.add_file(root_path + item[1])
copyfile(root_path + '/files/archive_test_file', root_path + '/temp/archive_test_file')
orig_size += int(fs.file_size(root_path + '/temp/archive_test_file'))
arc.add_file(root_path + '/temp/archive_test_file')
copyfile(root_path + '/files/archive_test_image', root_path + '/temp/archive_test_image')
orig_size += int(fs.file_size(root_path + '/temp/archive_test_image'))
arc.add_file(root_path + '/temp/archive_test_image')
arc.make(arc_path)
size = fs.file_size(arc_path)
self.assertTrue(size and 1024 < int(size) < orig_size)
def test_rename(self):
copyfile(root_path + '/files/archive_test_file', root_path + '/temp/archive_test_file')
fs.rename(root_path + '/temp/archive_test_file', root_path + '/temp/archive_test_file1')
self.assertTrue(fs.is_file(root_path + '/temp/archive_test_file1'))
self.assertFalse(fs.is_file(root_path + '/temp/archive_test_file'))
def test_home(self):
self.assertTrue(fs.get_util_home_path().find('/home/') == 0)
self.assertTrue(fs.is_dir(fs.get_util_home_path()))
def test_unlink1(self):
_dir = fs.get_util_home_path()
fs.make_dirs(_dir + '/dir')
self.assertRaises(OSError, fs.unlink, _dir)
def test_unlink2(self):
_dir = fs.get_util_home_path()
fs.make_dirs(_dir + '/dir')
fs.unlink(_dir, True)
self.assertFalse(fs.is_dir(_dir))
def test_not_filesize(self):
self.assertIsNone(fs.file_size(fs.get_util_home_path() + '/file'))
def test_check_free_space1(self):
self.assertTrue(fs.check_free_space(fs.get_util_home_path(), min_size=99))
def test_check_free_space2(self):
self.assertFalse(fs.check_free_space(fs.get_util_home_path(), 99, True))

View File

@@ -0,0 +1,120 @@
import json
import unittest
from os import path
from manga_py import fs
from manga_py.base_classes import Base, Static
root_path = fs.dirname(path.realpath(__file__))
files_paths = [
['/files/img1.jpg', '/temp/img1.jpg'],
['/files/img2.png', '/temp/img2.png'],
['/files/img3.jpg', '/temp/img3.jpg'],
['/files/img4.jpg', '/temp/img4.jpg'],
['/files/img5.png', '/temp/img5.png'],
['/files/img6.gif', '/temp/img6.gif'],
['/files/img7.webp', '/temp/img7.webp'],
]
def httpbin(bp: Base, _path: str):
variants = [
'https://httpbin-sttv.herokuapp.com',
'https://httpbin-org.herokuapp.com',
'https://httpbin.org',
]
_httpbin = None
for url in variants:
response = bp.http().requests(url=url, method='head')
if response.ok:
_httpbin = url
if _httpbin is None:
raise AttributeError('503. Service temporary unavailable / Path: %s ' % _path)
return '{}/{}'.format(_httpbin, _path.lstrip('/'))
class TestBaseClass(unittest.TestCase):
def test_base0(self):
bp = Base()
domain = 'http://example.org'
bp._params['url'] = domain + '/manga/here.html'
self.assertEqual(bp._params['url'], bp.get_url())
self.assertEqual(domain, bp.domain)
def test_base1(self):
bp = Base()
self.assertRaises(KeyError, bp.get_url)
def test_autocrop(self):
bp = Base()
img = files_paths[0]
fs.unlink(root_path + img[1])
bp.image_auto_crop(root_path + img[0], root_path + img[1])
self.assertTrue(fs.is_file(root_path + img[1]))
def test_manualcrop0(self):
bp = Base()
img = files_paths[0]
fs.unlink(root_path + img[1])
bp._image_params['crop'] = (10, 2, 100, 100)
bp.image_manual_crop(root_path + img[0], root_path + img[1])
self.assertTrue(fs.is_file(root_path + img[1]))
def test_manualcrop1(self):
bp = Base()
img = files_paths[0]
fs.unlink(root_path + img[1])
bp._image_params['offsets_crop'] = (10, 32, 12, 5)
bp.image_manual_crop(root_path + img[0], root_path + img[1])
self.assertTrue(fs.is_file(root_path + img[1]))
def test_get(self):
bp = Base()
bp._params['url'] = 'http://example.org/manga/here.html'
url = httpbin(bp, 'get')
self.assertEqual(url, json.loads(bp.http_get(url))['url'])
def test_post(self):
bp = Base()
bp._params['url'] = 'http://example.org/manga/here.html'
url = httpbin(bp, 'post')
self.assertEqual(url, json.loads(bp.http_post(url))['url'])
def test_cookies0(self):
bp = Base()
bp._params['url'] = 'http://example.org/manga/here.html'
url = httpbin(bp, 'cookies')
cookies = {'test': 'test-cookie'}
bp.http_get(httpbin(bp, 'cookies/set?test=') + cookies['test'])
content = bp.http_get(url, cookies=cookies)
# print(content)
self.assertEqual(cookies['test'], json.loads(content)['cookies']['test'])
def test_cookies1(self):
bp = Base()
bp._params['url'] = 'http://example.org/manga/here.html'
url = httpbin(bp, 'cookies/set?test=test-cookie')
self.assertEqual('test-cookie', bp.http().get_base_cookies(url).get('test'))
def test_redirect0(self):
from urllib.parse import quote
bp = Base()
bp._params['url'] = 'http://example.org/manga/here.html'
url = httpbin(bp, 'redirect-to?url=' + quote(httpbin(bp, 'get?test=1')))
test_data = {'test': '1'}
content = bp.http_get(url)
# print(content)
self.assertEqual(test_data, json.loads(content)['args'])
def test_redirect1(self):
bp = Base()
bp._params['url'] = 'http://example.org/manga/here.html'
url = httpbin(bp, 'redirect/11')
self.assertRaises(AttributeError, bp.http_get, url)
def test_ascii(self):
string = u'/\\\0@#$⼢⼣⼤abCde123йцуڪڦ'
normal_string = '@⼢⼣⼤abCde123йцуڪڦ'
self.assertEqual(Static.remove_not_ascii(string), normal_string)

View File

@@ -0,0 +1,76 @@
import unittest
from pathlib import Path
from .base import root_path
from manga_py.provider import Provider
from manga_py.crypt import AcQqComCrypt
from manga_py.crypt import KissMangaComCrypt
from manga_py.crypt import MangaRockComCrypt
from manga_py.crypt import ManhuaGuiComCrypt
from manga_py.crypt import MangaGoMe
from manga_py.image import Image
import json
import re
class TestCrypt(unittest.TestCase):
_ac_qq_data = '8eyJjb21pYyI6eyJpZCI6NTM2NDM1LCJ0aXRsZSI6Ilx1NTczMFx1ODVjZlx1OWY1MFx1NTkyOSIsImNvbGxlY3QiOiIxNDg3OTU1IiwiaXNKYXBhbkNvbWljIjpmYWxzZSwiaXNMaWdodE5vdmVsIjpmYWxzZSwiaXNMaWdodENvbWljIjpmYWxzZSwiaXNGaW5pc2giOmZhbHNlLCJpc1JvYXN0YWJsZSI6dHJ1ZSwiZUlkIjoiS2xCUFMwTlBYVlZhQWdZZkFRWUFBd3NNSEVKWVhTZz0ifSwiY2hhcHRlciI6eyJjaWQiOjI3NCwiY1RpdGxlIjoiMTI1XHVmZjFhXHU3OGE3XHU5MWNlXHUwMGI3XHU4NTg3XHU1YzlhIFx1NGUwYSIsImNTZXEiOiIyNTUiLCJ2aXBTdGF0dXMiOjIsInByZXZDaWQiOjI3MywibmV4dENpZCI6Mjc1LCJibGFua0ZpcnN0IjoxLCJjYW5SZWFkIjpmYWxzZX0sInBpY3R1cmUiOlt7InBpZCI6IjI4MDM3Iiwid2lkdGgiOjkwMCwiaGVpZ2h0IjoxMjczLCJ1cmwiOiJodHRwczpcL1wvbWFuaHVhLnFwaWMuY25cL21hbmh1YV9kZXRhaWxcLzBcLzI1XzE2XzI0X2U5NTNiZjhhMTBjODA1MWQxNTQyYzA0OWQ0OTdlOTJhXzI4MDM3LmpwZ1wvMCJ9XSwiYWRzIjp7InRvcCI6IiIsImxlZnQiOltdLCJib3R0b20iOnsidGl0bGUiOiJcdTRlMDdcdTRlOGJcdTRlMDdcdTcwNzUiLCJwaWMiOiJodHRwczpcL1wvbWFuaHVhLnFwaWMuY25cL29wZXJhdGlvblwvMFwvMDVfMTFfNDRfYzlhZGZlZGQxMjExNjczNTAyMWEyMmJjYTY2YWVkNDFfMTUzMDc2MjI2NjYxNy5qcGdcLzAiLCJ1cmwiOiJodHRwOlwvXC9hYy5xcS5jb21cL0NvbWljXC9jb21pY0luZm9cL2lkXC82MzEzOTkiLCJ3aWR0aCI6IjY1MCIsImhlaWdodCI6IjExMCJ9fSwiYXJ0aXN0Ijp7ImF2YXRhciI6Imh0dHA6XC9cL3RoaXJkcXEucWxvZ28uY25cL2c/Yj1zZGsmaz03dmg2WVBhSUQzNWRaQzZXMkppYlBFZyZzPTY0MCZ0PTE1MTczNzA2MjkiLCJuaWNrIjoiXHVmZjA4XHU1MTZiXHU1ZWE2XHVmZjA5XHU0ZTAwXHU0ZThjXHU1ZGU1XHU0ZjVjXHU1YmE0IiwidWluQ3J5cHQiOiJkMnRQZG5WV05GZE9XVms5In19'
_kissmanga_data = [
'hkJ+EJR/9dCEuATq4edqK2Y2yYuk7oHv6DtMcKdZDztGw8Bdrm3Uh9Z6aZnJeq51IeU04EwWn8DUZ3wEfdvMnYtQh7GSoWdOkdJa7Dbyfs7AspTURTDMhBqYsoZzduP7kyxQ/ftwtbQ733ShihZvNUg4pcR36H4YAKEAcwhZNA0=',
'hkJ+EJR/9dCEuATq4edqK9GZCq4jAmbydCinAnz3hV01EBnqDvmVlxgEsScYB6JxDM99fJN636C/8+qLQnGVZSDaZ5rRIISuamFvWwZBkpHl2UPXxHd/wIRd6CEcBxer6Zs7vjyjx6W33bVh1OHzeFcXJo8eHQCBmOdWEuF61fk=',
'hkJ+EJR/9dCEuATq4edqKzJtiFoZ4A6if1KVpaBlajzEcGnP+nT58dQpi9VyyFZduSlPLh9JhUtwrnN7SGjkTCaCr12oRm+OsHRJYhcLVjsz/tcnHEeBFUCJUC9IU5mK1ZKiIDQhEHbnJzh1P+WuNirvKIrHJGwpU7+NfxDvva4=',
]
_mangago_data = 'b/fewbQPsnakoTXxGjVeyvnp1IKTwZlqQJmozPy7EDIwDQP0M+OR+dhAvBSEBk0haWgKUgCELhnL1sDwJFKoJRPD3BPuEScf+m3wIHiDDySKmoG0yuM6D0nYKf3+mRPVeLWbPqEUEs9js8r/rZkMUpg8QBxL2LW9KWj5TFe5jbDieK1k0jKmnlLof+riZ5Lii3ogXBn3LkQ0OjuCEo3mH2495DfPuanMimtK52UCJIe1Slac4VGFmcfMxWggoTVwmxqlO3YvUHS8WvhUtXMSyy5i5PbuFCZ1RP1T7+RxtBr4xi4olxQBi84Lwk9LN9MnIXl3o3r5Jb2Aq8hBiDfG9gpAye+N0SVnONY2xjo/gEo/njWHEqb8Wggr6kuwUdjqtMQA8zOoEmLGGs4zgeddSR5SsE0WfSxc9gXQwUS3Dlz6vfWTSOPacqKonzT7ggG7cZOoR7gHmEUjjKPhumNnxCHLa0uwTdFpBg38c+72j5dpOqLRld6PsvOJalph2Y79'
@property
def _provider(self):
provider = Provider()
provider._params['url'] = 'http://example.org'
return provider
def test_ac_qq_com(self):
lib = AcQqComCrypt(self._provider)
'data from ac.qq.com/ComicView/index/id/536435/cid/274'
self.assertIsNotNone(lib.decode(self._ac_qq_data).get('comic', None))
def test_ac_qq_com_none(self):
lib = AcQqComCrypt(self._provider)
self.assertIsNone(lib.decode(self._ac_qq_data[5:]).get('comic', None))
def test_kissmanga(self):
lib = KissMangaComCrypt()
'view-source:kissmanga.com/Manga/Kou-1-Desu-ga-Isekai-de-Joushu-Hajimemashita/Chapter-019?id=401994'
key = lib.decode_escape(r'\x6E\x73\x66\x64\x37\x33\x32\x6E\x73\x64\x6E\x64\x73\x38\x32\x33\x6E\x73\x64\x66')
iv = b'a5e8e2e9c2721be0a84ad660c472c1f3'
for i in self._kissmanga_data:
href = lib.decrypt(iv, key, i).decode('utf-8').replace('\x10', '').replace('\x0f', '')
self.assertEqual(href[:4], 'http')
def test_manga_rock_com(self):
crypt = MangaRockComCrypt()
path_cr = str(Path(root_path).joinpath('files', 'manga_rock_com.mri'))
path_test = str(Path(root_path).joinpath('temp', 'manga_rock_com'))
self.assertIsNone(Image.real_extension(path_cr))
with open(path_cr, 'rb') as r:
with open(path_test, 'wb') as w:
w.write(crypt.decrypt(r.read()))
self.assertIsNotNone(Image.real_extension(path_test))
def test_manhuagui_com(self):
lib = ManhuaGuiComCrypt()
'view-source:https://www.manhuagui.com/comic/28271/375550.html#p=3'
path = str(Path(root_path).joinpath('files', 'manhuagui'))
with open(path, 'r') as f:
js = re.search(r'\](\(function\(.+\))\s?<', f.read())
data = lib.decrypt(js.group(1), '')
js = re.search(r'\(({.+})\)', data).group(1)
js = json.loads(js)
# self.assertIs(js, dict) # NOT WORKED Oo
self.assertTrue(isinstance(js, dict))
def test_mangago_me(self):
lib = MangaGoMe()
data = lib.decrypt(self._mangago_data)
self.assertEqual(data[:4], 'http')

View File

@@ -0,0 +1 @@
archive_test_file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,10 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import unittest
class TestGhPages(unittest.TestCase):
def test_make(self):
from helpers.gh_pages import main
main()

View File

@@ -0,0 +1,30 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import unittest
from manga_py.http.url_normalizer import normalize_uri
class TestHttpClasses(unittest.TestCase):
referer = 'http://example.org/manga/here.html'
def test_url_normalizer_url_helper1(self):
url = '//example.org/manga/here.html'
test_url = normalize_uri(url, self.referer)
self.assertEqual(self.referer, test_url)
def test_url_normalizer_url_helper2(self):
url = '/manga/here.html'
test_url = normalize_uri(url, self.referer)
self.assertEqual(self.referer, test_url)
def test_url_normalizer_url_helper3(self):
url = '://example.org/manga/here.html'
test_url = normalize_uri(url, self.referer)
self.assertEqual(self.referer, test_url)
def test_url_normalizer_url_helper4(self):
url = 'here.html'
test_url = normalize_uri(url, self.referer)
self.assertEqual(self.referer, test_url)

View File

@@ -0,0 +1,140 @@
import unittest
from os import path
from PIL import Image as PilImage
from manga_py import fs
from manga_py.image import Image
root_path = path.dirname(path.realpath(__file__))
files_paths = [
['/files/img1.jpg', '/temp/img1.jpg'],
['/files/img2.png', '/temp/img2.png'],
['/files/img3.jpg', '/temp/img3.jpg'],
['/files/img4.jpg', '/temp/img4.jpg'],
['/files/img5.png', '/temp/img5.png'],
['/files/img6.gif', '/temp/img6.gif'],
['/files/img7.webp', '/temp/img7.webp'],
]
class TestImages(unittest.TestCase):
def test_manual_crop(self):
for file in files_paths:
fs.unlink(root_path + file[1])
image = PilImage.open(root_path + file[0])
sizes = image.size
image.close()
img = Image(root_path + file[0])
img.crop_manual((10, 0, image.size[0], image.size[1]), root_path + file[1])
img.close()
cropped_image = PilImage.open(root_path + file[1])
cropped_sizes = cropped_image.size
cropped_image.close()
self.assertTrue((sizes[0] - cropped_sizes[0]) == 10)
def test_manual_crop_with_offsets(self):
for file in files_paths:
fs.unlink(root_path + file[1])
image = PilImage.open(root_path + file[0])
sizes = image.size
image.close()
img = Image(root_path + file[0])
img.crop_manual_with_offsets((10, 0, 0, 0), root_path + file[1])
img.close()
cropped_image = PilImage.open(root_path + file[1])
cropped_sizes = cropped_image.size
cropped_image.close()
self.assertTrue((sizes[0] - cropped_sizes[0]) == 10)
def test_auto_crop1(self):
file = files_paths[0]
fs.unlink(root_path + file[1])
image = PilImage.open(root_path + file[0])
sizes = image.size
image.close()
img = Image(root_path + file[0])
img.crop_auto(root_path + file[1])
img.close()
cropped_image = PilImage.open(root_path + file[1])
cropped_sizes = cropped_image.size
cropped_image.close()
self.assertTrue(sizes[0] > cropped_sizes[0])
def test_auto_crop2(self):
file = files_paths[1]
fs.unlink(root_path + file[1])
image = PilImage.open(root_path + file[0])
sizes = image.size
image.close()
img = Image(root_path + file[0])
img.crop_auto(root_path + file[1])
img.close()
cropped_image = PilImage.open(root_path + file[1])
cropped_sizes = cropped_image.size
cropped_image.close()
self.assertTrue(sizes[0] == cropped_sizes[0])
def test_auto_crop3(self):
file = files_paths[4]
fs.unlink(root_path + file[1])
image = PilImage.open(root_path + file[0])
sizes = image.size
image.close()
img = Image(root_path + file[0])
img.crop_auto(root_path + file[1])
img.close()
cropped_image = PilImage.open(root_path + file[1])
cropped_sizes = cropped_image.size
cropped_image.close()
self.assertTrue(sizes[0] == (2 + cropped_sizes[0])) # 2px black line
def test_image_not_found(self):
self.assertRaises(AttributeError, lambda: Image(root_path))
def test_gray1(self):
file = files_paths[1]
fs.unlink(root_path + file[1])
image = Image(root_path + file[0])
image.gray(root_path + file[1])
image.close()
image = PilImage.open(root_path + file[1])
index = image.mode.find('L')
image.close()
self.assertTrue(index == 0)
def test_convert(self):
file = files_paths[0][0]
image = Image(root_path + file)
basename = file[0:file.find('.')]
basename = root_path + '/temp' + basename + '.bmp'
image.convert(basename)
image.close()
self.assertTrue(path.isfile(basename))

View File

@@ -0,0 +1,38 @@
import unittest
from os import path
from manga_py import fs
from manga_py.provider import Provider
from manga_py.providers import get_provider
root_path = path.dirname(path.realpath(__file__))
class TestInitProvider(unittest.TestCase):
# success
def test_get_provider1(self):
provider = get_provider('http://readmanga.me/manga/name/here')
self.assertIsInstance(provider(), Provider)
# failed
def test_get_provider2(self):
provider = get_provider('http://example.org/manga/name/here')
self.assertFalse(provider)
def test_root_path(self):
self.assertEqual(path.realpath(fs.path_join(root_path, '..')), fs.root_path())
def test_file_name_query_remove1(self):
name = '/addr/to/filename'
self.assertEqual(
name,
fs.remove_file_query_params(name + '?query=params').replace('\\', '/') # windows os patch
)
def test_file_name_query_remove2(self):
name = '/addr/to/filename/'
self.assertEqual(
name + 'image.png',
fs.remove_file_query_params(name + '?query=params').replace('\\', '/') # windows os patch
)

View File

@@ -0,0 +1,211 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import json
import math
import operator
import unittest
from functools import reduce
from os import path
from PIL import Image as PilImage, ImageChops
from manga_py.crypt import sunday_webry_com
from manga_py.crypt.puzzle import Puzzle
from manga_py.crypt import mangago_me
from manga_py.crypt import viz_com
root_path = path.dirname(path.realpath(__file__))
class TestMatrix(unittest.TestCase):
@staticmethod
def _rmsdiff(im1, im2):
"""Calculate the root-mean-square difference between two images"""
h = ImageChops.difference(im1, im2).histogram()
# calculate rms
return math.sqrt(
reduce(
operator.add,
map(lambda h, i: h * (i ** 2), h, range(256))
) / (float(im1.size[0]) * im1.size[1])
)
def test_jpg(self):
file_src = root_path + '/mosaic/tonarinoyj_jp_orig.jpg' # tonarinoyj.jp image
file_ref = root_path + '/mosaic/tonarinoyj_jp_reference.jpg'
file_dst = root_path + '/temp/tonarinoyj_jp_mosaic.jpg'
div_num = 4
matrix = {}
for i in range(div_num * div_num):
matrix[i] = (i % div_num) * div_num + int(i / div_num)
p = Puzzle(div_num, div_num, matrix, 8)
p.need_copy_orig = True
p.de_scramble(file_src, file_dst)
src = PilImage.open(file_dst)
ref = PilImage.open(file_ref)
deviation = self._rmsdiff(src, ref)
src.close()
ref.close()
self.assertTrue(deviation < 10)
def test_png(self):
file_src = root_path + '/mosaic/tonarinoyj_jp_orig.png' # tonarinoyj.jp image
file_ref = root_path + '/mosaic/tonarinoyj_jp_reference.png'
file_dst = root_path + '/temp/tonarinoyj_jp_mosaic.png'
div_num = 4
matrix = {}
for i in range(div_num * div_num):
matrix[i] = (i % div_num) * div_num + int(i / div_num)
p = Puzzle(div_num, div_num, matrix, 8)
p.need_copy_orig = True
p.de_scramble(file_src, file_dst)
src = PilImage.open(file_dst)
ref = PilImage.open(file_ref)
deviation = self._rmsdiff(src, ref)
src.close()
ref.close()
self.assertTrue(deviation < 10)
def test_sunday_webry_com(self):
decoder = sunday_webry_com.SundayWebryCom()
with open(root_path + '/mosaic/sunday_reference_matrix.json') as f:
result = json.loads(f.read())
n = 0
for _i, _r in enumerate(result):
result_py = decoder.solve(848, 1200, 64, 64, _i + 1)
for i, r in enumerate(_r):
p = result_py[i]
if (
r['srcX'] != p['srcX'] or
r['srcY'] != p['srcY'] or
r['destX'] != p['destX'] or
r['destY'] != p['destY'] or
r['width'] != p['width'] or
r['height'] != p['height']
):
n += 1
self.assertTrue(n < 1)
def test_solve_sunday_webry_com(self):
decoder = sunday_webry_com.SundayWebryCom()
puzzle = sunday_webry_com.MatrixSunday()
src = root_path + '/mosaic/sunday_orig.jpg'
file_dst = root_path + '/temp/sunday_mosaic2.jpg'
file_ref = root_path + '/mosaic/sunday_reference.jpg'
result_py2 = decoder.solve_by_img(src, 64, 64, 2)
puzzle.de_scramble(src, file_dst, result_py2)
src = PilImage.open(file_dst)
ref = PilImage.open(file_ref)
deviation = self._rmsdiff(src, ref)
self.assertTrue(deviation < 10)
def test_solve_plus_comico_js(self):
src = root_path + '/mosaic/plus_comico_jp_orig.jpg'
file_dst = root_path + '/temp/plus_comico_jp_mosaic.jpg'
file_ref = root_path + '/mosaic/plus_comico_jp_reference.jpg'
_matrix = '3,14,5,8,10,12,4,2,1,6,15,13,7,11,0,9'.split(',')
div_num = 4
matrix = {}
n = 0
for i in _matrix:
matrix[int(i)] = n
n += 1
p = Puzzle(div_num, div_num, matrix, 8)
p.need_copy_orig = True
p.de_scramble(src, file_dst)
src = PilImage.open(file_dst)
ref = PilImage.open(file_ref)
deviation = self._rmsdiff(src, ref)
src.close()
ref.close()
self.assertTrue(deviation < 10)
def test_solve_mangago(self):
urls = [
(
'mangago1_orig.jpeg',
'mangago1_reference.jpeg',
'http://iweb7.mangapicgallery.com/r/cspiclink/make_me_bark/418858/962c5915bbe6f4ab0903149b5d94baba796a5cf059389458858fdeb74ddc02a4.jpeg'
),
(
'mangago2_orig.jpeg',
'mangago2_reference.jpeg',
'http://iweb7.mangapicgallery.com/r/cspiclink/make_me_bark/418858/53e50ae9291f4ab0903149b5d94baba796a5cf059383846d7d1f4dc72e9f75f9.jpeg'
),
(
'mangago3_orig.jpeg',
'mangago3_reference.jpeg',
'http://iweb7.mangapicgallery.com/r/cspiclink/make_me_bark/418859/c56e8e1f5baf770212313f5e9532ec5e6103b61e956e06496929048f98e33004.jpeg'
),
(
'mangago4_orig.jpeg',
'mangago4_reference.jpeg',
'http://iweb7.mangapicgallery.com/r/cspiclink/make_me_bark/418859/5af9065f5b2e2169a4bfd805e9aa21d3112d498d68c6caa9046af4b06a723170.jpeg'
),
(
'mangago5_orig.jpeg',
'mangago5_reference.jpeg',
'http://iweb7.mangapicgallery.com/r/cspiclink/make_me_bark/418859/34f05a15df5ae2169a4bfd805e9aa21d3112d498d68c765523c20c307fa0fda2.jpeg'
),
(
'mangago6_orig.jpeg',
'mangago6_reference.jpeg',
'http://iweb7.mangapicgallery.com/r/cspiclink/make_me_bark/418864/0d76361a3cf5baf770212313f5e9532ec5e6103b616618337cb81b6acf9c1912.jpeg'
),
(
'mangago7_orig.jpeg',
'mangago7_reference.jpeg',
'http://iweb7.mangapicgallery.com/r/cspiclink/lookism/443703/dbdf873a11bafad56c41ff7fbed622aa76e19f3564e5d52a6688d6d9e3c57fb2.jpeg'
),
]
for i in urls:
img = path.join(root_path, 'mosaic', i[0])
dst = path.join(root_path, 'temp', i[0])
ref = path.join(root_path, 'mosaic', i[1])
mangago_me.MangaGoMe.puzzle(img, dst, i[2])
# compare
src = PilImage.open(ref)
ref = PilImage.open(dst)
deviation = self._rmsdiff(src, ref)
src.close()
ref.close()
self.assertTrue(deviation < 10)
def test_solve_viz_com(self):
for i in range(7):
src_path = root_path + '/mosaic/viz/index{}.jfif'.format(i)
ref_path = root_path + '/temp/canvas{}.png'.format(i)
solved_path = root_path + '/mosaic/viz/canvas{}.png'.format(i)
ref = viz_com.solve(src_path, {'width': 800, 'height': 1200})
ref.save(ref_path)
solved = PilImage.open(solved_path)
deviation = self._rmsdiff(solved, ref)
solved.close()
self.assertTrue(deviation < 10)

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 357 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 514 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 413 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 494 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 409 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 419 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 467 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 KiB

View File

@@ -0,0 +1,76 @@
import unittest
from .base import root_path
from manga_py.fs import path_join
from manga_py.providers.helpers.std import Std
from manga_py.provider import Provider
class M(Std, Provider):
def get_main_content(self):
return self._get_content('{}/{}')
def get_manga_name(self) -> str:
return self._get_name(r'\.\w+/([^/]+)\?')
def get_chapters(self) -> list:
return self._elements('a')
def get_files(self) -> list:
parser = self.document_fromstring(self.content)
return self._images_helper(parser, 'a', 'href')
def get_archive_name(self) -> str:
return 'archive'
def get_chapter_index(self) -> str:
return '0'
class TestStd(unittest.TestCase):
@property
def _provider(self):
provider = M()
provider._params['url'] = 'https://www.google.com/imghp?hl=&tab=wi'
return provider
def test_base(self):
provider = self._provider
self.assertTrue(provider.get_manga_name() == provider.manga_name)
self.assertNotIn('manga_name', provider._storage)
provider._storage['manga_name'] = provider.get_manga_name() + '-name'
self.assertFalse(provider.get_manga_name() == provider.manga_name)
self.assertTrue(~provider.manga_name.find('imghp'))
provider._storage['manga_name'] = provider.get_manga_name()
self.assertTrue(len(provider.content) > 100)
def test_cookies(self):
provider = self._provider
provider._base_cookies(provider.get_url())
self.assertTrue(len(provider._storage['cookies'].keys()) > 0)
def test_normal_name(self):
name = self._provider.normal_arc_name(['1', '2'])
self.assertEqual('vol_001-2', name)
def test_iterators(self):
provider = self._provider
provider._storage['manga_name'] = provider.manga_name
self.assertTrue(len(provider.get_chapters()) > 0)
self.assertTrue(~provider.get_files()[0].find('.google.'))
def test_cover_from_content(self):
self.content = '<html>'
src = self._provider._cover_from_content('img')
self.assertEqual('http', src[:4])
def test_first_select(self):
provider = self._provider
with open(path_join(root_path, 'files', 'select.html'), 'r') as f:
provider._storage['main_content'] = f.read()
reference = len(provider._elements('select')[0].cssselect('option'))
parser = provider.document_fromstring(provider.content)
skip = len(provider._first_select_options(parser, 'select'))
not_exists = len(provider._first_select_options(parser, 'select#not_exists_selector'))
self.assertTrue(reference == (skip + 1))
self.assertTrue(not_exists == 0)

View File

@@ -0,0 +1,22 @@
import unittest
from pyvirtualdisplay import Display
from selenium.common.exceptions import NoSuchElementException
from manga_py.base_classes import WebDriver
class TestWebDriver(unittest.TestCase):
def test_driver(self):
display = Display(visible=0, size=(800, 600))
display.start()
driver = WebDriver().get_driver()
driver.get('https://ya.ru')
result = True
try:
driver.find_element_by_id('text')
except NoSuchElementException:
result = False
driver.close()
display.stop()
self.assertTrue(result)