chiark / gitweb /
documentation/python: test annotation special cases in a less hacky way.
authorVladimír Vondruš <mosra@centrum.cz>
Thu, 26 Sep 2024 17:16:50 +0000 (19:16 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Sat, 28 Sep 2024 01:44:29 +0000 (03:44 +0200)
We can just pull those into a custom module with __all__, no need to
modify directly math.__all__. This also means we don't need to worry
about the module-level docstring.

documentation/test_python/inspect_annotations/math373.html [deleted file]
documentation/test_python/inspect_builtin/inspect_builtin.html [moved from documentation/test_python/inspect_annotations/math.html with 83% similarity]
documentation/test_python/inspect_builtin/inspect_builtin.py [new file with mode: 0644]
documentation/test_python/inspect_builtin/inspect_builtin36.html [moved from documentation/test_python/inspect_annotations/math36.html with 80% similarity]
documentation/test_python/inspect_builtin/inspect_builtin39.html [moved from documentation/test_python/inspect_annotations/math39.html with 83% similarity]
documentation/test_python/test_inspect.py

diff --git a/documentation/test_python/inspect_annotations/math373.html b/documentation/test_python/inspect_annotations/math373.html
deleted file mode 100644 (file)
index 226e28e..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-  <meta charset="UTF-8" />
-  <title>math | My Python Project</title>
-  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600" />
-  <link rel="stylesheet" href="m-dark+documentation.compiled.css" />
-  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-</head>
-<body>
-<header><nav id="navigation">
-  <div class="m-container">
-    <div class="m-row">
-      <a href="index.html" id="m-navbar-brand" class="m-col-t-8 m-col-m-none m-left-m">My Python Project</a>
-    </div>
-  </div>
-</nav></header>
-<main><article>
-  <div class="m-container m-container-inflatable">
-    <div class="m-row">
-      <div class="m-col-l-10 m-push-l-1">
-        <h1>
-          math <span class="m-thin">module</span>
-        </h1>
-        <p>This module is always available.  It provides access to the
-mathematical functions defined by the C standard.</p>
-        <nav class="m-block m-default">
-          <h3>Contents</h3>
-          <ul>
-            <li>
-              Reference
-              <ul>
-                <li><a href="#functions">Functions</a></li>
-              </ul>
-            </li>
-          </ul>
-        </nav>
-        <section id="functions">
-          <h2><a href="#functions">Functions</a></h2>
-          <dl class="m-doc">
-            <dt id="pow">
-              <span class="m-doc-wrap-bumper">def <a href="#pow" class="m-doc-self">pow</a>(</span><span class="m-doc-wrap">x, y<span class="m-text m-dim">, /</span>)</span>
-            </dt>
-            <dd>Return x**y (x to the power of y).</dd>
-            <dt>
-              <span class="m-doc-wrap-bumper">def <a href="#log" class="m-doc">log</a>(</span><span class="m-doc-wrap">...)</span>
-            </dt>
-            <dd>log(x, [base=math.e])
-Return the logarithm of x to the given base.</dd>
-          </dl>
-        </section>
-        <section>
-          <h2>Function documentation</h2>
-          <section class="m-doc-details" id="log"><div>
-            <h3>
-              <span class="m-doc-wrap-bumper">def math.<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#log" class="m-doc-self">log</a>(</span><span class="m-doc-wrap">...)</span></span>
-            </h3>
-            <p>log(x, [base=math.e])
-Return the logarithm of x to the given base.</p>
-<p>If the base not specified, returns the natural logarithm (base e) of x.</p>
-          </div></section>
-        </section>
-      </div>
-    </div>
-  </div>
-</article></main>
-</body>
-</html>
similarity index 83%
rename from documentation/test_python/inspect_annotations/math.html
rename to documentation/test_python/inspect_builtin/inspect_builtin.html
index 982c3150a0c4f6df410b641893ecd3884d20a397..74a2585ce5f31d78ec0c980cf1555e188693dfc7 100644 (file)
@@ -2,7 +2,7 @@
 <html lang="en">
 <head>
   <meta charset="UTF-8" />
-  <title>math | My Python Project</title>
+  <title>inspect_builtin | My Python Project</title>
   <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600" />
   <link rel="stylesheet" href="m-dark+documentation.compiled.css" />
   <meta name="viewport" content="width=device-width, initial-scale=1.0" />
     <div class="m-row">
       <div class="m-col-l-10 m-push-l-1">
         <h1>
-          math <span class="m-thin">module</span>
+          inspect_builtin <span class="m-thin">module</span>
         </h1>
-        <p>This module provides access to the mathematical functions
-defined by the C standard.</p>
         <nav class="m-block m-default">
           <h3>Contents</h3>
           <ul>
@@ -53,7 +51,7 @@ Return the logarithm of x to the given base.</dd>
           <h2>Function documentation</h2>
           <section class="m-doc-details" id="log"><div>
             <h3>
-              <span class="m-doc-wrap-bumper">def math.<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#log" class="m-doc-self">log</a>(</span><span class="m-doc-wrap">...)</span></span>
+              <span class="m-doc-wrap-bumper">def inspect_builtin.<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#log" class="m-doc-self">log</a>(</span><span class="m-doc-wrap">...)</span></span>
             </h3>
             <p>log(x, [base=math.e])
 Return the logarithm of x to the given base.</p>
diff --git a/documentation/test_python/inspect_builtin/inspect_builtin.py b/documentation/test_python/inspect_builtin/inspect_builtin.py
new file mode 100644 (file)
index 0000000..12a6d88
--- /dev/null
@@ -0,0 +1,9 @@
+import sys
+from math import log, pow
+
+__all__ = ['pow', 'log']
+
+# Signature with / for pow() is not present in 3.6 so it makes no sense to have
+# it there.
+if sys.version_info < (3, 7):
+    __all__ = __all__[1:]
similarity index 80%
rename from documentation/test_python/inspect_annotations/math36.html
rename to documentation/test_python/inspect_builtin/inspect_builtin36.html
index 7301a2160211dbe52f66c4d45a77cee2598b4dcc..b9e7b300cc43433ce6940beee7a9d831f285f5e8 100644 (file)
@@ -2,7 +2,7 @@
 <html lang="en">
 <head>
   <meta charset="UTF-8" />
-  <title>math | My Python Project</title>
+  <title>inspect_builtin | My Python Project</title>
   <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600" />
   <link rel="stylesheet" href="m-dark+documentation.compiled.css" />
   <meta name="viewport" content="width=device-width, initial-scale=1.0" />
     <div class="m-row">
       <div class="m-col-l-10 m-push-l-1">
         <h1>
-          math <span class="m-thin">module</span>
+          inspect_builtin <span class="m-thin">module</span>
         </h1>
-        <p>This module is always available.  It provides access to the
-mathematical functions defined by the C standard.</p>
         <nav class="m-block m-default">
           <h3>Contents</h3>
           <ul>
@@ -48,7 +46,7 @@ mathematical functions defined by the C standard.</p>
           <h2>Function documentation</h2>
           <section class="m-doc-details" id="log"><div>
             <h3>
-              <span class="m-doc-wrap-bumper">def math.<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#log" class="m-doc-self">log</a>(</span><span class="m-doc-wrap">...)</span></span>
+              <span class="m-doc-wrap-bumper">def inspect_builtin.<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#log" class="m-doc-self">log</a>(</span><span class="m-doc-wrap">...)</span></span>
             </h3>
             <p>log(x[, base])</p>
 <p>Return the logarithm of x to the given base.
similarity index 83%
rename from documentation/test_python/inspect_annotations/math39.html
rename to documentation/test_python/inspect_builtin/inspect_builtin39.html
index cb97c7fafec37b622d61ef025569f39ea9b45d45..5711a4e96256b9d240c30e00fd8bc072cde95339 100644 (file)
@@ -2,7 +2,7 @@
 <html lang="en">
 <head>
   <meta charset="UTF-8" />
-  <title>math | My Python Project</title>
+  <title>inspect_builtin | My Python Project</title>
   <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600" />
   <link rel="stylesheet" href="m-dark+documentation.compiled.css" />
   <meta name="viewport" content="width=device-width, initial-scale=1.0" />
     <div class="m-row">
       <div class="m-col-l-10 m-push-l-1">
         <h1>
-          math <span class="m-thin">module</span>
+          inspect_builtin <span class="m-thin">module</span>
         </h1>
-        <p>This module provides access to the mathematical functions
-defined by the C standard.</p>
         <nav class="m-block m-default">
           <h3>Contents</h3>
           <ul>
@@ -53,7 +51,7 @@ Return the logarithm of x to the given base.</dd>
           <h2>Function documentation</h2>
           <section class="m-doc-details" id="log"><div>
             <h3>
-              <span class="m-doc-wrap-bumper">def math.<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#log" class="m-doc-self">log</a>(</span><span class="m-doc-wrap">...)</span></span>
+              <span class="m-doc-wrap-bumper">def inspect_builtin.<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#log" class="m-doc-self">log</a>(</span><span class="m-doc-wrap">...)</span></span>
             </h3>
             <p>log(x, [base=math.e])
 Return the logarithm of x to the given base.</p>
index 05b7fc1da182dfd1aa538a8cf7cded774e576b48..fee28f5e42399724863693f4e2f44e349f016532 100644 (file)
@@ -109,36 +109,23 @@ class Annotations(BaseInspectTestCase):
         else:
             self.assertEqual(*self.actual_expected_contents('inspect_annotations.AContainer.html', 'inspect_annotations.AContainer-py36-38.html'))
 
-    def test_math(self):
-        # From math export only pow() so we have the verification easier, and
-        # in addition log() because it doesn't provide any signature metadata
-        assert not hasattr(math, '__all__')
-        math.__all__ = ['log']
-        # signature with / for pow() is not present in 3.6 so it makes no sense
-        # to have it
-        if sys.version_info >= (3, 7):
-            math.__all__ = ['pow'] + math.__all__
-
-        self.run_python({
-            'INPUT_MODULES': [math]
-        })
+class Builtin(BaseInspectTestCase):
+    def test(self):
+        self.run_python()
 
-        # 3.12 improves a docstring further. It got seemingly backported to
-        # 3.11.3 and 3.10.11 as well, but an actual build of 3.11.9 doesn't
-        # seem to have that, so checking this just on 3.12.
+        # log() and pow() from the builtin math module. 3.12 improves a
+        # docstring. It got seemingly backported to 3.11.3 and 3.10.11 as well,
+        # but an actual build of 3.11.9 doesn't seem to have that, so checking
+        # this just on 3.12.
         # https://github.com/python/cpython/pull/102049
         if sys.version_info >= (3, 12):
-            file = 'math.html'
-        elif sys.version_info >= (3, 7, 4):
-            file = 'math39.html'
-        # 3.7.3 and below has a different docstring
-        # https://github.com/python/cpython/pull/13394
+            file = 'inspect_builtin.html'
         elif sys.version_info >= (3, 7):
-            file = 'math373.html'
-        # signature with / for pow() is not present in 3.6
+            file = 'inspect_builtin39.html'
+        # Signature with / for pow() is not present in 3.6
         else:
-            file = 'math36.html'
-        self.assertEqual(*self.actual_expected_contents('math.html', file))
+            file = 'inspect_builtin36.html'
+        self.assertEqual(*self.actual_expected_contents('inspect_builtin.html', file))
 
 class NameMapping(BaseInspectTestCase):
     def test(self):