pyobjc / pyobjc-framework-Cocoa / PyObjCTest /

from PyObjCTools.TestSupport import *
import os

from Foundation import *

except NameError:
    unicode = str

class TestNSJavaSetup (TestCase):
    def testConstants(self):
        self.assertIsInstance(NSJavaClasses, unicode)
        self.assertIsInstance(NSJavaRoot, unicode)
        self.assertIsInstance(NSJavaPath, unicode)
        self.assertIsInstance(NSJavaUserPath, unicode)
        self.assertIsInstance(NSJavaLibraryPath, unicode)
        self.assertIsInstance(NSJavaOwnVirtualMachine, unicode)
        self.assertIsInstance(NSJavaPathSeparator, unicode)
        self.assertIsInstance(NSJavaWillSetupVirtualMachineNotification, unicode)
        self.assertIsInstance(NSJavaDidSetupVirtualMachineNotification, unicode)
        self.assertIsInstance(NSJavaWillCreateVirtualMachineNotification, unicode)
        self.assertIsInstance(NSJavaDidCreateVirtualMachineNotification, unicode)
    def testFunctions(self):
        v = NSJavaNeedsVirtualMachine({})
        self.assertIs(v, False)
        v = NSJavaProvidesClasses({})
        self.assertIs(v, False)
        v = NSJavaNeedsToLoadClasses({})
        self.assertIs(v, False)
        vm = NSJavaSetup({})
        self.assertIsInstance(vm, objc.objc_object)
        v = NSJavaSetupVirtualMachine()
        self.assertIsInstance(v, objc.objc_object)
        v = NSJavaObjectNamedInPath("java.lang.Object", None)
        self.assertIsInstance(v, objc.objc_object)
        v, vm = NSJavaClassesFromPath(None, ['java.lang.Object'], True, None)
        self.assertIsInstance(v, NSArray)
        self.assertEqual(len(v), 1)
        self.assertIsInstance(vm, objc.objc_object)
        v, vm = NSJavaClassesForBundle(NSBundle.mainBundle(), True, None)
        self.assertIsInstance(v, NSArray)
        self.assertEqual(len(v), 0)
        self.assertIsInstance(vm, objc.objc_object)
        vm = NSJavaBundleSetup(NSBundle.mainBundle(), {})
        self.assertIsInstance(vm, objc.objc_object)
        # FIXME: NSJavaBundleCleanup gives an exception
        # This seems to be related to the way we call these APIs and I don't
        # plan to fix is (there is no problem with PyObjC or the Foundation
        # wrappers)
        fd = os.dup(2)
        x ='/dev/null', os.O_WRONLY)
        os.dup2(x, 2)
                NSJavaBundleCleanup(NSBundle.mainBundle(), {})
            except ValueError:
            os.dup2(fd, 2)

if __name__ == "__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
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.