| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
import keyword |
| 19 |
|
| 20 |
import pytest |
| 21 |
|
| 22 |
import jpype |
| 23 |
import common |
| 24 |
|
| 25 |
|
| 26 |
@pytest.mark.parametrize( |
| 27 |
"identifier", |
| 28 |
list(keyword.kwlist) + [ |
| 29 |
'__del__', |
| 30 |
|
| 31 |
|
| 32 |
'print', |
| 33 |
'____', |
| 34 |
] |
| 35 |
) |
| 36 |
def testPySafe__Keywords(identifier): |
| 37 |
safe = jpype._pykeywords.pysafe(identifier) |
| 38 |
if identifier.startswith("__"): |
| 39 |
assert safe is None |
| 40 |
else: |
| 41 |
assert isinstance(safe, str), f"Fail on keyword {identifier}" |
| 42 |
assert safe.endswith("_") |
| 43 |
|
| 44 |
|
| 45 |
@pytest.mark.parametrize( |
| 46 |
"identifier", |
| 47 |
[ |
| 48 |
'notSpecial', |
| 49 |
'__notSpecial', |
| 50 |
'notSpecial__', |
| 51 |
'_notSpecial_', |
| 52 |
'_not__special_', |
| 53 |
'__', '___', |
| 54 |
]) |
| 55 |
def testPySafe__NotKeywords(identifier): |
| 56 |
safe = jpype._pykeywords.pysafe(identifier) |
| 57 |
assert safe == identifier |
| 58 |
|
| 59 |
|
| 60 |
class AttributeTestCase(common.JPypeTestCase): |
| 61 |
def testPySafe(self): |
| 62 |
cls = jpype.JPackage("jpype").attr.TestKeywords |
| 63 |
self.assertTrue(hasattr(cls, "__leading_double_underscore")) |
| 64 |
self.assertFalse(hasattr(cls, "__dunder_name__")) |