Skip to content
Snippets Groups Projects
Commit 4c7414d7 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

New python functional test for FixedBinAxis, IAxis operators are exposed to python.

parent cd2d54e3
No related branches found
No related tags found
No related merge requests found
...@@ -191,6 +191,9 @@ void register_IAxis_class(){ ...@@ -191,6 +191,9 @@ void register_IAxis_class(){
, ( bp::arg("name") ) ); , ( bp::arg("name") ) );
} }
IAxis_exposer.def( bp::self != bp::self );
IAxis_exposer.def( bp::self_ns::str( bp::self ) );
IAxis_exposer.def( bp::self == bp::self );
} }
} }
...@@ -18,7 +18,7 @@ void register_OutputDataIOFactory_class(){ ...@@ -18,7 +18,7 @@ void register_OutputDataIOFactory_class(){
{ //::OutputDataIOFactory { //::OutputDataIOFactory
typedef bp::class_< OutputDataIOFactory > OutputDataIOFactory_exposer_t; typedef bp::class_< OutputDataIOFactory > OutputDataIOFactory_exposer_t;
OutputDataIOFactory_exposer_t OutputDataIOFactory_exposer = OutputDataIOFactory_exposer_t( "OutputDataIOFactory", bp::init< >() ); OutputDataIOFactory_exposer_t OutputDataIOFactory_exposer = OutputDataIOFactory_exposer_t( "OutputDataIOFactory" );
bp::scope OutputDataIOFactory_scope( OutputDataIOFactory_exposer ); bp::scope OutputDataIOFactory_scope( OutputDataIOFactory_exposer );
{ //::OutputDataIOFactory::getReader { //::OutputDataIOFactory::getReader
......
...@@ -62,9 +62,11 @@ public: ...@@ -62,9 +62,11 @@ public:
virtual size_t findClosestIndex(double value) const=0; virtual size_t findClosestIndex(double value) const=0;
//! test for equality //! test for equality
friend bool operator==(const IAxis& left, const IAxis& right) { friend bool operator==(const IAxis& left, const IAxis& right);
return left.equals(right);
} // friend bool operator==(const IAxis& left, const IAxis& right) {
// return left.equals(right);
// }
friend std::ostream& operator<<(std::ostream& ostr, const IAxis& m) friend std::ostream& operator<<(std::ostream& ostr, const IAxis& m)
{ m.print(ostr); return ostr; } { m.print(ostr); return ostr; }
...@@ -85,6 +87,10 @@ inline bool IAxis::equals(const IAxis& other) const ...@@ -85,6 +87,10 @@ inline bool IAxis::equals(const IAxis& other) const
return getName()==other.getName(); return getName()==other.getName();
} }
inline bool operator==(const IAxis& left, const IAxis& right) {
return left.equals(right);
}
inline bool operator!=(const IAxis& left, const IAxis& right) { inline bool operator!=(const IAxis& left, const IAxis& right) {
return !(left == right); return !(left == right);
} }
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <algorithm> #include <algorithm>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
//! Creates axis of certain type from input stream
IAxis *OutputDataIOHelper::createAxis(std::istream &input_stream) IAxis *OutputDataIOHelper::createAxis(std::istream &input_stream)
{ {
std::string line; std::string line;
...@@ -22,7 +24,8 @@ IAxis *OutputDataIOHelper::createAxis(std::istream &input_stream) ...@@ -22,7 +24,8 @@ IAxis *OutputDataIOHelper::createAxis(std::istream &input_stream)
} }
// FixedBinAxis("axis0", 10, -1, 1) //! Create FixedBinAxis from string representation
//! FixedBinAxis("axis0", 10, -1, 1)
FixedBinAxis *OutputDataIOHelper::createFixedBinAxis(std::string line) FixedBinAxis *OutputDataIOHelper::createFixedBinAxis(std::string line)
{ {
boost::replace_all(line, FixedBinAxisType, ""); boost::replace_all(line, FixedBinAxisType, "");
...@@ -39,14 +42,11 @@ FixedBinAxis *OutputDataIOHelper::createFixedBinAxis(std::string line) ...@@ -39,14 +42,11 @@ FixedBinAxis *OutputDataIOHelper::createFixedBinAxis(std::string line)
if( !(iss >> name >> nbins >> start >> end) ) if( !(iss >> name >> nbins >> start >> end) )
throw Exceptions::FormatErrorException("OutputDataIOHelper::createFixedBinAxis() -> Error. Can't parse the string."); throw Exceptions::FormatErrorException("OutputDataIOHelper::createFixedBinAxis() -> Error. Can't parse the string.");
std::cout << line << " " << name << " " << nbins << " " << start << " " << end << std::endl; return new FixedBinAxis(name, nbins, start, end);
FixedBinAxis *result = new FixedBinAxis(name, nbins, start, end);
return result;
} }
//! Fills output data raw buffer from input stream
void OutputDataIOHelper::fillOutputData(OutputData<double> *data, std::istream &input_stream) void OutputDataIOHelper::fillOutputData(OutputData<double> *data, std::istream &input_stream)
{ {
std::string line; std::string line;
......
...@@ -181,8 +181,6 @@ OutputData<double > *OutputDataReadStreamBA::readOutputData(std::istream &input_ ...@@ -181,8 +181,6 @@ OutputData<double > *OutputDataReadStreamBA::readOutputData(std::istream &input_
while( std::getline(input_stream, line) ) while( std::getline(input_stream, line) )
{ {
if(line.empty()) continue;
if (line.find("axis") != std::string::npos) { if (line.find("axis") != std::string::npos) {
IAxis *axis = OutputDataIOHelper::createAxis(input_stream); IAxis *axis = OutputDataIOHelper::createAxis(input_stream);
result->addAxis(*axis); result->addAxis(*axis);
......
############################################################################ ############################################################################
# CMakeLists.txt file for building TestPyCore functional tests # CMakeLists.txt file for running TestPyCore functional tests
############################################################################ ############################################################################
set(list_of_tests set(list_of_tests
"intensitydata.py" "intensitydata.py"
"intensitydata_io.py"
"isgisaxs01.py" "isgisaxs01.py"
"isgisaxs01_normalize.py" "isgisaxs01_normalize.py"
"isgisaxs02.py" "isgisaxs02.py"
......
import sys
import os
import unittest
import numpy
sys.path.append(os.path.abspath(
os.path.join(os.path.split(__file__)[0],
'..', '..', '..', 'lib')))
from libBornAgainCore import *
class AxesTest(unittest.TestCase):
"""
Test creation of IntensityData object and different ways of accessing its data
"""
def test_FixedBinAxis_access(self):
axis = FixedBinAxis("length", 100, 0.0, 10.0)
self.assertEqual("length", axis.getName())
self.assertEqual(100, axis.getSize())
self.assertEqual(0.0, axis.getMin())
self.assertEqual(10.0, axis.getMax())
self.assertAlmostEqual(0.05, axis[0])
self.assertAlmostEqual(0.15, axis[1])
self.assertAlmostEqual(6.55, axis[65])
self.assertAlmostEqual(9.95, axis[99])
def test_FixedBinAxis_equality(self):
b1 = FixedBinAxis("axis", 99, -1.01, 3.3)
b2 = FixedBinAxis("axis", 99, -1.01, 3.3)
self.assertTrue( b1 == b2)
if __name__ == '__main__':
unittest.main()
# tests of IntensityData object
import sys
import os
import unittest
import numpy
sys.path.append(os.path.abspath(
os.path.join(os.path.split(__file__)[0],
'..', '..', '..', 'lib')))
from libBornAgainCore import *
def fill_data(data):
"""Fills intensity data with some numbers"""
for i in range(0, data.getAllocatedSize()):
data[i] = i
def is_the_same(data1, data2):
if data1.getAllocatedSize() != data2.getAllocatedSize():
return False
if data1.getRank() != data2.getRank():
return False
for i in range(0, data1.getRank()):
if data1.getAxis(i) == data2.getAxis(i):
print "xxx"
else:
print "yyy"
return True
class OutputDataIOTest(unittest.TestCase):
"""
Test serialization of IntensityData
"""
def test_1D_FixedBinAxis(self):
data = IntensityData()
data.addAxis(FixedBinAxis("axis0", 10, -1.00000001, 1.0))
fill_data(data)
OutputDataIOFactory.writeIntensityData(data, "tmp.baint")
newdata = OutputDataIOFactory.readIntensityData("tmp.baint")
self.assertTrue(is_the_same(data, newdata))
if __name__ == '__main__':
unittest.main()
...@@ -173,6 +173,9 @@ def ManualClassTunings(mb): ...@@ -173,6 +173,9 @@ def ManualClassTunings(mb):
mb.class_("AxisDouble").member_function("clone").exclude() mb.class_("AxisDouble").member_function("clone").exclude()
mb.class_("AxisDouble").member_functions("createDoubleBinSize").exclude() mb.class_("AxisDouble").member_functions("createDoubleBinSize").exclude()
axis_operators = mb.free_operators( lambda decl: 'IAxis' in decl.decl_string )
axis_operators.include()
mb.class_("Detector").member_functions("addAxis").exclude() mb.class_("Detector").member_functions("addAxis").exclude()
# #
shared_ptrs = mb.decls(lambda decl: decl.name.startswith('shared_ptr<' )) shared_ptrs = mb.decls(lambda decl: decl.name.startswith('shared_ptr<' ))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment