Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bindings/pyroot/pythonizations/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,6 @@ if(NOT MSVC OR CMAKE_SIZEOF_VOID_P EQUAL 8 OR win_broken_tests)
# https://github.com/root-project/root/issues/9809
ROOT_ADD_PYUNITTEST(pyroot_array_numpy_views array_conversions.py PYTHON_DEPS numpy)
endif()

file(COPY mock_rdf_define_header.hxx DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
ROOT_ADD_PYUNITTEST(mock_rdf_define_pyz mock_rdf_define_pyz.py)
25 changes: 25 additions & 0 deletions bindings/pyroot/pythonizations/test/mock_rdf_define_header.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef MOCK_RDF_DEFINE_HEADER
#define MOCK_RDF_DEFINE_HEADER

#include <iostream>
#include <string_view>
#include <string>
#include <vector>

float foo()
{
return 42;
}

using ColumnNames_t = std::vector<std::string>;

struct MockRDF {
template <typename F, typename std::enable_if_t<!std::is_convertible<F, std::string>::value, int> = 0>
void mock_define(std::string_view name, F fun, const ColumnNames_t &columns = {})
{
auto val = fun();
std::cout << "Class method with name " << name << " got value " << val << "\n";
}
};

#endif // MOCK_RDF_DEFINE_HEADER
29 changes: 29 additions & 0 deletions bindings/pyroot/pythonizations/test/mock_rdf_define_pyz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import unittest

import ROOT


class MockRDFTest(unittest.TestCase):

def test_mock_define(self):

ROOT.gInterpreter.Declare('#include "mock_rdf_define_header.hxx"')

ROOT.MockRDF._original_define = ROOT.MockRDF.mock_define
ROOT.MockRDF.mock_define = None

# On Linux and MacOS this should work, on Windows it triggers an error like
# Traceback (most recent call last):
# File "C:\root-dev\build\x64\relwithdebinfo\runtutorials\test_header.py", line 4, in <module>
# val = df._OriginalDefine("x", ROOT.foo).Sum("x").GetValue()
# ^^^^^^^^
# File "C:\root-dev\build\x64\relwithdebinfo\bin\ROOT\_facade.py", line 120, in _fallback_getattr
# raise AttributeError("Failed to get attribute {} from ROOT".format(name))
# AttributeError: Failed to get attribute foo from ROOT
signature_of_foo = "float()"
std_fn = ROOT.std.function(signature_of_foo)
ROOT.MockRDF()._original_define[type(std_fn)]("myname", ROOT.foo)


if __name__ == '__main__':
unittest.main()
Loading