-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more tests for API generation script (#581)
Part of #223. One way to improve the maintainability of our API generation is to test more. It gives us confidence we aren't breaking things and it makes it more obvious how the function behaves. This PR also makes some light refactoring like renaming things to be more clear. --------- Co-authored-by: Arnau Casau <[email protected]> Co-authored-by: Arnau Casau <[email protected]>
- Loading branch information
1 parent
1e46f0b
commit d273272
Showing
23 changed files
with
323 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// This code is a Qiskit project. | ||
// | ||
// (C) Copyright IBM 2024. | ||
// | ||
// This code is licensed under the Apache License, Version 2.0. You may | ||
// obtain a copy of this license in the LICENSE file in the root directory | ||
// of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// Any modifications or derivative works of this code must retain this | ||
// copyright notice, and modified files need to carry a notice indicating | ||
// that they have been altered from the originals. | ||
|
||
import { expect, test } from "@jest/globals"; | ||
|
||
import { getRoot, pathExists } from "./fs"; | ||
|
||
test("pathExists() with getRoot()", async () => { | ||
const readme = await pathExists(`${getRoot()}/README.md`); | ||
expect(readme).toBe(true); | ||
|
||
const dir = await pathExists(`${getRoot()}/docs/`); | ||
expect(dir).toBe(true); | ||
|
||
const fake = await pathExists(`${getRoot()}/fake-file`); | ||
expect(fake).toBe(false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// This code is a Qiskit project. | ||
// | ||
// (C) Copyright IBM 2024. | ||
// | ||
// This code is licensed under the Apache License, Version 2.0. You may | ||
// obtain a copy of this license in the LICENSE file in the root directory | ||
// of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// Any modifications or derivative works of this code must retain this | ||
// copyright notice, and modified files need to carry a notice indicating | ||
// that they have been altered from the originals. | ||
|
||
import { expect, test } from "@jest/globals"; | ||
|
||
import addFrontMatter from "./addFrontMatter"; | ||
import { Pkg } from "../sharedTypes"; | ||
import { SphinxToMdResult } from "./SphinxToMdResult"; | ||
|
||
test("addFrontMatter()", () => { | ||
const results: SphinxToMdResult[] = [ | ||
{ | ||
markdown: "# Hardcoded!", | ||
meta: { | ||
hardcoded_frontmatter: "title: hardcoded\ndescription: Hello world!", | ||
}, | ||
images: [], | ||
isReleaseNotes: false, | ||
}, | ||
{ | ||
markdown: "# Hardcoded with python_api_name!", | ||
meta: { | ||
hardcoded_frontmatter: | ||
"title: hardcoded with python_api_name\ndescription: Hello world!", | ||
python_api_name: "quantum_software.MyClass", | ||
python_api_type: "class", | ||
}, | ||
images: [], | ||
isReleaseNotes: true, | ||
}, | ||
{ | ||
markdown: "# Python API", | ||
meta: { | ||
python_api_name: "quantum_software.MyClass", | ||
python_api_type: "class", | ||
}, | ||
images: [], | ||
isReleaseNotes: false, | ||
}, | ||
{ | ||
markdown: "# Some release notes!", | ||
meta: {}, | ||
images: [], | ||
isReleaseNotes: true, | ||
}, | ||
]; | ||
const pkg = { | ||
versionWithoutPatch: "0.0", | ||
hasSeparateReleaseNotes: true, | ||
title: "My Quantum Software Project", | ||
} as Pkg; | ||
|
||
addFrontMatter(results, pkg); | ||
expect(results.map((result) => result.markdown)).toEqual([ | ||
`--- | ||
title: hardcoded | ||
description: Hello world! | ||
--- | ||
# Hardcoded! | ||
`, | ||
`--- | ||
title: hardcoded with python_api_name | ||
description: Hello world! | ||
--- | ||
# Hardcoded with python_api_name! | ||
`, | ||
`--- | ||
title: MyClass | ||
description: API reference for quantum_software.MyClass | ||
in_page_toc_min_heading_level: 1 | ||
python_api_type: class | ||
python_api_name: quantum_software.MyClass | ||
--- | ||
# Python API | ||
`, | ||
`--- | ||
title: My Quantum Software Project 0.0 release notes | ||
description: Changes made in My Quantum Software Project 0.0 | ||
in_page_toc_max_heading_level: 2 | ||
--- | ||
# Some release notes! | ||
`, | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// This code is a Qiskit project. | ||
// | ||
// (C) Copyright IBM 2024. | ||
// | ||
// This code is licensed under the Apache License, Version 2.0. You may | ||
// obtain a copy of this license in the LICENSE file in the root directory | ||
// of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// Any modifications or derivative works of this code must retain this | ||
// copyright notice, and modified files need to carry a notice indicating | ||
// that they have been altered from the originals. | ||
|
||
import { expect, test } from "@jest/globals"; | ||
|
||
import flattenFolders from "./flattenFolders"; | ||
import { SphinxToMdResultWithUrl } from "./SphinxToMdResult"; | ||
|
||
test("flattenFolders()", () => { | ||
const results = [ | ||
{ url: "/api/my-pkg/apidoc/my_module" }, | ||
{ url: "/api/my-pkg/apidocs/my_module2" }, | ||
{ url: "/api/my-pkg/stubs/my_module.foo.Bar" }, | ||
{ url: "/api/my-pkg/release_notes" }, | ||
] as SphinxToMdResultWithUrl[]; | ||
|
||
flattenFolders(results); | ||
expect(results.map((result) => result.url)).toEqual([ | ||
"/api/my-pkg/my_module", | ||
"/api/my-pkg/my_module2", | ||
"/api/my-pkg/my_module.foo.Bar", | ||
"/api/my-pkg/release_notes", | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.