fix: wrong reference counter after module initialization

This commit is contained in:
Vadim Levin
2022-01-27 12:04:56 +03:00
parent 16661847a7
commit ef85b24a78
2 changed files with 21 additions and 9 deletions
+12 -4
View File
@@ -602,10 +602,18 @@ class Arguments(NewOpenCVTests):
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.")
# Nested submodule is managed by the global submodules dictionary
# and parent native module
expected_ref_count = 2
# `getrefcount` temporary increases reference counter by 1
actual_ref_count = sys.getrefcount(cv.utils.nested) - 1
self.assertEqual(actual_ref_count, expected_ref_count,
msg="Nested submodule reference counter has wrong value\n"
"Expected: {}. Actual: {}".format(expected_ref_count, actual_ref_count))
for flag in (True, False):
self.assertEqual(flag, cv.utils.nested.testEchoBooleanFunction(flag),
msg="Function in nested module returns wrong result")