Skip to content

Commit f198ab4

Browse files
committed
[do not merge] Test mock RDF Define pythonization
While working on #20898 I discovered that the Python version of the tutorial fails only on Windows for what looks to be a problem with the RDF Define Pythonization. This may or may not be related to #21405
1 parent 319a37e commit f198ab4

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

bindings/pyroot/pythonizations/test/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,6 @@ if(NOT MSVC OR CMAKE_SIZEOF_VOID_P EQUAL 8 OR win_broken_tests)
188188
# https://github.com/root-project/root/issues/9809
189189
ROOT_ADD_PYUNITTEST(pyroot_array_numpy_views array_conversions.py PYTHON_DEPS numpy)
190190
endif()
191+
192+
file(COPY mock_rdf_define_header.hxx DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
193+
ROOT_ADD_PYUNITTEST(mock_rdf_define_pyz mock_rdf_define_pyz.py)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef MOCK_RDF_DEFINE_HEADER
2+
#define MOCK_RDF_DEFINE_HEADER
3+
4+
#include <iostream>
5+
#include <string_view>
6+
#include <string>
7+
#include <vector>
8+
9+
float foo()
10+
{
11+
return 42;
12+
}
13+
14+
using ColumnNames_t = std::vector<std::string>;
15+
16+
struct MockRDF {
17+
template <typename F, typename std::enable_if_t<!std::is_convertible<F, std::string>::value, int> = 0>
18+
void mock_define(std::string_view name, F fun, const ColumnNames_t &columns = {})
19+
{
20+
auto val = fun();
21+
std::cout << "Class method with name " << name << " got value " << val << "\n";
22+
}
23+
};
24+
25+
#endif // MOCK_RDF_DEFINE_HEADER
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import unittest
2+
3+
import ROOT
4+
5+
6+
class MockRDFTest(unittest.TestCase):
7+
8+
def test_mock_define(self):
9+
10+
ROOT.gInterpreter.Declare('#include "mock_rdf_define_header.hxx"')
11+
12+
ROOT.MockRDF._original_define = ROOT.MockRDF.mock_define
13+
ROOT.MockRDF.mock_define = None
14+
15+
# On Linux and MacOS this should work, on Windows it triggers an error like
16+
# Traceback (most recent call last):
17+
# File "C:\root-dev\build\x64\relwithdebinfo\runtutorials\test_header.py", line 4, in <module>
18+
# val = df._OriginalDefine("x", ROOT.foo).Sum("x").GetValue()
19+
# ^^^^^^^^
20+
# File "C:\root-dev\build\x64\relwithdebinfo\bin\ROOT\_facade.py", line 120, in _fallback_getattr
21+
# raise AttributeError("Failed to get attribute {} from ROOT".format(name))
22+
# AttributeError: Failed to get attribute foo from ROOT
23+
signature_of_foo = "float()"
24+
std_fn = ROOT.std.function(signature_of_foo)
25+
ROOT.MockRDF()._original_define[type(std_fn)]("myname", ROOT.foo)
26+
27+
28+
if __name__ == '__main__':
29+
unittest.main()

0 commit comments

Comments
 (0)