From 6877c81025954f61f703d73259faf704ea177196 Mon Sep 17 00:00:00 2001 From: Ashley Whetter Date: Sun, 1 Sep 2024 18:21:13 -0700 Subject: [PATCH] Tests pass when ssl module is not included in the Python distribution --- tests/python/pystdlib/stdlib/json.py | 9 +++++++ .../pystdlib/stdlib/{myssl.py => myjson.py} | 4 +-- tests/python/pystdlib/stdlib/ssl.py | 9 ------- tests/python/test_pyintegration.py | 26 +++++++++---------- 4 files changed, 24 insertions(+), 24 deletions(-) create mode 100644 tests/python/pystdlib/stdlib/json.py rename tests/python/pystdlib/stdlib/{myssl.py => myjson.py} (64%) delete mode 100644 tests/python/pystdlib/stdlib/ssl.py diff --git a/tests/python/pystdlib/stdlib/json.py b/tests/python/pystdlib/stdlib/json.py new file mode 100644 index 00000000..02742d60 --- /dev/null +++ b/tests/python/pystdlib/stdlib/json.py @@ -0,0 +1,9 @@ +"""json is the same name as a stdlib module.""" + + +class JSONDecoder: + """Do things with json.""" + + def decode(self, s): + """Decode a string.""" + return s diff --git a/tests/python/pystdlib/stdlib/myssl.py b/tests/python/pystdlib/stdlib/myjson.py similarity index 64% rename from tests/python/pystdlib/stdlib/myssl.py rename to tests/python/pystdlib/stdlib/myjson.py index a3d41179..7e53715e 100644 --- a/tests/python/pystdlib/stdlib/myssl.py +++ b/tests/python/pystdlib/stdlib/myjson.py @@ -1,9 +1,9 @@ """This is a docstring.""" -from ssl import SSLContext +from json import JSONDecoder -class MySSLContext(SSLContext): +class MyJSONDecoder(JSONDecoder): """This is a class.""" def my_method(self): diff --git a/tests/python/pystdlib/stdlib/ssl.py b/tests/python/pystdlib/stdlib/ssl.py deleted file mode 100644 index dfb311e7..00000000 --- a/tests/python/pystdlib/stdlib/ssl.py +++ /dev/null @@ -1,9 +0,0 @@ -"""ssl is the same name as a stdlib module.""" - - -class SSLContext: - """Do things with ssl.""" - - def wrap_socket(self, sock): - """Wrap a socket.""" - return sock diff --git a/tests/python/test_pyintegration.py b/tests/python/test_pyintegration.py index 0bda9ffa..dddfbe49 100644 --- a/tests/python/test_pyintegration.py +++ b/tests/python/test_pyintegration.py @@ -1252,30 +1252,30 @@ def built(self, builder): builder("pystdlib") def test_integration(self, parse): - ssl_file = parse("_build/html/autoapi/ssl/index.html") + json_file = parse("_build/html/autoapi/json/index.html") - ssl_mod = ssl_file.find(id="ssl") - assert "ssl is the same name" in ssl_mod.parent.text + json_mod = json_file.find(id="json") + assert "json is the same name" in json_mod.parent.text - assert ssl_file.find(id="ssl.SSLContext") - wrap_socket = ssl_file.find(id="ssl.SSLContext.wrap_socket") - assert wrap_socket - wrap_docstring = wrap_socket.parent.find("dd").text.strip() - assert wrap_docstring == "Wrap a socket." + assert json_file.find(id="json.JSONDecoder") + decode = json_file.find(id="json.JSONDecoder.decode") + assert decode + wrap_docstring = decode.parent.find("dd").text.strip() + assert wrap_docstring == "Decode a string." - myssl_file = parse("_build/html/autoapi/myssl/index.html") + myjson_file = parse("_build/html/autoapi/myjson/index.html") # Find members that are not inherited from local standard library classes. - ctx = myssl_file.find(id="myssl.MySSLContext") + ctx = myjson_file.find(id="myjson.MyJSONDecoder") assert ctx - meth = myssl_file.find(id="myssl.MySSLContext.my_method") + meth = myjson_file.find(id="myjson.MyJSONDecoder.my_method") assert meth meth_docstring = meth.parent.find("dd").text.strip() assert meth_docstring == "This is a method." # Find members that are inherited from local standard library classes. - wrap_socket = myssl_file.find(id="myssl.MySSLContext.wrap_socket") - assert not wrap_socket + decode = myjson_file.find(id="myjson.MyJSONDecoder.decode") + assert decode myast_file = parse("_build/html/autoapi/myast/index.html")