From c5da2c2738a5868e8ee2234af5559a772afb3dd2 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Tue, 5 Sep 2023 07:54:51 +0200 Subject: [PATCH 01/14] Update for tox >= 4. --- .github/workflows/tests.yml | 6 +++--- tox.ini | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4f407cf..3f4f64b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,7 +27,7 @@ jobs: - headless # - head # disabled because it needs xvfb which is not so easy to set up on GHA - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest name: ${{ matrix.config[1] }}-${{ matrix.browser }}-${{ matrix.state }} steps: - uses: actions/checkout@v2 @@ -36,7 +36,7 @@ jobs: with: python-version: ${{ matrix.config[0] }} - name: Pip cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('setup.*', 'tox.ini') }} @@ -45,7 +45,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install 'tox < 4' tox-factor + pip install tox - name: Install dependencies (firefox) if: matrix.browser == 'ff' run: | diff --git a/tox.ini b/tox.ini index f2c48ef..e410c11 100644 --- a/tox.ini +++ b/tox.ini @@ -4,10 +4,12 @@ envlist = py{37,38,39}-{wsgi,plonetesting,grok}-{chrome,ff,edge}-headless py38-wsgi-{chrome,ff,edge}-head coverage-report -minversion = 3.7 +minversion = 4.0 [testenv] -passenv = DISPLAY GOCEPT_* +passenv = + DISPLAY + GOCEPT_* usedevelop = true setenv = COVERAGE_FILE=.coverage.{envname} From a7f5fb72389591f0fa6809c84d6ee4cee1f97134 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Tue, 5 Sep 2023 07:59:56 +0200 Subject: [PATCH 02/14] Fix pkg_ressources deprecation warnings. --- setup.py | 1 + src/gocept/selenium/screenshot.py | 6 +++--- src/gocept/selenium/tests/test_wd_selenese.py | 11 +++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index 64ddb3e..846d934 100644 --- a/setup.py +++ b/setup.py @@ -5,6 +5,7 @@ install_requires = [ 'gocept.httpserverlayer >= 3', 'httpagentparser', + 'importlib-resources', 'plone.testing >= 7.0', 'selenium >= 4', 'Pillow', diff --git a/src/gocept/selenium/screenshot.py b/src/gocept/selenium/screenshot.py index cf05b4c..a075eb9 100644 --- a/src/gocept/selenium/screenshot.py +++ b/src/gocept/selenium/screenshot.py @@ -1,10 +1,10 @@ from PIL import Image from PIL import ImageChops +import importlib_resources import inspect import itertools import math import os -import pkg_resources import tempfile @@ -13,7 +13,7 @@ def get_path(resource): - return pkg_resources.resource_filename('gocept.selenium', resource) + return importlib_resources.files('gocept.selenium') / resource WHITE = (255, 255, 255, 0) @@ -215,7 +215,7 @@ def _screenshot_path(screenshot_directory): if screenshot_directory == '.': screenshot_directory = \ inspect.currentframe().f_back.f_back.f_back.f_globals['__name__'] - return pkg_resources.resource_filename(screenshot_directory, '') + return importlib_resources.files(screenshot_directory) def save_screenshot_temporary(screenshot): diff --git a/src/gocept/selenium/tests/test_wd_selenese.py b/src/gocept/selenium/tests/test_wd_selenese.py index bc22866..9f0bd46 100644 --- a/src/gocept/selenium/tests/test_wd_selenese.py +++ b/src/gocept/selenium/tests/test_wd_selenese.py @@ -26,10 +26,10 @@ from selenium.webdriver.common.by import By from unittest import mock import gocept.httpserverlayer.static +import gocept.selenium import gocept.testing.assertion +import importlib_resources import os.path -import pathlib -import pkg_resources import pytest import shutil import stat @@ -98,8 +98,7 @@ class HTMLTestCase(gocept.selenium.webdriver.WebdriverSeleneseTestCase, def setUp(self): super().setUp() - directory = pathlib.Path(pkg_resources.resource_filename( - 'gocept.selenium.tests.fixture', '')) + directory = importlib_resources.files('gocept.selenium.tests.fixture') for glob in ('*.html', '*.pdf'): for name in directory.glob(glob): shutil.copy(directory / name, self.layer['documentroot']) @@ -373,7 +372,7 @@ class ScreenshotDirectorySettingTest(HTMLTestCase): def test_default_setting_when_not_set(self): # the default is the directory where the current test is - img = pkg_resources.resource_filename(self.__module__, 'foo.png') + img = str(importlib_resources.files(self.__module__) / 'foo.png') self.selenium.capture_screenshot = True self.selenium.open('screenshot.html') with self.assertRaisesRegex(ValueError, img): @@ -384,7 +383,7 @@ def test_default_setting_when_not_set(self): def test_screenshot_directory_setting_resolves_dotted_name(self): directory = 'gocept.selenium.tests.screenshot_directory' self.selenium.screenshot_directory = directory - img = pkg_resources.resource_filename(directory, 'foo.png') + img = str(importlib_resources.files(directory) / 'foo.png') self.selenium.capture_screenshot = True self.selenium.open('screenshot.html') with self.assertRaisesRegex(ValueError, img): From 32be707edbbcb30087d46c3242ed5132cd84a1be Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Tue, 5 Sep 2023 08:00:14 +0200 Subject: [PATCH 03/14] Fix chrome driver args. --- src/gocept/selenium/webdriver.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gocept/selenium/webdriver.py b/src/gocept/selenium/webdriver.py index ebe560e..615ae45 100644 --- a/src/gocept/selenium/webdriver.py +++ b/src/gocept/selenium/webdriver.py @@ -147,8 +147,9 @@ def get_chrome_webdriver_args(self): return { 'options': options, - 'service_args': ['--log-path=chromedriver.log'], - 'service': ChromeService(ChromeDriverManager().install()), + 'service': ChromeService( + ChromeDriverManager().install(), + service_args=['--log-path=chromedriver.log']), } def _start_selenium(self): From 591062f502a2d3f140a20fa555a7882eab592c09 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Thu, 7 Sep 2023 07:57:17 +0200 Subject: [PATCH 04/14] Fix firefox deprecation warning. --- src/gocept/selenium/webdriver.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gocept/selenium/webdriver.py b/src/gocept/selenium/webdriver.py index 615ae45..09ea69c 100644 --- a/src/gocept/selenium/webdriver.py +++ b/src/gocept/selenium/webdriver.py @@ -109,8 +109,11 @@ def get_firefox_webdriver_args(self): "browser.helperApps.neverAsk.saveToDisk", "application/pdf") options.set_preference("pdfjs.disabled", True) - return {'options': options, - 'service': FirefoxService(GeckoDriverManager().install())} + return { + 'options': options, + 'service': FirefoxService( + GeckoDriverManager().install(), + log_output=open("geckodriver.log", "a+", encoding="utf-8"))} def get_edge_webdriver_args(self): options = selenium.webdriver.edge.options.Options() From 637915d6355b61c33cf2699696650f95f3d75d8f Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Wed, 13 Sep 2023 07:52:25 +0200 Subject: [PATCH 05/14] Ignore some DeprecationWarnings coming from upstream packages. --- pytest.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pytest.ini b/pytest.ini index 834dfcc..192a019 100644 --- a/pytest.ini +++ b/pytest.ini @@ -4,3 +4,5 @@ python_files = test[s|_]*.py filterwarnings = error ignore::pytest.PytestUnraisableExceptionWarning + ignore:pkg_resources is deprecated as an API:DeprecationWarning + ignore:Deprecated call to `pkg_resources.declare_namespace.*:DeprecationWarning From 702e2334de4b0768a97ba5fe48a33d4f3850ca81 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Wed, 13 Sep 2023 07:53:58 +0200 Subject: [PATCH 06/14] Fix a pre-commit warning. --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2b90b34..053c5f2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,7 +36,7 @@ repos: - id: rst name: rst entry: rst-lint --encoding utf-8 - exclude: ./doc/* + exclude: ./doc/.* # We have Sphinx directives in the docs. This cannot be validated # here. We therefore include two rst-linter. They complement each # other. This regex matches all *.rst not in the doc/ folder. From 635d45d9faadba612d4dc009608f06a10d22dd62 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Thu, 14 Sep 2023 08:02:45 +0200 Subject: [PATCH 07/14] Allow higher rate limit. --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index e410c11..1f07326 100644 --- a/tox.ini +++ b/tox.ini @@ -10,6 +10,7 @@ minversion = 4.0 passenv = DISPLAY GOCEPT_* + GH_TOKEN usedevelop = true setenv = COVERAGE_FILE=.coverage.{envname} From fa7936484c734847783a23b88cbc680be8ac13b4 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Thu, 14 Sep 2023 08:08:09 +0200 Subject: [PATCH 08/14] The screenshots of edge are currently broken: the results do not show what was on the screen. --- .../selenium/tests/fixture/screenshot-edge.png | Bin 397 -> 413 bytes .../tests/fixture/screenshot_threshold_edge.png | Bin 0 -> 693 bytes src/gocept/selenium/tests/test_wd_selenese.py | 13 ++++++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/gocept/selenium/tests/fixture/screenshot_threshold_edge.png diff --git a/src/gocept/selenium/tests/fixture/screenshot-edge.png b/src/gocept/selenium/tests/fixture/screenshot-edge.png index b6b4148abb8650832f7f17d99c56918e2b3b2685..0a060740729db18b7b47083758824d0c73a392b6 100644 GIT binary patch delta 386 zcmV-|0e$|B1DykqB!4++LqkwWLqi}?a&Km7Y-Iodc$|HZy-UMT6i1JxAbw3MIyhw0 zMQy8XDd=E7EP^<+3awk3h9b5#q!FDJH~$D{T|0`iyWphYA~-k*f@}Sy8B&mXANSqE z$tCaI2a$Oc(HOMao?9wrjY{><7=2?zs~@J-aTp%z`gsm|pMRGB=^GYfb-QD!eknay zhwGPh@k}G&bDwJgU;BLKIiC2&XLrAp6L-Z+jRCF=u;sXZ|BHB|)jYMrdoyXb56Y?) zG(AS*6S|N0_1lX>#OA64Rb$owz7TLbgDLEGfCX_KZxLHPt*@@-eo_`0p7U zdGQLH)n2c6AA7ppJ?MVG_-E)A?_lZy95jzXtvl`_Vrr%-WQg+V& zJY-hm&#VSJw6RzbC3NRFsb7qaPTfep1#kcW03S(2K~#90WBmXB|9=J|0248aMy^5@ gLJHoPsE}qN0H?+UR?y)27XSbN07*qoM6N<$f;S+sI{*Lx delta 370 zcmV-&0ge8h1C0ZaB!4hzLqkwWLqi}?a&Km7Y-Iodc$|HaJxjw-6owy*i`YT%b8yJe z!Nrf(+D33{Yl>^DP~Flr6tRsVjVP|JPOe>?MO+1cft!QiCabXJMYdFN*p)k)7v!cdJJ4+Pm#HNGv!4OyQd@r{ zTJZ+%Utr-O(Q7iw=|_0#hi>E!q)GEgehI$kRl9@PPnf=vx@gMDx5-U) zc&v$XZ0PibU%d@U;2iKnvH$=87)eAyRCt_Yyk#Z)pMeO#M2wWn zsF+hbVXyb$01@~8r3!VvT2>Y*mtAvL=W4!4u-9p_*uu3odRCj#Hq#}7b4AVnbEL;w zcWvJNV95g|3k!~>?7vGTgC=P?RE=p{0ql1P32P@M;hmjMWwoLoZEq3_8T=;|a*jC#rUSM)$ N@O1TaS?83{1OQav@9h8p literal 0 HcmV?d00001 diff --git a/src/gocept/selenium/tests/test_wd_selenese.py b/src/gocept/selenium/tests/test_wd_selenese.py index 9f0bd46..71b3185 100644 --- a/src/gocept/selenium/tests/test_wd_selenese.py +++ b/src/gocept/selenium/tests/test_wd_selenese.py @@ -292,18 +292,29 @@ def test_successful_comparison_chrome(self): def test_successful_comparison_edge(self): self.selenium.open('screenshot.html') self.selenium.assertScreenshot( - 'screenshot-edge', 'css=#block-1', threshold=14) + 'screenshot-edge', 'css=#block-1', threshold=5) def test_raises_exception_if_image_sizes_differ(self): self.selenium.open('screenshot.html') with self.assertRaises(ScreenshotSizeMismatchError): self.selenium.assertScreenshot('screenshot', 'css=#block-2') + @pytest.mark.skipif( + os.environ.get('GOCEPT_WEBDRIVER_BROWSER').lower() == 'edge', + reason='Screenshots of Edge are currently broken.') def test_does_not_fail_if_threshold_greater_than_distance(self): self.selenium.open('screenshot_threshold.html') self.selenium.assertScreenshot( 'screenshot_threshold', 'css=#block-2', threshold=12) + @pytest.mark.skipif( + os.environ.get('GOCEPT_WEBDRIVER_BROWSER').lower() != 'edge', + reason='Test the broken screenshots of Edge.') + def test_does_not_fail_if_threshold_greater_than_distance_edge(self): + self.selenium.open('screenshot_threshold.html') + self.selenium.assertScreenshot( + 'screenshot_threshold_edge', 'css=#block-2', threshold=12) + def test_does_fail_if_threshold_less_than_distance(self): self.selenium.open('screenshot_threshold.html') with self.assertRaises(ScreenshotMismatchError): From fa74a643ba86bfdf67a83b37d388483df9cce223 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Fri, 15 Sep 2023 07:53:45 +0200 Subject: [PATCH 09/14] Try to circumvent GH rate limit. --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3f4f64b..af2013a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,6 +9,9 @@ on: # Allow to run this workflow manually from the Actions tab workflow_dispatch: +env: + GH_TOKEN: ${{ vars.GH_TOKEN }} + jobs: build: strategy: From 36ec9c726dacd27fa3f20948cf72ecb6bccdeae8 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Fri, 15 Sep 2023 07:59:54 +0200 Subject: [PATCH 10/14] Move token to secrets. --- .github/workflows/tests.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index af2013a..f063edd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,9 +9,6 @@ on: # Allow to run this workflow manually from the Actions tab workflow_dispatch: -env: - GH_TOKEN: ${{ vars.GH_TOKEN }} - jobs: build: strategy: @@ -64,6 +61,8 @@ jobs: sudo apt update sudo apt install microsoft-edge-stable - name: Test + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} run: | tox -f ${{ matrix.config[1] }}-${{ matrix.browser }}-${{ matrix.state }} - name: Report to coveralls From eff8bfa3d0c6be34c5604d28c3b80bc8d075e879 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Mon, 18 Sep 2023 06:58:56 +0200 Subject: [PATCH 11/14] Hopefully circumvent rate limit problems. --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f063edd..eec4d5d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,6 +13,7 @@ jobs: build: strategy: fail-fast: false + max-parallel: 1 matrix: config: # [Python version, tox env] From 154b06abd729a1855d1805830f3d6f51664c9253 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Wed, 27 Sep 2023 07:58:10 +0200 Subject: [PATCH 12/14] Add support for Python 3.10, 3.11 + drop testing Firefox and Edge. --- .github/workflows/tests.yml | 8 ++++---- CHANGES.rst | 8 +++++++- tox.ini | 8 ++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index eec4d5d..0f00dcb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,10 +20,12 @@ jobs: - ["3.7", "py37"] - ["3.8", "py38"] - ["3.9", "py39"] + - ["3.10", "py310"] + - ["3.11", "py311"] browser: - - ff + # - ff # unability to solve `API rate limit exceeded` problems - chrome - - edge + # - edge # Edge version and driver version do not match state: - headless # - head # disabled because it needs xvfb which is not so easy to set up on GHA @@ -62,8 +64,6 @@ jobs: sudo apt update sudo apt install microsoft-edge-stable - name: Test - env: - GH_TOKEN: ${{ secrets.GH_TOKEN }} run: | tox -f ${{ matrix.config[1] }}-${{ matrix.browser }}-${{ matrix.state }} - name: Report to coveralls diff --git a/CHANGES.rst b/CHANGES.rst index da4d902..40eca1a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,13 @@ Changelog 7.2 (unreleased) ---------------- -- Nothing changed yet. +- Add support for Python 3.10, 3.11. + +- Drop testing against ``Firefox`` in GitHub Actions: I was unable to solve the + *API rate limit exceeded* problem. + +- Drop testing against ``Edge`` in GitHub Actions: It says that the driver does + not match the Edge version. 7.1 (2022-06-30) diff --git a/tox.ini b/tox.ini index 1f07326..3bc71ae 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,8 @@ [tox] # Please update in the environment `testenv:coverage-report` as well. envlist = - py{37,38,39}-{wsgi,plonetesting,grok}-{chrome,ff,edge}-headless - py38-wsgi-{chrome,ff,edge}-head + py{37,38,39,310,311}-{wsgi,plonetesting,grok}-{chrome,ff,edge}-headless + py39-wsgi-{chrome,ff,edge}-head coverage-report minversion = 4.0 @@ -56,8 +56,8 @@ commands = basepython = python3 deps = coverage depends = - py{37,38,39}-{wsgi,plonetesting,grok}-{chrome,ff}-headless - py38-{wsgi,plonetesting,grok}-{chrome,ff,edge}-head + py{37,38,39,310,311}-{wsgi,plonetesting,grok}-{chrome,ff}-headless + py39-{wsgi,plonetesting,grok}-{chrome,ff,edge}-head setenv = COVERAGE_FILE=.coverage skip_install = true From 5053fb610684035e4922d567cc6691516241d2e6 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Wed, 27 Sep 2023 07:59:45 +0200 Subject: [PATCH 13/14] No need to serialize the tests. --- .github/workflows/tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0f00dcb..9d51569 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,7 +13,6 @@ jobs: build: strategy: fail-fast: false - max-parallel: 1 matrix: config: # [Python version, tox env] From 160b4b415d7a395c3862c376393b23e071db7687 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Thu, 28 Sep 2023 07:53:21 +0200 Subject: [PATCH 14/14] Silence deprecation warnings in Python 3.11 --- pytest.ini | 2 ++ src/gocept/selenium/plonetesting/tests/zope2/test_zope2.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pytest.ini b/pytest.ini index 192a019..52fa281 100644 --- a/pytest.ini +++ b/pytest.ini @@ -6,3 +6,5 @@ filterwarnings = ignore::pytest.PytestUnraisableExceptionWarning ignore:pkg_resources is deprecated as an API:DeprecationWarning ignore:Deprecated call to `pkg_resources.declare_namespace.*:DeprecationWarning + ignore:'crypt' is deprecated and slated for removal in Python 3.13:DeprecationWarning + ignore:'cgi' is deprecated and slated for removal in Python 3.13:DeprecationWarning diff --git a/src/gocept/selenium/plonetesting/tests/zope2/test_zope2.py b/src/gocept/selenium/plonetesting/tests/zope2/test_zope2.py index 935501a..25773ad 100644 --- a/src/gocept/selenium/plonetesting/tests/zope2/test_zope2.py +++ b/src/gocept/selenium/plonetesting/tests/zope2/test_zope2.py @@ -26,4 +26,4 @@ class Zope2Tests(gocept.selenium.tests.isolation.IsolationTests, def test_suite(): - return unittest.makeSuite(Zope2Tests) + return unittest.defaultTestLoader.loadTestsFromTestCase(Zope2Tests)