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();
28 PyEval_InitThreads();
30 // Insert the directory of the properties file as a sitedir
31 // to ensure the built copy of mantid gets picked up
32 const py::object siteModule{py::handle<>(PyImport_ImportModule("site"))};
33 siteModule.attr("addsitedir")(ConfigService::Instance().getPropertiesDir());
34
35 // Use Agg backend for matplotlib
36 py::object mpl{py::handle<>(PyImport_ImportModule("matplotlib"))};
37 mpl.attr("use")("Agg");
38
39 return Py_IsInitialized();
40 }
41
42 bool tearDown() override {
43 // Some test methods may leave the Python error handler with an error
44 // set that confuse other tests when the executable is run as a whole
45 // Clear the errors after each suite method is run
46 PyErr_Clear();
47 return CxxTest::GlobalFixture::tearDown();
48 }
49
50 bool tearDownWorld() override {
51 Py_Finalize();
52 return true;
53 }
54};
Manage the lifetime of a class intended to be a singleton.
MANTID_PYTHONINTERFACE_CORE_DLL void importNumpy()
Initialize the numpy array api for this DLL.
Definition: NDArray.cpp:22