Source

pyobjc / pyobjc-core / PyObjCTest / test3_typecheck.py

from PyObjCTools.TestSupport import *
import objc

class TestPython3Types (TestCase):
    # Add tests here for all metadata and function arguments (when py3k and py2
    # behaviour is different)

    def testSelectorArguments(self):
        self.assertRaises(TypeError, objc.selector, "hello", signature=b"v@:")
        self.assertRaises(TypeError, objc.selector, b"hello", signature="v@:")

    def testSelectorAttributes(self):
        o = objc.lookUpClass('NSObject').alloc().init()

        m = o.description
        self.assertIsInstance(m.selector, bytes)
        self.assertIsInstance(m.signature, bytes)

        meta = m.__metadata__()
        self.assertIsInstance(meta['retval']['type'], bytes)
        for a in meta['arguments']:
            self.assertIsInstance(a['type'], bytes)

    def testFunctionLookup(self):
        NSBundle = objc.lookUpClass('NSBundle')
        bundle = NSBundle.bundleForClass_(NSBundle)

        tab = [
                ( 'NSHomeDirectory', b'@'),
        ]
        d = {}
        objc.loadBundleFunctions(bundle, d, tab)
        self.assertIn('NSHomeDirectory', d)


        tab = [
                ( 'NSHomeDirectory', '@'),
        ]
        self.assertRaises(TypeError, objc.loadBundleFunctions, bundle, d, tab)

        tab = [
                ( b'NSHomeDirectory', b'@'),
        ]
        self.assertRaises(TypeError, objc.loadBundleFunctions, bundle, d, tab)

    def testVariableLookup(self):
        NSBundle = objc.lookUpClass('NSBundle')
        bundle = NSBundle.bundleForClass_(NSBundle)

        tab = [
            ('NSAppleScriptErrorMessage', b'@'),
        ]

        d = {}
        objc.loadBundleVariables(bundle, d, tab)
        self.assertIn('NSAppleScriptErrorMessage', d)



        tab = [
            ('NSAppleScriptErrorMessage', '@'),
        ]

        self.assertRaises(TypeError, objc.loadBundleVariables, bundle, d, tab)

        tab = [
            (b'NSAppleScriptErrorMessage', b'@'),
        ]

        self.assertRaises(TypeError, objc.loadBundleVariables, bundle, d, tab)



if __name__ == "__main__":
    main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.