python 3.6.15 test_13_wrapping_module fails
Closed this issue · 2 comments
sundarnagarajan commented
FAIL: test_13_wrapping_module (main.test_pyprotect)
Traceback (most recent call last):
File "test_pyprotect.py", line 879, in test_13_wrapping_module
t.module_attr_not_in_dir
AssertionError: Exception not raised
sundarnagarajan commented
Fixed. python3 < 3.6 belongs like python3 in not considering dir for modules
-- a/pyprotect/Private_FrozenPrivate.pxi
+++ b/pyprotect/Private_FrozenPrivate.pxi
@@ -32,14 +32,20 @@ cdef class Private(Wrapped):
return False
if a not in dir(self.pvt_o):
return False
- # Special hack for PY2 that does not seem to obey __dir__ for modules
- if PY2 and isinstance(self.pvt_o, types.ModuleType):
- if (
- hasattr(self.pvt_o, '__dir__') and
- callable(self.pvt_o.__dir__)
- ):
- if a not in self.pvt_o.__dir__():
- return False
+ # Special case for PY2 that does not seem to obey __dir__ for modules
+ # Also applies to PY3 < 3.7
+ if (
+ isinstance(self.pvt_o, types.ModuleType) and
+ (
+ PY2 or (sys.version_info.major, sys.version_info.minor) < (3, 7)
+ )
+ ):
+ if (
+ hasattr(self.pvt_o, '__dir__') and
+ callable(self.pvt_o.__dir__)
+ ):
+ if a not in self.pvt_o.__dir__():
+ return False
return True
cdef private_writeable(self, a):
Also fixed an issue in tests/cls_gen.py
Python3 < 3.6 does not have random.choices - so we treat it like PY2
--- a/tests/cls_gen.py
+++ b/tests/cls_gen.py
@@ -4,7 +4,12 @@ Utilities to generate test classes
import sys
sys.dont_write_bytecode = True
-if sys.version_info.major == 2:
+if (
+ sys.version_info.major == 2 or
+ (
+ (sys.version_info.major, sys.version_info.minor) < (3, 6)
+ )
+):
from random import sample as choices
else:
from random import choices
sundarnagarajan commented
Fixed in f91fa14