Skip to content

Commit d64b076

Browse files
committed
Requested updates and test
1 parent 5ecfdd0 commit d64b076

File tree

6 files changed

+103
-10
lines changed

6 files changed

+103
-10
lines changed

buildconfig/CMake/CommonSetup.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ endif()
1919
option(ENABLE_OPENGL "Enable OpenGLbased rendering" ON)
2020
option(ENABLE_OPENCASCADE "Enable OpenCascade-based 3D visualisation" ON)
2121
option(USE_PYTHON_DYNAMIC_LIB "Dynamic link python libs" ON)
22+
option(ENABLE_QTASSISTANT "If enabled, add a target to build the qthelp documentation for qtassistant" ON)
2223

2324
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
2425
make_directory(${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Testing)

qt/widgets/common/CMakeLists.txt

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
option(DOCS_QTHELP "If enabled add a target to build the qthelp documentation for qtassistant" ON)
2-
31
set(SRC_FILES
42
src/AddWorkspaceDialog.cpp
53
src/AddWorkspaceMultiDialog.cpp
@@ -161,7 +159,7 @@ set(SRC_FILES
161159
src/Python/QHashToDict.cpp
162160
)
163161

164-
if(DOCS_QTHELP STREQUAL "OFF")
162+
if(NOT ENABLE_QTASSISTANT)
165163
list(APPEND SRC_FILES src/PythonHelpBridge.cpp)
166164
list(APPEND SRC_FILES src/PythonHelpWindow.cpp)
167165
endif()
@@ -269,7 +267,7 @@ set(QT5_MOC_FILES
269267
inc/MantidQtWidgets/Common/QtPropertyBrowser/WorkspaceEditorFactory.h
270268
)
271269

272-
if(DOCS_QTHELP STREQUAL "OFF")
270+
if(NOT ENABLE_QTASSISTANT)
273271
list(APPEND QT5_MOC_FILES inc/MantidQtWidgets/Common/PythonHelpBridge.h)
274272
list(APPEND QT5_MOC_FILES inc/MantidQtWidgets/Common/PythonHelpWindow.h)
275273
endif()
@@ -649,7 +647,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
649647
endif()
650648

651649
# Add option to the compiler to register MantidHelpWindow
652-
if(DOCS_QTHELP)
650+
if(ENABLE_QTASSISTANT)
653651
add_definitions(-DDOCS_QTHELP)
654652
endif()
655653

@@ -738,6 +736,7 @@ set(TEST_FILES
738736
test/ProgressableViewTest.h
739737
test/ProjectSaveModelTest.h
740738
test/ProjectSavePresenterTest.h
739+
test/PythonHelpWindowTest.h
741740
test/SelectionNotificationServiceTest.h
742741
test/SelectionWorkspacesDialogTest.h
743742
test/TrackedActionTest.h

qt/widgets/common/inc/MantidQtWidgets/Common/PythonHelpBridge.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ namespace MantidWidgets {
1515
class EXPORT_OPT_MANTIDQT_COMMON PythonHelpBridge {
1616
public:
1717
PythonHelpBridge();
18-
void showHelpPage(const std::string &relative_url, const std::string &local_docs = "",
19-
const std::string &online_base_url = "https://docs.mantidproject.org/");
18+
void showHelpPage(const std::string &relative_url);
2019
};
2120

2221
} // namespace MantidWidgets

qt/widgets/common/src/PythonHelpBridge.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ PythonHelpBridge::PythonHelpBridge() {
3434
}
3535
}
3636

37-
void PythonHelpBridge::showHelpPage(const std::string &relative_url, const std::string &local_docs,
38-
const std::string &online_base_url) {
37+
void PythonHelpBridge::showHelpPage(const std::string &relative_url) {
3938
PyGILState_STATE gstate = PyGILState_Ensure();
4039
try {
4140
boost::python::object module = getHelpWindowModule();

qt/widgets/common/src/PythonHelpWindow.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void PythonHelpWindow::showCustomInterface(const QString &name, const QString &a
9191
}
9292

9393
void PythonHelpWindow::shutdown() {
94-
// no-op for python help window
94+
// TODO: We may need to close the Python-based help window when integrated into Mantid Workbench
9595
}
9696

9797
} // namespace MantidWidgets
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Mantid Repository : https://github.com/mantidproject/mantid
2+
//
3+
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4+
// NScD Oak Ridge National Laboratory, European Spallation Source,
5+
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6+
// SPDX - License - Identifier: GPL - 3.0 +
7+
#pragma once
8+
9+
#include <cxxtest/TestSuite.h>
10+
#include <gmock/gmock.h>
11+
12+
#include <QString>
13+
#include <QUrl>
14+
15+
#include "MantidQtWidgets/Common/PythonHelpBridge.h"
16+
#include "MantidQtWidgets/Common/PythonHelpWindow.h"
17+
18+
#include "MantidKernel/WarningSuppressions.h"
19+
GNU_DIAG_OFF_SUGGEST_OVERRIDE
20+
21+
using namespace MantidQt::API;
22+
using namespace MantidQt::MantidWidgets;
23+
using namespace testing;
24+
25+
GNU_DIAG_ON_SUGGEST_OVERRIDE
26+
27+
class PythonHelpWindowTest : public CxxTest::TestSuite {
28+
public:
29+
void setUp() override {}
30+
31+
void tearDown() override {}
32+
33+
// 1) Test the constructor doesn't throw and creates a valid object
34+
void testConstructorDoesNotThrow() { TS_ASSERT_THROWS_NOTHING(PythonHelpWindow helpWin); }
35+
36+
// 2) Test showPage(std::string) with an empty string
37+
void testShowPageWithEmptyString() {
38+
PythonHelpWindow helpWin;
39+
TS_ASSERT_THROWS_NOTHING(helpWin.showPage(std::string{}));
40+
}
41+
42+
// 3) Test showPage(std::string) with a non-empty string
43+
void testShowPageWithNonEmptyString() {
44+
PythonHelpWindow helpWin;
45+
TS_ASSERT_THROWS_NOTHING(helpWin.showPage("custom_page.html"));
46+
}
47+
48+
// 4) Test showPage(QString) with an empty string
49+
void testShowPage_QString_Empty() {
50+
PythonHelpWindow helpWin;
51+
TS_ASSERT_THROWS_NOTHING(helpWin.showPage(QString()));
52+
}
53+
54+
// 5) Test showPage(QUrl) with an empty URL
55+
void testShowPage_QUrl_Empty() {
56+
PythonHelpWindow helpWin;
57+
TS_ASSERT_THROWS_NOTHING(helpWin.showPage(QUrl()));
58+
}
59+
60+
// 6) Test showAlgorithm(std::string) with empty name and version
61+
void testShowAlgorithm_NoName() {
62+
PythonHelpWindow helpWin;
63+
TS_ASSERT_THROWS_NOTHING(helpWin.showAlgorithm("", -1));
64+
}
65+
66+
// 7) Test showAlgorithm(std::string) with valid name and version
67+
void testShowAlgorithm_NameAndVersion() {
68+
PythonHelpWindow helpWin;
69+
TS_ASSERT_THROWS_NOTHING(helpWin.showAlgorithm("Load", 2));
70+
}
71+
72+
// 8) Test showConcept(std::string) with empty name
73+
void testShowConceptEmpty() {
74+
PythonHelpWindow helpWin;
75+
TS_ASSERT_THROWS_NOTHING(helpWin.showConcept(""));
76+
}
77+
78+
// 9) Test showFitFunction(std::string) with a name
79+
void testShowFitFunctionName() {
80+
PythonHelpWindow helpWin;
81+
TS_ASSERT_THROWS_NOTHING(helpWin.showFitFunction("GaussPeak"));
82+
}
83+
84+
// 10) Test showCustomInterface(std::string) with name, area, section
85+
void testShowCustomInterface() {
86+
PythonHelpWindow helpWin;
87+
TS_ASSERT_THROWS_NOTHING(helpWin.showCustomInterface("Reflectometry", "ISISReflectometry", "Usage"));
88+
}
89+
90+
// 11) Test the shutdown method (currently a no-op)
91+
void testShutdownDoesNotThrow() {
92+
PythonHelpWindow helpWin;
93+
TS_ASSERT_THROWS_NOTHING(helpWin.shutdown());
94+
}
95+
};

0 commit comments

Comments
 (0)