fix: submodules creation and registration

- Add special case handling when submodule has the same name as parent
- `PyDict_SetItemString` doesn't steal reference, so reference count
  should be explicitly decremented to transfer object life-time
  ownership
- Add sanity checks for module registration input
This commit is contained in:
Vadim Levin
2022-01-19 00:07:50 +03:00
parent 25f25275cd
commit eca2d92791
3 changed files with 184 additions and 36 deletions
+15
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env python
from __future__ import print_function
import sys
import ctypes
from functools import partial
from collections import namedtuple
@@ -596,6 +597,20 @@ class Arguments(NewOpenCVTests):
self.assertTrue(isinstance(rr, tuple), msg=type(rrv))
self.assertEqual(len(rr), 3)
def test_nested_function_availability(self):
self.assertTrue(hasattr(cv.utils, "nested"),
msg="Module is not generated for nested namespace")
self.assertTrue(hasattr(cv.utils.nested, "testEchoBooleanFunction"),
msg="Function in nested module is not available")
self.assertEqual(sys.getrefcount(cv.utils.nested), 2,
msg="Nested submodule lifetime should be managed by "
"the parent module so the reference count should be "
"2, because `getrefcount` temporary increases it.")
for flag in (True, False):
self.assertEqual(flag, cv.utils.nested.testEchoBooleanFunction(flag),
msg="Function in nested module returns wrong result")
class SamplesFindFile(NewOpenCVTests):
def test_ExistedFile(self):