Skip to content

Commit

Permalink
Add integration test of qiskit-sphinx-theme (Qiskit#960)
Browse files Browse the repository at this point in the history
Closes Qiskit#715.

This is useful generally for better testing of our conversion pipeline,
as it's our only test that tests the entire conversion pipeline.

It also is useful to allow us to easily compare Sphinx's behavior vs.
our app's behavior, like the PDFs I uploaded in
Qiskit#947.

--

I didn't document this in the README because we don't talk about testing
in the README currently. Our README is already quite long, so I was
hesitant to add to it since most technical writers don't care about
testing, unlike Jupyter notebook testing that we do document.

Instead, I documented the test file itself. I'm not sure if this is
clear enough.

---------

Co-authored-by: Arnau Casau <47946624+arnaucasau@users.noreply.github.com>
  • Loading branch information
Eric-Arellano and arnaucasau authored Mar 5, 2024
1 parent 4895682 commit 12545a3
Show file tree
Hide file tree
Showing 9 changed files with 2,214 additions and 0 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
docs
translations
scripts/lib/api/testdata
378 changes: 378 additions & 0 deletions scripts/lib/api/__snapshots__/conversionPipeline.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,378 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`qiskit-sphinx-theme: _package 1`] = `
"{
"name": "qiskit-sphinx-theme",
"version": "0.1.1"
}
"
`;

exports[`qiskit-sphinx-theme: _toc 1`] = `
"{
"title": "Qiskit Sphinx Theme",
"children": [
{
"title": "api_example",
"children": [
{
"title": "Overview",
"url": "/api/qiskit-sphinx-theme/module"
},
{
"title": "Electron",
"url": "/api/qiskit-sphinx-theme/api_example.Electron"
},
{
"title": "my_function",
"url": "/api/qiskit-sphinx-theme/api_example.my_function"
},
{
"title": "SimpleInlineClass",
"url": "/api/qiskit-sphinx-theme/inline_classes"
}
]
},
{
"title": "Release notes",
"url": "/api/qiskit-sphinx-theme/release-notes"
}
],
"collapsed": true
}
"
`;

exports[`qiskit-sphinx-theme: api_example.Electron 1`] = `
"---
title: Electron
description: API reference for api_example.Electron
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: api_example.Electron
---
# Electron
<span id="api_example.Electron" />
\`api_example.Electron(size=None, name=None)\` [GitHub](https://github.com/Qiskit/qiskit_sphinx_theme/tree/stable/0.1/api_example/electron.py "view source code")
Bases: \`object\`
A representation of an electron.
**Examples**
\`\`\`python
from api_example import Electron
ELECTRON = Electron(size="2GB", name="QuantumComputing")
\`\`\`
Create an electron.
**Parameters**
* **size** (*str*) – How big should this thing be?
* **name** (*str*) – The name we’ll call the electron. Nicknames preferred.
**Raises**
**ValueError** – You did something wrong
## Attributes
<span id="api_example.Electron.CLASS_ATTRIBUTE" />
### CLASS\\_ATTRIBUTE
\`= re.compile('abc')\`
<span id="api_example.Electron.charge" />
### charge
<span id="api_example.Electron.mass" />
### mass
The mass of the electron.
<span id="api_example.Electron.really_long_named_attribute_that_probably_does_not_fit_nicely" />
### really\\_long\\_named\\_attribute\\_that\\_probably\\_does\\_not\\_fit\\_nicely
A bit too verbose if you ask me.
## Methods
### compute\\_momentum
<span id="api_example.Electron.compute_momentum" />
\`compute_momentum(velocity)\`
Compute the electron’s velocity.
**Parameters**
**velocity** (*float*) – The electron’s velocity
**Returns**
The computed momentum.
**Raises**
**ValueError** – You did something wrong
**Return type**
float
### method\\_with\\_a\\_reallyyreallreallyreallyreallyreallyreallreallyreallyreallyreally\\_long\\_title
<span id="api_example.Electron.method_with_a_reallyyreallreallyreallyreallyreallyreallreallyreallyreallyreally_long_title" />
\`method_with_a_reallyyreallreallyreallyreallyreallyreallreallyreallyreallyreally_long_title()\`
blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah
### overloaded\\_func
<span id="api_example.Electron.overloaded_func" />
\`overloaded_func(arg1: tuple[str, str], arg2: list[str], arg3: int, arg4: Electron) → None\`
\`overloaded_func(arg1: tuple[int, int], arg2: list[int], arg3: bool, arg4: set[Electron]) → None\`
This is meant to test out [https://github.com/Qiskit/qiskit\\_sphinx\\_theme/pull/319](https://github.com/Qiskit/qiskit_sphinx_theme/pull/319).
**Parameters**
* **arg1** – Tuples ftw!
* **arg2** – But lists are more flexy.
* **arg3** – Primitive values are good too.
* **arg4** – Recursionnnnn.
"
`;

exports[`qiskit-sphinx-theme: api_example.my_function 1`] = `
"---
title: my_function
description: API reference for api_example.my_function
in_page_toc_min_heading_level: 1
python_api_type: function
python_api_name: api_example.my_function
---
<span id="api-example-my-function" />
# api\\_example.my\\_function
<span id="api_example.my_function" />
\`api_example.my_function(input1, input2, input3=None, **kwargs)\` [GitHub](https://github.com/Qiskit/qiskit_sphinx_theme/tree/stable/0.1/api_example.py "view source code")
A function that does awesome stuff.
**Returns**
Did the function work.
**Raises**
* **ValueError** – If the inputs are not the correct values.
* **TypeError** – If the inputs are not strings.
**Return type**
int
"
`;

exports[`qiskit-sphinx-theme: inline_classes 1`] = `
"---
title: SimpleInlineClass
description: API reference for api_example.inline_classes.SimpleInlineClass
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: api_example.inline_classes.SimpleInlineClass
---
# Inline classes
This is a page to test out how we render classes and functions included inline in the page. This is common with module pages.
## Important APIs
Every time you use this program, you’ll want to create an instance of [\`api_example.inline_classes.SimpleInlineClass\`](#api_example.inline_classes.SimpleInlineClass "api_example.inline_classes.SimpleInlineClass"). It has a simple interface:
<span id="api_example.inline_classes.SimpleInlineClass" />
\`api_example.inline_classes.SimpleInlineClass(arg1)\` [GitHub](https://github.com/Qiskit/qiskit_sphinx_theme/tree/stable/0.1/api_example/inline_classes.py "view source code")
This is a simple class that does not have any methods or attributes.
It only has the class description and constructor. Many classes in Qiskit docs are simple like this.
It can be useful to use free functions rather than the class:
###
\`api_example.my_function(input1, input2, input3=None, **kwargs)\` [GitHub](https://github.com/Qiskit/qiskit_sphinx_theme/tree/stable/0.1/api_example.py "view source code")
A function that does awesome stuff.
**Returns**
Did the function work.
**Raises**
* **ValueError** – If the inputs are not the correct values.
* **TypeError** – If the inputs are not strings.
**Return type**
int
Sometimes, you even need to use a really complex class!
<span id="api_example.inline_classes.InlineClassWithMethods" />
\`api_example.inline_classes.InlineClassWithMethods\` [GitHub](https://github.com/Qiskit/qiskit_sphinx_theme/tree/stable/0.1/api_example/inline_classes.py "view source code")
Bases: \`object\`
This class is more involved.
Note how the methods and attributes are rendered and indented when this class is inlined on the docs page.
## Attributes
<span id="api_example.inline_classes.InlineClassWithMethods.CLASS_ATTRIBUTE" />
### CLASS\\_ATTRIBUTE
\`str\`
\`= 'An important part of any API.'\`
<span id="api_example.inline_classes.InlineClassWithMethods.interest_rate" />
### interest\\_rate
## Methods
### method1
<span id="api_example.inline_classes.InlineClassWithMethods.method1" />
\`method1()\`
A simple method.
**Return type**
int
### method2
<span id="api_example.inline_classes.InlineClassWithMethods.method2" />
\`method2(arg1, arg2, description)\`
A method with a lot of args!
This method will use a Hamiltonian to reach quantum advantage. Hamilton: great play & the secret to quantum computing. What a polymath.
**Parameters**
* **arg1** (*int | float*) – All numbers accepted.
* **arg2** (*list\\[*[*InlineClassWithMethods*](#api_example.inline_classes.InlineClassWithMethods "api_example.inline_classes.InlineClassWithMethods")*]*) – A list of other instances, although these will be discarded.
* **description** (*str*) – If your description is too boring or too cryptic, this program will crash your computer.
**Return type**
tuple\\[int, [*InlineClassWithMethods*](#api_example.inline_classes.InlineClassWithMethods "api_example.inline_classes.InlineClassWithMethods")]
### Warning: exceptions
The above APIs might raise an exception! Be careful!
### CustomException
<span id="api_example.inline_classes.CustomException" />
\`api_example.inline_classes.CustomException\` [GitHub](https://github.com/Qiskit/qiskit_sphinx_theme/tree/stable/0.1/api_example/inline_classes.py "view source code")
See how exceptions render too.
## Other prose
Blah blah blah.
"
`;

exports[`qiskit-sphinx-theme: module 1`] = `
"---
title: api_example
description: API reference for api_example
in_page_toc_min_heading_level: 2
python_api_type: module
python_api_name: api_example
---
<span id="api-example-api-example" />
<span id="module-api_example" />
# API example
<span id="module-api_example" />
\`api_example\`
Welcome to my super cool module!
<Admonition title="Note" type="note">
This is an example!
</Admonition>
Testing internal references… [\`Electron.compute_momentum()\`](api_example.Electron#compute_momentum "api_example.Electron.compute_momentum").
## Contents
| | |
| --------------------------------------------------------------------------------------------- | ----------------------------------- |
| [\`Electron\`](api_example.Electron "api_example.Electron")(\\[size, name]) | A representation of an electron. |
| [\`my_function\`](api_example.my_function "api_example.my_function")(input1, input2\\[, input3]) | A function that does awesome stuff. |
## Functions
###
\`api_example.my_function(input1, input2, input3=None, **kwargs)\` [GitHub](https://github.com/Qiskit/qiskit_sphinx_theme/tree/stable/0.1/api_example.py "view source code")
A function that does awesome stuff.
**Returns**
Did the function work.
**Raises**
* **ValueError** – If the inputs are not the correct values.
* **TypeError** – If the inputs are not strings.
**Return type**
int
"
`;
Loading

0 comments on commit 12545a3

Please sign in to comment.