Mantid
Loading...
Searching...
No Matches
PythonInterpreterGlobalFixture.h
Go to the documentation of this file.
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
12#include "cxxtest/GlobalFixture.h"
13#include <boost/algorithm/string/trim.hpp>
14
21class PythonInterpreterGlobalFixture : CxxTest::GlobalFixture {
22public:
23 bool setUpWorld() override {
25 namespace py = boost::python;
26
27 Py_Initialize();
29 // Insert the directory of the properties file as a sitedir
30 // to ensure the built copy of mantid gets picked up
31 const py::object siteModule{py::handle<>(PyImport_ImportModule("site"))};
32 siteModule.attr("addsitedir")(ConfigService::Instance().getPropertiesDir());
33
34 // Use Agg backend for matplotlib
35 py::object mpl{py::handle<>(PyImport_ImportModule("matplotlib"))};
36 mpl.attr("use")("Agg");
37
38 return Py_IsInitialized();
39 }
40
41 bool tearDown() override {
42 // Some test methods may leave the Python error handler with an error
43 // set that confuse other tests when the executable is run as a whole
44 // Clear the errors after each suite method is run
45 PyErr_Clear();
46 return CxxTest::GlobalFixture::tearDown();
47 }
48
49 bool tearDownWorld() override {
50 Py_Finalize();
51 return true;
52 }
53};
Mantid::Kernel::SingletonHolder< ConfigServiceImpl > ConfigService
MANTID_PYTHONINTERFACE_CORE_DLL void importNumpy()
Initialize the numpy array api for this DLL.
Definition NDArray.cpp:22