@@ -60,37 +60,40 @@ def testTypesAndClasses(self):
60
60
61
61
@onlyPython2
62
62
def testStrConversion (self ):
63
- curEnabledFlag = objc .getStrBridgeEnabled ()
64
- objc .setStrBridgeEnabled (True )
65
- try :
66
- v = NSString .stringWithString_ ("hello2" )
67
- self .assertIsInstance (v , objc .pyobjc_unicode )
68
- self .assertEqual (v , b"hello2" .decode ('ascii' ))
63
+ with warnings .catch_warnings ():
64
+ warnings .filterwarnings ("ignore" )
69
65
66
+ curEnabledFlag = objc .getStrBridgeEnabled ()
67
+ objc .setStrBridgeEnabled (True )
68
+ try :
69
+ v = NSString .stringWithString_ ("hello2" )
70
+ self .assertIsInstance (v , objc .pyobjc_unicode )
71
+ self .assertEqual (v , b"hello2" .decode ('ascii' ))
70
72
71
- self .assertRaises (UnicodeError , unicode , "\xff " )
72
- # XXX: string bridge now uses the default NSString encoding
73
- # self.assertRaises(UnicodeError, NSString.stringWithString_, '\xff')
74
73
75
- objc .setStrBridgeEnabled (False )
74
+ self .assertRaises (UnicodeError , unicode , "\xff " )
75
+ # XXX: string bridge now uses the default NSString encoding
76
+ # self.assertRaises(UnicodeError, NSString.stringWithString_, '\xff')
76
77
77
- warnings .filterwarnings ('error' , category = objc .PyObjCStrBridgeWarning )
78
- try :
79
- #v = NSString.stringWithString_("hello")
78
+ objc .setStrBridgeEnabled (False )
80
79
81
- # we need to make sure that the str is unique
82
- # because an already bridged one might have crossed
83
- # and would be cached
84
- newString = type ('test_str' , (str ,), {})('hello2' )
85
- self .assertRaises (objc .PyObjCStrBridgeWarning ,
86
- NSString .stringWithString_ , newString )
80
+ warnings .filterwarnings ('error' , category = objc .PyObjCStrBridgeWarning )
81
+ try :
82
+ #v = NSString.stringWithString_("hello")
87
83
88
- finally :
89
- del warnings .filters [0 ]
84
+ # we need to make sure that the str is unique
85
+ # because an already bridged one might have crossed
86
+ # and would be cached
87
+ newString = type ('test_str' , (str ,), {})('hello2' )
88
+ self .assertRaises (objc .PyObjCStrBridgeWarning ,
89
+ NSString .stringWithString_ , newString )
90
90
91
+ finally :
92
+ del warnings .filters [0 ]
91
93
92
- finally :
93
- objc .setStrBridgeEnabled (curEnabledFlag )
94
+
95
+ finally :
96
+ objc .setStrBridgeEnabled (curEnabledFlag )
94
97
95
98
def testNSStringMethodAccess (self ):
96
99
self .assertIsInstance (self .nsUniString , objc .pyobjc_unicode )
0 commit comments