Mantid
Loading...
Searching...
No Matches
Framework
PythonInterface
core
inc
MantidPythonInterface
core
Testing
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
9
#include "
MantidKernel/ConfigService.h
"
10
#include "
MantidPythonInterface/core/NDArray.h
"
11
#include "
MantidPythonInterface/core/VersionCompat.h
"
12
#include "cxxtest/GlobalFixture.h"
13
#include <boost/algorithm/string/trim.hpp>
14
21
class
PythonInterpreterGlobalFixture
: CxxTest::GlobalFixture {
22
public
:
23
bool
setUpWorld
()
override
{
24
using
Mantid::Kernel::ConfigService
;
25
namespace
py =
boost::python
;
26
27
Py_Initialize();
28
Mantid::PythonInterface::importNumpy
();
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
};
ConfigService.h
NDArray.h
VersionCompat.h
PythonInterpreterGlobalFixture
PythonInterpreter.
Definition
PythonInterpreterGlobalFixture.h:21
PythonInterpreterGlobalFixture::tearDownWorld
bool tearDownWorld() override
Definition
PythonInterpreterGlobalFixture.h:49
PythonInterpreterGlobalFixture::setUpWorld
bool setUpWorld() override
Definition
PythonInterpreterGlobalFixture.h:23
PythonInterpreterGlobalFixture::tearDown
bool tearDown() override
Definition
PythonInterpreterGlobalFixture.h:41
Mantid::Kernel::ConfigService
Mantid::Kernel::SingletonHolder< ConfigServiceImpl > ConfigService
Definition
ConfigService.h:302
Mantid::PythonInterface::importNumpy
MANTID_PYTHONINTERFACE_CORE_DLL void importNumpy()
Initialize the numpy array api for this DLL.
Definition
NDArray.cpp:22
boost::python
Definition
NDArray.h:50
Generated by
1.9.8