Skip to content

Commit

Permalink
Merge pull request #315 from NWChemEx-Project/test_doc_mods_patch
Browse files Browse the repository at this point in the history
`test_document_modules` Patch
  • Loading branch information
jwaldrop107 authored Aug 24, 2023
2 parents 6152008 + ffa61ec commit cfe6b78
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 176 deletions.
2 changes: 1 addition & 1 deletion src/pluginplay/printing/detail_/print_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ reSTPrinter& input_full_list(reSTPrinter& p, const type::input_map& inputs) {
p << "- Domain Restrictions :\n\n";
for(auto& desc : checks) {
auto p1 = std::string(" - ") + desc + "\n\n";
p << p1;
p.print_verbatim(p1);
}
}
p.finish_section();
Expand Down
12 changes: 5 additions & 7 deletions src/pluginplay/printing/document_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ std::string document_module(std::string name, const Module& mod) {
std::stringstream ss;
detail_::reSTPrinter p(ss);

p << ".. comment::\n\n";
p << " This page is autogenerated by pluginplay::document_module. Any "
"changes "
"made\n";
p << " to this document will be overwritten the next time it is "
p << ".. This page is autogenerated by pluginplay::document_module. Any "
"changes made\n";
p << ".. to this document will be overwritten the next time it is "
"generated.\n\n";

p.start_section(name);
Expand Down Expand Up @@ -63,8 +61,8 @@ std::string document_module(std::string name, const Module& mod) {
p << "The following is a list of property types that this module "
"satisfies.\n\n";
for(const auto& x : mod.property_types()) {
p << "- ``" << utilities::printing::Demangler::demangle(x)
<< "``\n";
p.print_verbatim(
"- ``" + utilities::printing::Demangler::demangle(x) + "``\n");
}
}
p << "\n";
Expand Down
3 changes: 2 additions & 1 deletion src/pluginplay/printing/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ namespace pluginplay::printing {
void generate_index_file(std::ostream& os,
const std::vector<std::string>& toc) {
// Generate index.rst text
std::string index = ".. toctree::\n :maxdepth: 1\n";
std::string index = "***********\nModules API\n***********\n\n"
".. toctree::\n :maxdepth: 1\n";

// Add file names to the toctree
for(std::string file : toc) { index += std::string("\n ") + file; }
Expand Down
22 changes: 11 additions & 11 deletions src/python/printing/export_printing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* limitations under the License.
*/

#pragma once
#include "../export_pluginplay.hpp"

namespace pluginplay {

void export_document_modules(py_module_reference m);

inline void export_printing(py_module_reference m) {
export_document_modules(m);
}

#pragma once
#include "../export_pluginplay.hpp"

namespace pluginplay {

void export_document_modules(py_module_reference m);

inline void export_printing(py_module_reference m) {
export_document_modules(m);
}

} // namespace pluginplay
275 changes: 136 additions & 139 deletions tests/cxx/unit_tests/pluginplay/printing/document_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ TEST_CASE("document_module") {
SECTION("Empty module") {
auto m = make_module<NullModule>();
auto corr =
".. comment::\n"
"\n"
" This page is autogenerated by pluginplay::document_module. Any"
".. This page is autogenerated by pluginplay::document_module. Any"
" changes made\n"
" to this document will be overwritten the next time it "
".. to this document will be overwritten the next time it "
"is generated.\n"
"\n"
"############\n"
Expand Down Expand Up @@ -109,141 +107,140 @@ TEST_CASE("document_module") {
REQUIRE(document_module("empty module", *m) == corr);
}
SECTION("The whole shebang") {
auto m = make_module<RealDeal>();
auto corr = ".. comment::\n"
"\n"
" This page is autogenerated by "
"pluginplay::document_module. Any changes made\n"
" to this document will be overwritten the next time it "
"is generated.\n"
"\n"
"#########\n"
"For Reals\n"
"#########\n"
"\n"
"This module is the real deal. It does math stuff like:\n"
"\n"
".. math::\n"
"\n"
" \\sum_{i=0}^N i = \\frac{N(N+1)}{2}\n"
"\n"
"Okay it's not that cool...\n"
"\n"
"***********\n"
"Please Cite\n"
"***********\n"
"\n"
"- A. Person. *The Best Article*. A Journal You Have Never "
"Heard Of. 1 (2008).\n"
"- B. Person. *A So-So Article*. A Journal Everyone Has "
"HeardOf. 1 (2009).\n"
"\n"
"\n"
"**************\n"
"Property Types\n"
"**************\n"
"\n"
"The following is a list of property types that this "
"module satisfies.\n"
"\n"
"- ``testing::OneIn``\n"
"- ``testing::NullPT``\n"
"- ``testing::OneOut``\n"
"\n"
"*************\n"
"Module Inputs\n"
"*************\n"
"\n"
"This section details the full list of inputs that the "
"module accepts. Inputs\n"
"that are not listed as optional must have their value set "
"before the module can\n"
"be run. Inputs can be set manually by calling the "
"module's ``change_input``\n"
"function or by passing arguments to a property type.\n"
"\n"
"Quick Reference\n"
"===============\n"
"\n"
"The following table provides a quick summary of the "
"inputs available to this\n"
"module. The columns are:\n"
"\n"
"- ``Key``: The key used to retrieve the option,\n"
"- ``Default`` : The initial value, if one exists, and\n"
"- ``Description`` : A human readable description of what "
"the option is used for.\n"
"\n"
"+----------+---------+-------------+\n"
"| Key | Default | Description |\n"
"+==========+=========+=============+\n"
"| Option 1 | N/A | N/A |\n"
"+----------+---------+-------------+\n"
"\n"
"\n"
"Detailed Descriptions\n"
"=====================\n"
"\n"
"The following subsections provide detailed descriptions "
"of each input recognized\n"
"by this module. The subsection headings are the name of "
"the input. Within each\n"
"subsection we list:\n"
"\n"
"- ``Description`` : A human readable description of what "
"the option is used for.\n"
"- ``Default Value`` : The initial value, if one exists.\n"
"- ``Optional?`` : Whether the value must be set inorder "
"for the module to run.\n"
"- ``Opaque?`` : Does the value of the input influence "
"memoization?.\n"
"- ``Domain Restrictions`` : Criteria a value must obey to "
"be deemed valid.\n"
"\n"
"Option 1\n"
"--------\n"
"\n"
"- Description : N/A\n"
"- Default Value : N/A\n"
"- Optional? : False\n"
"- Opaque? : True\n"
"- Domain Restrictions :\n"
"\n"
" - Type == int\n"
"\n"
"\n"
"**************\n"
"Module Results\n"
"**************\n"
"\n"
"This section tabulates the full list of results that the "
"module returns. The\n"
"columns respectively are:\n"
"\n"
"- Key: What the result is called\n"
"- Type: The C++ type of the result\n"
"- Description: What the result is/how it was computed.\n"
"\n"
".. note::\n"
"\n"
" A given property type will only return a subset of the "
"available results. \n"
" Additional results can be accessed by using other "
"property types or by using\n"
" the Module class's advanced API.\n"
"\n"
"+----------+------+-------------+\n"
"| Key | Type | Description |\n"
"+==========+======+=============+\n"
"| Result 1 | int | N/A |\n"
"+----------+------+-------------+\n"
"\n"
"\n"
"**********\n"
"Submodules\n"
"**********\n"
"\n"
"The module defines no submodules.\n\n";
auto m = make_module<RealDeal>();
auto corr =
".. This page is autogenerated by "
"pluginplay::document_module. Any changes made\n"
".. to this document will be overwritten the next time it "
"is generated.\n"
"\n"
"#########\n"
"For Reals\n"
"#########\n"
"\n"
"This module is the real deal. It does math stuff like:\n"
"\n"
".. math::\n"
"\n"
" \\sum_{i=0}^N i = \\frac{N(N+1)}{2}\n"
"\n"
"Okay it's not that cool...\n"
"\n"
"***********\n"
"Please Cite\n"
"***********\n"
"\n"
"- A. Person. *The Best Article*. A Journal You Have Never "
"Heard Of. 1 (2008).\n"
"- B. Person. *A So-So Article*. A Journal Everyone Has "
"HeardOf. 1 (2009).\n"
"\n"
"\n"
"**************\n"
"Property Types\n"
"**************\n"
"\n"
"The following is a list of property types that this "
"module satisfies.\n"
"\n"
"- ``testing::OneIn``\n"
"- ``testing::NullPT``\n"
"- ``testing::OneOut``\n"
"\n"
"*************\n"
"Module Inputs\n"
"*************\n"
"\n"
"This section details the full list of inputs that the "
"module accepts. Inputs\n"
"that are not listed as optional must have their value set "
"before the module can\n"
"be run. Inputs can be set manually by calling the "
"module's ``change_input``\n"
"function or by passing arguments to a property type.\n"
"\n"
"Quick Reference\n"
"===============\n"
"\n"
"The following table provides a quick summary of the "
"inputs available to this\n"
"module. The columns are:\n"
"\n"
"- ``Key``: The key used to retrieve the option,\n"
"- ``Default`` : The initial value, if one exists, and\n"
"- ``Description`` : A human readable description of what "
"the option is used for.\n"
"\n"
"+----------+---------+-------------+\n"
"| Key | Default | Description |\n"
"+==========+=========+=============+\n"
"| Option 1 | N/A | N/A |\n"
"+----------+---------+-------------+\n"
"\n"
"\n"
"Detailed Descriptions\n"
"=====================\n"
"\n"
"The following subsections provide detailed descriptions "
"of each input recognized\n"
"by this module. The subsection headings are the name of "
"the input. Within each\n"
"subsection we list:\n"
"\n"
"- ``Description`` : A human readable description of what "
"the option is used for.\n"
"- ``Default Value`` : The initial value, if one exists.\n"
"- ``Optional?`` : Whether the value must be set inorder "
"for the module to run.\n"
"- ``Opaque?`` : Does the value of the input influence "
"memoization?.\n"
"- ``Domain Restrictions`` : Criteria a value must obey to "
"be deemed valid.\n"
"\n"
"Option 1\n"
"--------\n"
"\n"
"- Description : N/A\n"
"- Default Value : N/A\n"
"- Optional? : False\n"
"- Opaque? : True\n"
"- Domain Restrictions :\n"
"\n"
" - Type == int\n"
"\n"
"\n"
"**************\n"
"Module Results\n"
"**************\n"
"\n"
"This section tabulates the full list of results that the "
"module returns. The\n"
"columns respectively are:\n"
"\n"
"- Key: What the result is called\n"
"- Type: The C++ type of the result\n"
"- Description: What the result is/how it was computed.\n"
"\n"
".. note::\n"
"\n"
" A given property type will only return a subset of the "
"available results. \n"
" Additional results can be accessed by using other "
"property types or by using\n"
" the Module class's advanced API.\n"
"\n"
"+----------+------+-------------+\n"
"| Key | Type | Description |\n"
"+==========+======+=============+\n"
"| Result 1 | int | N/A |\n"
"+----------+------+-------------+\n"
"\n"
"\n"
"**********\n"
"Submodules\n"
"**********\n"
"\n"
"The module defines no submodules.\n\n";

REQUIRE(document_module("For Reals", *m) == corr);
}
Expand Down
10 changes: 8 additions & 2 deletions tests/cxx/unit_tests/pluginplay/printing/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ using namespace pluginplay::printing;

TEST_CASE("generate_index_string") {
SECTION("Empty toc") {
auto corr = ".. toctree::\n"
auto corr = "***********\n"
"Modules API\n"
"***********\n\n"
".. toctree::\n"
" :maxdepth: 1\n";

std::stringstream ss;
Expand All @@ -36,7 +39,10 @@ TEST_CASE("generate_index_string") {
}

SECTION("Full toc") {
auto corr = ".. toctree::\n"
auto corr = "***********\n"
"Modules API\n"
"***********\n\n"
".. toctree::\n"
" :maxdepth: 1\n"
"\n"
" Coulomb's_Law\n"
Expand Down
Loading

0 comments on commit cfe6b78

Please sign in to comment.