1from PyObjCTools.TestSupport import * 2import objc 3import os 4 5from AppKit import * 6 7try: 8 unicode 9except NameError: 10 unicode = str 11 12 13class TestNSWorkspace(TestCase): 14 def testInfoForFile(self): 15 ws = NSWorkspace.sharedWorkspace() 16 17 # A method with 2 output parameters, this means the result 18 # is a tuple with 3 elements (return value, param1, param2) 19 res = ws.getInfoForFile_application_type_(b'/'.decode('ascii'), None, None) 20 self.assert_(isinstance(res, tuple)) 21 self.assert_(len(res) == 3) 22 self.assert_(res[0] == 1) 23 self.assert_(res[1] == b'/System/Library/CoreServices/Finder.app'.decode('ascii')) 24 self.assert_(res[2] == b''.decode('ascii')) 25 26 def testConstants(self): 27 self.assertEqual(NSWorkspaceLaunchAndPrint, 2) 28 self.assertEqual(NSWorkspaceLaunchInhibitingBackgroundOnly, 0x00000080) 29 self.assertEqual(NSWorkspaceLaunchWithoutAddingToRecents, 0x00000100) 30 self.assertEqual(NSWorkspaceLaunchWithoutActivation, 0x00000200) 31 self.assertEqual(NSWorkspaceLaunchAsync, 0x00010000) 32 self.assertEqual(NSWorkspaceLaunchAllowingClassicStartup, 0x00020000) 33 self.assertEqual(NSWorkspaceLaunchPreferringClassic, 0x00040000) 34 self.assertEqual(NSWorkspaceLaunchNewInstance, 0x00080000) 35 self.assertEqual(NSWorkspaceLaunchAndHide, 0x00100000) 36 self.assertEqual(NSWorkspaceLaunchAndHideOthers, 0x00200000) 37 self.assertEqual(NSWorkspaceLaunchDefault, ( 38 NSWorkspaceLaunchAsync | NSWorkspaceLaunchAllowingClassicStartup)) 39 40 self.assertEqual(NSExcludeQuickDrawElementsIconCreationOption, 1 << 1) 41 self.assertEqual(NSExclude10_4ElementsIconCreationOption, 1 << 2) 42 43 self.assertIsInstance(NSWorkspaceDidLaunchApplicationNotification, unicode) 44 self.assertIsInstance(NSWorkspaceDidMountNotification, unicode) 45 self.assertIsInstance(NSWorkspaceDidPerformFileOperationNotification, unicode) 46 self.assertIsInstance(NSWorkspaceDidTerminateApplicationNotification, unicode) 47 self.assertIsInstance(NSWorkspaceDidUnmountNotification, unicode) 48 self.assertIsInstance(NSWorkspaceWillLaunchApplicationNotification, unicode) 49 self.assertIsInstance(NSWorkspaceWillPowerOffNotification, unicode) 50 self.assertIsInstance(NSWorkspaceWillUnmountNotification, unicode) 51 self.assertIsInstance(NSWorkspaceWillSleepNotification, unicode) 52 self.assertIsInstance(NSWorkspaceDidWakeNotification, unicode) 53 self.assertIsInstance(NSWorkspaceSessionDidBecomeActiveNotification, unicode) 54 self.assertIsInstance(NSWorkspaceSessionDidResignActiveNotification, unicode) 55 self.assertIsInstance(NSPlainFileType, unicode) 56 self.assertIsInstance(NSDirectoryFileType, unicode) 57 self.assertIsInstance(NSApplicationFileType, unicode) 58 self.assertIsInstance(NSFilesystemFileType, unicode) 59 self.assertIsInstance(NSShellCommandFileType, unicode) 60 self.assertIsInstance(NSWorkspaceMoveOperation, unicode) 61 self.assertIsInstance(NSWorkspaceCopyOperation, unicode) 62 self.assertIsInstance(NSWorkspaceLinkOperation, unicode) 63 self.assertIsInstance(NSWorkspaceCompressOperation, unicode) 64 self.assertIsInstance(NSWorkspaceDecompressOperation, unicode) 65 self.assertIsInstance(NSWorkspaceEncryptOperation, unicode) 66 self.assertIsInstance(NSWorkspaceDecryptOperation, unicode) 67 self.assertIsInstance(NSWorkspaceDestroyOperation, unicode) 68 self.assertIsInstance(NSWorkspaceRecycleOperation, unicode) 69 self.assertIsInstance(NSWorkspaceDuplicateOperation, unicode) 70 @min_os_level('10.6') 71 def testConstants10_6(self): 72 self.assertIsInstance(NSWorkspaceDesktopImageScalingKey, unicode) 73 self.assertIsInstance(NSWorkspaceDesktopImageAllowClippingKey, unicode) 74 self.assertIsInstance(NSWorkspaceDesktopImageFillColorKey, unicode) 75 self.assertIsInstance(NSWorkspaceApplicationKey, unicode) 76 self.assertIsInstance(NSWorkspaceDidHideApplicationNotification, unicode) 77 self.assertIsInstance(NSWorkspaceDidUnhideApplicationNotification, unicode) 78 self.assertIsInstance(NSWorkspaceDidActivateApplicationNotification, unicode) 79 self.assertIsInstance(NSWorkspaceDidDeactivateApplicationNotification, unicode) 80 self.assertIsInstance(NSWorkspaceVolumeLocalizedNameKey, unicode) 81 self.assertIsInstance(NSWorkspaceVolumeURLKey, unicode) 82 self.assertIsInstance(NSWorkspaceVolumeOldLocalizedNameKey, unicode) 83 self.assertIsInstance(NSWorkspaceVolumeOldURLKey, unicode) 84 self.assertIsInstance(NSWorkspaceDidRenameVolumeNotification, unicode) 85 self.assertIsInstance(NSWorkspaceScreensDidSleepNotification, unicode) 86 self.assertIsInstance(NSWorkspaceScreensDidWakeNotification, unicode) 87 self.assertIsInstance(NSWorkspaceDidChangeFileLabelsNotification, unicode) 88 self.assertIsInstance(NSWorkspaceActiveSpaceDidChangeNotification, unicode) 89 self.assertIsInstance(NSWorkspaceLaunchConfigurationAppleEvent, unicode) 90 self.assertIsInstance(NSWorkspaceLaunchConfigurationArguments, unicode) 91 self.assertIsInstance(NSWorkspaceLaunchConfigurationEnvironment, unicode) 92 self.assertIsInstance(NSWorkspaceLaunchConfigurationArchitecture, unicode) 93 94 95 def testMethods(self): 96 self.assertResultIsBOOL(NSWorkspace.openFile_) 97 self.assertResultIsBOOL(NSWorkspace.openFile_withApplication_) 98 self.assertResultIsBOOL(NSWorkspace.openFile_withApplication_andDeactivate_) 99 self.assertArgIsBOOL(NSWorkspace.openFile_withApplication_andDeactivate_, 2) 100 self.assertResultIsBOOL(NSWorkspace.openTempFile_) 101 self.assertResultIsBOOL(NSWorkspace.openFile_fromImage_at_inView_) 102 self.assertResultIsBOOL(NSWorkspace.openURL_) 103 self.assertResultIsBOOL(NSWorkspace.launchApplication_) 104 self.assertResultIsBOOL(NSWorkspace.launchApplication_showIcon_autolaunch_) 105 self.assertArgIsBOOL(NSWorkspace.launchApplication_showIcon_autolaunch_, 1) 106 self.assertArgIsBOOL(NSWorkspace.launchApplication_showIcon_autolaunch_, 2) 107 self.assertResultIsBOOL(NSWorkspace.selectFile_inFileViewerRootedAtPath_) 108 self.assertResultIsBOOL(NSWorkspace.fileSystemChanged) 109 self.assertResultIsBOOL(NSWorkspace.userDefaultsChanged) 110 self.assertResultIsBOOL(NSWorkspace.getInfoForFile_application_type_) 111 self.assertArgIsOut(NSWorkspace.getInfoForFile_application_type_, 1) 112 self.assertArgIsOut(NSWorkspace.getInfoForFile_application_type_, 2) 113 self.assertResultIsBOOL(NSWorkspace.isFilePackageAtPath_) 114 self.assertResultIsBOOL(NSWorkspace.setIcon_forFile_options_) 115 self.assertResultIsBOOL(NSWorkspace.getFileSystemInfoForPath_isRemovable_isWritable_isUnmountable_description_type_) 116 self.assertArgHasType(NSWorkspace.getFileSystemInfoForPath_isRemovable_isWritable_isUnmountable_description_type_, 1, b'o^' + objc._C_NSBOOL) 117 self.assertArgHasType(NSWorkspace.getFileSystemInfoForPath_isRemovable_isWritable_isUnmountable_description_type_, 2, b'o^' + objc._C_NSBOOL) 118 self.assertArgHasType(NSWorkspace.getFileSystemInfoForPath_isRemovable_isWritable_isUnmountable_description_type_, 3, b'o^' + objc._C_NSBOOL) 119 self.assertArgIsOut(NSWorkspace.getFileSystemInfoForPath_isRemovable_isWritable_isUnmountable_description_type_, 4) 120 self.assertArgIsOut(NSWorkspace.getFileSystemInfoForPath_isRemovable_isWritable_isUnmountable_description_type_, 5) 121 self.assertResultIsBOOL(NSWorkspace.performFileOperation_source_destination_files_tag_) 122 self.assertArgIsOut(NSWorkspace.performFileOperation_source_destination_files_tag_, 4) 123 self.assertResultIsBOOL(NSWorkspace.unmountAndEjectDeviceAtPath_) 124 self.assertResultIsBOOL(NSWorkspace.launchAppWithBundleIdentifier_options_additionalEventParamDescriptor_launchIdentifier_) 125 self.assertArgIsOut(NSWorkspace.launchAppWithBundleIdentifier_options_additionalEventParamDescriptor_launchIdentifier_, 3) 126 self.assertResultIsBOOL(NSWorkspace.openURLs_withAppBundleIdentifier_options_additionalEventParamDescriptor_launchIdentifiers_) 127 self.assertArgIsOut(NSWorkspace.openURLs_withAppBundleIdentifier_options_additionalEventParamDescriptor_launchIdentifiers_, 4) 128 self.assertArgIsOut(NSWorkspace.typeOfFile_error_, 1) 129 self.assertResultIsBOOL(NSWorkspace.filenameExtension_isValidForType_) 130 self.assertResultIsBOOL(NSWorkspace.type_conformsToType_) 131 132 self.assertResultIsBOOL(NSWorkspace.selectFile_inFileViewerRootedAtPath_) 133 self.assertArgHasType(NSWorkspace.slideImage_from_to_, 1, NSPoint.__typestr__) 134 self.assertArgHasType(NSWorkspace.slideImage_from_to_, 2, NSPoint.__typestr__) 135 136 @min_os_level('10.6') 137 def testMethods10_6(self): 138 self.assertArgIsOut(NSWorkspace.launchApplicationAtURL_options_configuration_error_, 3) 139 self.assertResultIsBOOL(NSWorkspace.showSearchResultsForQueryString_) 140 141 self.assertArgIsBlock(NSWorkspace.recycleURLs_completionHandler_, 1, b'v@@') 142 self.assertArgIsBlock(NSWorkspace.duplicateURLs_completionHandler_, 1, b'v@@') 143 144 self.assertResultIsBOOL(NSWorkspace.unmountAndEjectDeviceAtURL_error_) 145 self.assertArgIsOut(NSWorkspace.unmountAndEjectDeviceAtURL_error_, 1) 146 147 self.assertResultIsBOOL(NSWorkspace.setDesktopImageURL_forScreen_options_error_) 148 self.assertArgIsOut(NSWorkspace.setDesktopImageURL_forScreen_options_error_, 3) 149 150 151if __name__ == '__main__': 152 main( ) 153