Skip to content

Commit c89362d

Browse files
committed
[PyROOT] Add test for STL vector pythonizations
1 parent 291aee6 commit c89362d

2 files changed

Lines changed: 28 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
@@ -26,6 +26,9 @@ ROOT_ADD_PYUNITTEST(pyroot_pyz_decorator pythonization_decorator.py)
2626
ROOT_ADD_PYUNITTEST(pyroot_pyz_pretty_printing pretty_printing.py)
2727
ROOT_ADD_PYUNITTEST(pyroot_pyz_array_interface array_interface.py PYTHON_DEPS numpy)
2828

29+
# STL vector pythonizations
30+
ROOT_ADD_PYUNITTEST(pyroot_pyz_stl_vector stl_vector.py)
31+
2932
# TObject and subclasses pythonisations
3033
ROOT_ADD_PYUNITTEST(pyroot_pyz_tobject_contains tobject_contains.py)
3134
ROOT_ADD_PYUNITTEST(pyroot_pyz_tobject_comparisonops tobject_comparisonops.py)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import unittest
2+
import ROOT
3+
4+
5+
class STL_vector(unittest.TestCase):
6+
"""
7+
Tests for the pythonizations of std::vector.
8+
"""
9+
10+
def test_vec_char_data(self):
11+
'''
12+
Test that calling std::vector<char>::data() returns a Python string
13+
that contains the characters of the vector and no exception is raised.
14+
Check also that the iteration over the vector runs normally (#9632).
15+
'''
16+
17+
elems = ['a','b','c']
18+
v = ROOT.std.vector['char'](elems)
19+
self.assertEqual(v.data(), ''.join(elems))
20+
21+
for elem in v:
22+
self.assertEqual(elem, elems.pop(0))
23+
24+
if __name__ == '__main__':
25+
unittest.main()

0 commit comments

Comments
 (0)