File 0001-Remove-deprecated-sphinx-testing-dependency.patch of Package python-os-api-ref
From 06cd5abff4a05929178fb79fd7c9f09705640b13 Mon Sep 17 00:00:00 2001
From: Daniel Garcia Moreno <daniel.garcia@suse.com>
Date: Mon, 3 Oct 2022 12:08:38 +0200
Subject: [PATCH] Remove deprecated sphinx-testing dependency
This patch replaces the sphinx-testing package using the SphinxTestApp
provided by the Sphinx package.
The sphinx-testing package is deprecated and should be replaced with
the sphinx.testing package that's bundled with Sphinx.
Change-Id: I60b4d1a8b83dc35c394e29d746a2fbb3ff744c1a
---
os_api_ref/tests/base.py | 27 ++++++++++++++++++++++++++
os_api_ref/tests/test_basic_example.py | 16 +--------------
os_api_ref/tests/test_microversions.py | 5 ++---
os_api_ref/tests/test_warnings.py | 4 +---
test-requirements.txt | 1 -
5 files changed, 31 insertions(+), 22 deletions(-)
diff --git a/os_api_ref/tests/base.py b/os_api_ref/tests/base.py
index 730258f..6e5e0dc 100644
--- a/os_api_ref/tests/base.py
+++ b/os_api_ref/tests/base.py
@@ -16,8 +16,12 @@
import os
import fixtures
+import tempfile
import testtools
+from sphinx.testing.path import path
+from sphinx.testing.util import SphinxTestApp
+
def example_dir(name=""):
return os.path.join(os.path.dirname(__file__), 'examples', name)
@@ -26,6 +30,29 @@ def example_dir(name=""):
_TRUE_VALUES = ('True', 'true', '1', 'yes')
+class with_app:
+ def __init__(self, **kwargs):
+ if 'srcdir' in kwargs:
+ self.srcdir = path(kwargs['srcdir'])
+ self.sphinx_app_args = kwargs
+
+ def __call__(self, f):
+ def newf(*args, **kwargs):
+ with tempfile.TemporaryDirectory() as tmpdirname:
+ tmpdir = path(tmpdirname)
+ tmproot = tmpdir / self.srcdir.basename()
+ self.srcdir.copytree(tmproot)
+ self.sphinx_app_args['srcdir'] = tmproot
+ self.builddir = tmproot.joinpath('_build')
+
+ app = SphinxTestApp(freshenv=True, **self.sphinx_app_args)
+
+ f(*args, app, app._status, app._warning, **kwargs)
+
+ app.cleanup()
+ return newf
+
+
class OutputStreamCapture(fixtures.Fixture):
"""Capture output streams during tests.
diff --git a/os_api_ref/tests/test_basic_example.py b/os_api_ref/tests/test_basic_example.py
index 4a82a6a..83e2892 100644
--- a/os_api_ref/tests/test_basic_example.py
+++ b/os_api_ref/tests/test_basic_example.py
@@ -18,23 +18,10 @@ Tests for `os_api_ref` module.
"""
from bs4 import BeautifulSoup
-import sphinx
-from sphinx_testing import with_app
from os_api_ref.tests import base
-# FIXME(stephenfin): This is horrible. We're monkeypatching this to work around
-# the fact that Sphinx 1.8+ started called 'abspath' from within the
-# 'sphinx.application.Application' class [1]. This means our careful use of
-# 'sphinx_testing.path.path' for 'Application.outdir' etc. gets stomped on.
-# We're correcting that but we're doing so globally because mock doesn't work
-# for some reason and this is bound to have some side effects
-#
-# [1] https://github.com/sphinx-doc/sphinx/commit/3a85b3502f
-sphinx.application.abspath = lambda x: x
-
-
class TestBasicExample(base.TestCase):
"""Test basic rendering.
@@ -42,8 +29,7 @@ class TestBasicExample(base.TestCase):
examples, so if someone breaks something we know.
"""
- @with_app(buildername='html', srcdir=base.example_dir('basic'),
- copy_srcdir_to_tmpdir=True)
+ @base.with_app(buildername='html', srcdir=base.example_dir('basic'))
def setUp(self, app, status, warning):
super(TestBasicExample, self).setUp()
self.app = app
diff --git a/os_api_ref/tests/test_microversions.py b/os_api_ref/tests/test_microversions.py
index 7da8c2f..8281442 100644
--- a/os_api_ref/tests/test_microversions.py
+++ b/os_api_ref/tests/test_microversions.py
@@ -18,7 +18,6 @@ Tests for `os_api_ref` module.
"""
from bs4 import BeautifulSoup
-from sphinx_testing import with_app
from os_api_ref.tests import base
@@ -30,8 +29,8 @@ class TestMicroversions(base.TestCase):
examples, so if someone breaks something we know.
"""
- @with_app(buildername='html', srcdir=base.example_dir('microversions'),
- copy_srcdir_to_tmpdir=True)
+ @base.with_app(buildername='html',
+ srcdir=base.example_dir('microversions'))
def setUp(self, app, status, warning):
super(TestMicroversions, self).setUp()
self.app = app
diff --git a/os_api_ref/tests/test_warnings.py b/os_api_ref/tests/test_warnings.py
index 0a588d2..9fa9fef 100644
--- a/os_api_ref/tests/test_warnings.py
+++ b/os_api_ref/tests/test_warnings.py
@@ -18,7 +18,6 @@ Tests for `os_api_ref` module.
"""
from bs4 import BeautifulSoup
-from sphinx_testing import with_app
from os_api_ref.tests import base
@@ -30,8 +29,7 @@ class TestWarnings(base.TestCase):
examples, so if someone breaks something we know.
"""
- @with_app(buildername='html', srcdir=base.example_dir('warnings'),
- copy_srcdir_to_tmpdir=True)
+ @base.with_app(buildername='html', srcdir=base.example_dir('warnings'))
def setUp(self, app, status, warning):
super(TestWarnings, self).setUp()
self.app = app
diff --git a/test-requirements.txt b/test-requirements.txt
index d165510..0fd36ef 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -8,7 +8,6 @@ coverage!=4.4,>=4.0 # Apache-2.0
python-subunit>=1.0.0 # Apache-2.0/BSD
testrepository>=0.0.18 # Apache-2.0/BSD
testtools>=2.2.0 # MIT
-sphinx-testing>=1.0.1 # BSD License
beautifulsoup4>=4.6.0 # MIT
stestr>=2.0.0 # Apache-2.0
pre-commit>=2.6.0 # MIT
--
2.37.3