playwright wrapper (#28)
This commit is contained in:
parent
365daad4f5
commit
c53f744097
|
@ -60,3 +60,20 @@ jython-core:
|
||||||
- export PATH="$HOME/jython/bin:$PATH"
|
- export PATH="$HOME/jython/bin:$PATH"
|
||||||
script:
|
script:
|
||||||
- ./devscripts/run_tests.sh
|
- ./devscripts/run_tests.sh
|
||||||
|
|
||||||
|
# uncomment once the images are available
|
||||||
|
# https://github.com/microsoft/playwright-python/issues/338
|
||||||
|
# playwright-tests-core:
|
||||||
|
# image: mcr.microsoft.com/playwright-python:focal
|
||||||
|
# variables:
|
||||||
|
# HDL_TEST_SET: core
|
||||||
|
# script:
|
||||||
|
# - ./devscripts/run_tests.sh
|
||||||
|
|
||||||
|
# playwright-tests-download:
|
||||||
|
# image: mcr.microsoft.com/playwright-python:focal
|
||||||
|
# variables:
|
||||||
|
# HDL_TEST_SET: download
|
||||||
|
# HDL_TEST_PLAYWRIGHT_DOWNLOAD: 1
|
||||||
|
# script:
|
||||||
|
# - ./devscripts/run_tests.sh
|
||||||
|
|
|
@ -12,6 +12,9 @@ case "$HDL_TEST_SET" in
|
||||||
;;
|
;;
|
||||||
download)
|
download)
|
||||||
test_set="-I test_(?!$DOWNLOAD_TESTS).+\.py"
|
test_set="-I test_(?!$DOWNLOAD_TESTS).+\.py"
|
||||||
|
if [[ "$HDL_TEST_PLAYWRIGHT_DOWNLOAD" == "1" ]]; then
|
||||||
|
test_set="-I test_(?!download).+\.py"
|
||||||
|
fi
|
||||||
multiprocess_args="--processes=4 --process-timeout=540"
|
multiprocess_args="--processes=4 --process-timeout=540"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|
|
@ -395,6 +395,7 @@ class InfoExtractor(object):
|
||||||
_GEO_IP_BLOCKS = None
|
_GEO_IP_BLOCKS = None
|
||||||
_WORKING = True
|
_WORKING = True
|
||||||
_SELFHOSTED = False
|
_SELFHOSTED = False
|
||||||
|
_REQUIRES_PLAYWRIGHT = False
|
||||||
|
|
||||||
def __init__(self, downloader=None):
|
def __init__(self, downloader=None):
|
||||||
"""Constructor. Receives an optional downloader."""
|
"""Constructor. Receives an optional downloader."""
|
||||||
|
|
31
haruhi_dl/playwright.py
Normal file
31
haruhi_dl/playwright.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# coding: utf-8
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from .utils import (
|
||||||
|
ExtractorError,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PlaywrightHelper():
|
||||||
|
_pw = None
|
||||||
|
_pw_version = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _real_import_pw(cls):
|
||||||
|
from playwright import sync_playwright, _repo_version
|
||||||
|
cls._pw = sync_playwright
|
||||||
|
cls._pw_version = _repo_version.version
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _import_pw(cls, fatal=True):
|
||||||
|
try:
|
||||||
|
cls._real_import_pw()
|
||||||
|
except ImportError as err:
|
||||||
|
if fatal is True:
|
||||||
|
raise ExtractorError('Playwright could not be imported: %s' % err.msg, expected=True)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _version(cls):
|
||||||
|
if not cls._pw_version:
|
||||||
|
cls._import_pw(fatal=False)
|
||||||
|
return cls._pw_version
|
|
@ -37,7 +37,10 @@ from haruhi_dl.utils import (
|
||||||
UnavailableVideoError,
|
UnavailableVideoError,
|
||||||
)
|
)
|
||||||
from haruhi_dl.extractor import get_info_extractor
|
from haruhi_dl.extractor import get_info_extractor
|
||||||
|
from haruhi_dl.playwright import PlaywrightHelper
|
||||||
|
|
||||||
|
|
||||||
|
PLAYWRIGHT_INSTALLED = PlaywrightHelper._version() is not None
|
||||||
RETRIES = 3
|
RETRIES = 3
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,6 +107,14 @@ def generator(test_case, tname):
|
||||||
print_skipping('IE marked as not _WORKING')
|
print_skipping('IE marked as not _WORKING')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if ie._REQUIRES_PLAYWRIGHT:
|
||||||
|
if not PLAYWRIGHT_INSTALLED:
|
||||||
|
print_skipping('Playwright is not installed')
|
||||||
|
return
|
||||||
|
elif os.environ.get('HDL_TEST_PLAYWRIGHT_DOWNLOAD') == '1':
|
||||||
|
print_skipping('Does not use Playwright')
|
||||||
|
return
|
||||||
|
|
||||||
for tc in test_cases:
|
for tc in test_cases:
|
||||||
info_dict = tc.get('info_dict', {})
|
info_dict = tc.get('info_dict', {})
|
||||||
if not (info_dict.get('id') and info_dict.get('ext')):
|
if not (info_dict.get('id') and info_dict.get('ext')):
|
||||||
|
|
36
test/test_playwright.py
Normal file
36
test/test_playwright.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# coding: utf-8
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
# Allow direct execution
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
|
from haruhi_dl.compat import compat_str
|
||||||
|
|
||||||
|
from haruhi_dl.playwright import PlaywrightHelper
|
||||||
|
|
||||||
|
|
||||||
|
class TestPlaywright(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_import_nonfatal(self):
|
||||||
|
PlaywrightHelper._import_pw(fatal=False)
|
||||||
|
|
||||||
|
def test_import_fatal(self):
|
||||||
|
helper = PlaywrightHelper
|
||||||
|
try:
|
||||||
|
helper._import_pw(fatal=True)
|
||||||
|
self.assertIsNotNone(helper._pw)
|
||||||
|
self.assertIsInstance(helper._pw_version, compat_str)
|
||||||
|
except ImportError:
|
||||||
|
self.assertIsNone(helper._pw)
|
||||||
|
self.assertIsNone(helper._pw_version)
|
||||||
|
|
||||||
|
def test_checking_version(self):
|
||||||
|
version = PlaywrightHelper._version()
|
||||||
|
self.assertIsInstance(version, (compat_str, None))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Reference in a new issue