Skip to content

Commit 7c8a73a

Browse files
committed
[Python] Ensure same-type equality comparisons in RooFit unit tests
We should avoid equality comparisons between C++ proxies of different types, as their results can unexpectedly differ from C++ semantics.
1 parent 932cfb5 commit 7c8a73a

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

bindings/pyroot/pythonizations/test/roofit.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,19 @@ def _test_contains(self, collection_class):
7575

7676
for i, vptr in enumerate(variables):
7777
vname = "var" + str(i)
78-
self.assertEqual(coll.find(vptr) == vptr, vptr in coll)
79-
self.assertEqual(coll.find(vname) == vptr, vname in coll)
78+
79+
found_by_ptr = coll.find(vptr)
80+
found_by_name = coll.find(vname)
81+
82+
# To ensure comparing objects of equal type also when it can't
83+
# auto-downcast because the object was not found in the collection:
84+
if found_by_ptr == ROOT.nullptr:
85+
found_by_ptr = ROOT.BindObject(found_by_ptr, vptr.IsA().GetName())
86+
if found_by_name == ROOT.nullptr:
87+
found_by_name = ROOT.BindObject(found_by_name, vptr.IsA().GetName())
88+
89+
self.assertEqual(found_by_ptr == vptr, vptr in coll)
90+
self.assertEqual(found_by_name == vptr, vname in coll)
8091

8192
def _test_getitem(self, collection_class):
8293

0 commit comments

Comments
 (0)