-
Notifications
You must be signed in to change notification settings - Fork 24
/
test_nsfilemanager.py
261 lines (216 loc) · 15 KB
/
test_nsfilemanager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
from PyObjCTools.TestSupport import *
from Foundation import *
class TestNSFileManagerHelper (NSObject):
def fileManager_shouldProceedAfterError_(self, a, b): return 1
def fileManager_willProcessPath_(self, a, b): pass
def fileManager_shouldCopyItemAtPath_toPath_(self, a, b, c): return 1
def fileManager_shouldProceedAfterError_copyingItemAtPath_toPath_(self, a, b, c, d): return 1
def fileManager_shouldMoveItemAtPath_toPath_(self, a, b, c): return 1
def fileManager_shouldProceedAfterError_movingItemAtPath_toPath_(self, a, b, c, d): return 1
def fileManager_shouldLinkItemAtPath_toPath_(self, a, b, c): return 1
def fileManager_shouldProceedAfterError_linkingItemAtPath_toPath_(self, a, b, c, d): return 1
def fileManager_shouldRemoveItemAtPath_(self, a, b): return 1
def fileManager_shouldProceedAfterError_removingItemAtPath_(self, a, b, c): return 1
def fileManager_shouldCopyItemAtURL_toURL_(self, a, b, c): return 1
def fileManager_shouldProceedAfterError_copyingItemAtURL_toURL_(self, a, b, c, d): return 1
def fileManager_shouldMoveItemAtURL_toURL_(self, a, b, c): return 1
def fileManager_shouldProceedAfterError_movingItemAtURL_toURL_(self, a, b, c, d): return 1
def fileManager_shouldLinkItemAtURL_toURL_(self, a, b, c): return 1
def fileManager_shouldProceedAfterError_linkingItemAtURL_toURL_(self, a, b, c, d): return 1
def fileManager_shouldRemoveItemAtURL_(self, a, b): return 1
def fileManager_shouldProceedAfterError_removingItemAtURL_(self, a, b, c): return 1
class TestNSFileManager (TestCase):
def testConstants(self):
self.assertEqual(NSFoundationVersionWithFileManagerResourceForkSupport, 412)
self.assertIsInstance(NSFileType, unicode)
self.assertIsInstance(NSFileTypeDirectory, unicode)
self.assertIsInstance(NSFileTypeRegular, unicode)
self.assertIsInstance(NSFileTypeSymbolicLink, unicode)
self.assertIsInstance(NSFileTypeSocket, unicode)
self.assertIsInstance(NSFileTypeCharacterSpecial, unicode)
self.assertIsInstance(NSFileTypeBlockSpecial, unicode)
self.assertIsInstance(NSFileTypeUnknown, unicode)
self.assertIsInstance(NSFileSize, unicode)
self.assertIsInstance(NSFileModificationDate, unicode)
self.assertIsInstance(NSFileReferenceCount, unicode)
self.assertIsInstance(NSFileDeviceIdentifier, unicode)
self.assertIsInstance(NSFileOwnerAccountName, unicode)
self.assertIsInstance(NSFileGroupOwnerAccountName, unicode)
self.assertIsInstance(NSFilePosixPermissions, unicode)
self.assertIsInstance(NSFileSystemNumber, unicode)
self.assertIsInstance(NSFileSystemFileNumber, unicode)
self.assertIsInstance(NSFileExtensionHidden, unicode)
self.assertIsInstance(NSFileHFSCreatorCode, unicode)
self.assertIsInstance(NSFileHFSTypeCode, unicode)
self.assertIsInstance(NSFileImmutable, unicode)
self.assertIsInstance(NSFileAppendOnly, unicode)
self.assertIsInstance(NSFileCreationDate, unicode)
self.assertIsInstance(NSFileOwnerAccountID, unicode)
self.assertIsInstance(NSFileGroupOwnerAccountID, unicode)
self.assertIsInstance(NSFileBusy, unicode)
self.assertIsInstance(NSFileSystemSize, unicode)
self.assertIsInstance(NSFileSystemFreeSize, unicode)
self.assertIsInstance(NSFileSystemNodes, unicode)
self.assertIsInstance(NSFileSystemFreeNodes, unicode)
@min_os_level('10.6')
def testConstants10_6(self):
self.assertEqual(NSVolumeEnumerationSkipHiddenVolumes, 1<<1)
self.assertEqual(NSVolumeEnumerationProduceFileReferenceURLs, 1<<2)
self.assertEqual(NSDirectoryEnumerationSkipsSubdirectoryDescendants, 1<<0)
self.assertEqual(NSDirectoryEnumerationSkipsPackageDescendants, 1<<1)
self.assertEqual(NSDirectoryEnumerationSkipsHiddenFiles, 1<<2)
self.assertEqual(NSFileManagerItemReplacementUsingNewMetadataOnly, 1<<0)
self.assertEqual(NSFileManagerItemReplacementWithoutDeletingBackupItem, 1<<1)
@min_os_level('10.6')
def testMethods10_6(self):
self.assertArgIsOut(NSFileManager.contentsOfDirectoryAtURL_includingPropertiesForKeys_options_error_, 3)
self.assertArgIsBOOL(NSFileManager.URLForDirectory_inDomain_appropriateForURL_create_error_, 3)
self.assertArgIsOut(NSFileManager.URLForDirectory_inDomain_appropriateForURL_create_error_, 4)
self.assertResultIsBOOL(NSFileManager.copyItemAtURL_toURL_error_)
self.assertArgIsOut(NSFileManager.copyItemAtURL_toURL_error_, 2)
self.assertResultIsBOOL(NSFileManager.moveItemAtURL_toURL_error_)
self.assertArgIsOut(NSFileManager.moveItemAtURL_toURL_error_, 2)
self.assertResultIsBOOL(NSFileManager.linkItemAtURL_toURL_error_)
self.assertArgIsOut(NSFileManager.linkItemAtURL_toURL_error_, 2)
self.assertResultIsBOOL(NSFileManager.removeItemAtURL_error_)
self.assertArgIsOut(NSFileManager.removeItemAtURL_error_, 1)
def testOutput(self):
obj = NSFileManager.defaultManager()
m = obj.setAttributes_ofItemAtPath_error_.__metadata__()
self.assertTrue(m['arguments'][4]['type'].startswith(b'o^'))
m = obj.createDirectoryAtPath_withIntermediateDirectories_attributes_error_.__metadata__()
self.assertEqual(m['arguments'][3]['type'] , b'Z')
self.assertTrue(m['arguments'][5]['type'].startswith(b'o^'))
m = obj.contentsOfDirectoryAtPath_error_.__metadata__()
self.assertTrue(m['arguments'][3]['type'].startswith(b'o^'))
m = obj.subpathsOfDirectoryAtPath_error_.__metadata__()
self.assertTrue(m['arguments'][3]['type'].startswith(b'o^'))
m = obj.attributesOfItemAtPath_error_.__metadata__()
self.assertTrue(m['arguments'][3]['type'].startswith(b'o^'))
m = obj.attributesOfFileSystemForPath_error_.__metadata__()
self.assertTrue(m['arguments'][3]['type'].startswith(b'o^'))
m = obj.createSymbolicLinkAtPath_withDestinationPath_error_.__metadata__()
self.assertTrue(m['arguments'][4]['type'].startswith(b'o^'))
m = obj.destinationOfSymbolicLinkAtPath_error_.__metadata__()
self.assertTrue(m['arguments'][3]['type'].startswith(b'o^'))
m = obj.copyItemAtPath_toPath_error_.__metadata__()
self.assertEqual(m['retval']['type'] , b'Z')
self.assertTrue(m['arguments'][4]['type'].startswith(b'o^'))
m = obj.moveItemAtPath_toPath_error_.__metadata__()
self.assertEqual(m['retval']['type'] , b'Z')
self.assertTrue(m['arguments'][4]['type'].startswith(b'o^'))
m = obj.linkItemAtPath_toPath_error_.__metadata__()
self.assertEqual(m['retval']['type'] , b'Z')
self.assertTrue(m['arguments'][4]['type'].startswith(b'o^'))
m = obj.removeItemAtPath_error_.__metadata__()
self.assertEqual(m['retval']['type'] , b'Z')
self.assertTrue(m['arguments'][3]['type'].startswith(b'o^'))
def testProtocols(self):
class FileManagerTest1 (NSObject):
def fileManager_shouldCopyItemAtPath_toPath_(self, fm, src, dst):
return True
def fileManager_shouldProceedAfterError_copyingItemAtPath_toPath_(self, fm, error, src, dst):
return True
def fileManager_shouldMoveItemAtPath_toPath_(self, fm, src, dst):
return True
def fileManager_shouldProceedAfterError_movingItemAtPath_toPath_(self, fm, error, src, dst):
return True
def fileManager_shouldLinkItemAtPath_toPath_(self, fm, src, dst):
return True
def fileManager_shouldProceedAfterError_linkingItemAtPath_toPath_(self, fm, error, src, dst):
return True
def fileManager_shouldRemoveItemAtPath_(self, fm, src):
return True
def fileManager_shouldProceedAfterError_removingItemAtPath_(self, fm, error, src):
return True
obj = FileManagerTest1.alloc().init()
m = obj.fileManager_shouldCopyItemAtPath_toPath_.__metadata__()
self.assertEqual(m['retval']['type'] , 'Z')
m = obj.fileManager_shouldProceedAfterError_copyingItemAtPath_toPath_.__metadata__()
self.assertEqual(m['retval']['type'] , 'Z')
m = obj.fileManager_shouldMoveItemAtPath_toPath_.__metadata__()
self.assertEqual(m['retval']['type'] , 'Z')
m = obj.fileManager_shouldProceedAfterError_movingItemAtPath_toPath_.__metadata__()
self.assertEqual(m['retval']['type'] , 'Z')
m = obj.fileManager_shouldLinkItemAtPath_toPath_.__metadata__()
self.assertEqual(m['retval']['type'] , 'Z')
m = obj.fileManager_shouldProceedAfterError_linkingItemAtPath_toPath_.__metadata__()
self.assertEqual(m['retval']['type'] , 'Z')
m = obj.fileManager_shouldRemoveItemAtPath_.__metadata__()
self.assertEqual(m['retval']['type'] , 'Z')
m = obj.fileManager_shouldProceedAfterError_removingItemAtPath_.__metadata__()
self.assertEqual(m['retval']['type'] , 'Z')
@min_os_level('10.5')
def testMethods10_5(self):
self.assertResultIsBOOL(NSFileManager.setAttributes_ofItemAtPath_error_)
self.assertArgIsOut(NSFileManager.setAttributes_ofItemAtPath_error_, 2)
self.assertResultIsBOOL(NSFileManager.createDirectoryAtPath_withIntermediateDirectories_attributes_error_)
self.assertArgIsBOOL(NSFileManager.createDirectoryAtPath_withIntermediateDirectories_attributes_error_, 1)
self.assertArgIsOut(NSFileManager.createDirectoryAtPath_withIntermediateDirectories_attributes_error_, 3)
self.assertArgIsOut(NSFileManager.contentsOfDirectoryAtPath_error_, 1)
self.assertArgIsOut(NSFileManager.subpathsOfDirectoryAtPath_error_, 1)
self.assertArgIsOut(NSFileManager.attributesOfItemAtPath_error_, 1)
self.assertArgIsOut(NSFileManager.attributesOfFileSystemForPath_error_, 1)
self.assertResultIsBOOL(NSFileManager.createSymbolicLinkAtPath_withDestinationPath_error_)
self.assertArgIsOut(NSFileManager.createSymbolicLinkAtPath_withDestinationPath_error_, 2)
self.assertArgIsOut(NSFileManager.destinationOfSymbolicLinkAtPath_error_, 1)
self.assertResultIsBOOL(NSFileManager.copyItemAtPath_toPath_error_)
self.assertArgIsOut(NSFileManager.copyItemAtPath_toPath_error_, 2)
self.assertResultIsBOOL(NSFileManager.moveItemAtPath_toPath_error_)
self.assertArgIsOut(NSFileManager.moveItemAtPath_toPath_error_, 2)
self.assertResultIsBOOL(NSFileManager.linkItemAtPath_toPath_error_)
self.assertArgIsOut(NSFileManager.linkItemAtPath_toPath_error_, 2)
self.assertResultIsBOOL(NSFileManager.removeItemAtPath_error_)
self.assertArgIsOut(NSFileManager.removeItemAtPath_error_, 1)
self.assertArgIsBlock(NSFileManager.enumeratorAtURL_includingPropertiesForKeys_options_errorHandler_, 3, objc._C_NSBOOL + b'@@')
self.assertResultIsBOOL(NSFileManager.replaceItemAtURL_withItemAtURL_backupItemName_options_resultingItemURL_error_)
self.assertArgIsOut(NSFileManager.replaceItemAtURL_withItemAtURL_backupItemName_options_resultingItemURL_error_, 4)
self.assertArgIsOut(NSFileManager.replaceItemAtURL_withItemAtURL_backupItemName_options_resultingItemURL_error_, 5)
def testMethods(self):
self.assertArgIsBOOL(NSFileManager.fileAttributesAtPath_traverseLink_, 1)
self.assertResultIsBOOL(NSFileManager.changeFileAttributes_atPath_)
self.assertResultIsBOOL(NSFileManager.createSymbolicLinkAtPath_pathContent_)
self.assertResultIsBOOL(NSFileManager.createDirectoryAtPath_attributes_)
self.assertResultIsBOOL(NSFileManager.linkPath_toPath_handler_)
self.assertResultIsBOOL(NSFileManager.copyPath_toPath_handler_)
self.assertResultIsBOOL(NSFileManager.movePath_toPath_handler_)
self.assertResultIsBOOL(NSFileManager.removeFileAtPath_handler_)
self.assertResultIsBOOL(NSFileManager.changeCurrentDirectoryPath_)
self.assertResultIsBOOL(NSFileManager.fileExistsAtPath_)
self.assertResultIsBOOL(NSFileManager.fileExistsAtPath_isDirectory_)
self.assertArgHasType(NSFileManager.fileExistsAtPath_isDirectory_, 1, b'o^' + objc._C_NSBOOL)
self.assertResultIsBOOL(NSFileManager.isReadableFileAtPath_)
self.assertResultIsBOOL(NSFileManager.isWritableFileAtPath_)
self.assertResultIsBOOL(NSFileManager.isExecutableFileAtPath_)
self.assertResultIsBOOL(NSFileManager.isDeletableFileAtPath_)
self.assertResultIsBOOL(NSFileManager.contentsEqualAtPath_andPath_)
self.assertResultIsBOOL(NSFileManager.createFileAtPath_contents_attributes_)
self.assertResultHasType(NSFileManager.fileSystemRepresentationWithPath_, b'^' + objc._C_CHAR_AS_TEXT)
self.assertResultIsNullTerminated(NSFileManager.fileSystemRepresentationWithPath_)
self.assertArgHasType(NSFileManager.stringWithFileSystemRepresentation_length_, 0, b'n^' + objc._C_CHAR_AS_TEXT)
self.assertArgSizeInArg(NSFileManager.stringWithFileSystemRepresentation_length_, 0, 1)
self.assertResultIsBOOL(NSDictionary.fileIsImmutable)
self.assertResultIsBOOL(NSDictionary.fileIsAppendOnly)
self.assertResultIsBOOL(NSDictionary.fileExtensionHidden)
def testProtocols(self):
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldProceedAfterError_)
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldCopyItemAtPath_toPath_)
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldProceedAfterError_copyingItemAtPath_toPath_)
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldMoveItemAtPath_toPath_)
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldProceedAfterError_movingItemAtPath_toPath_)
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldLinkItemAtPath_toPath_)
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldProceedAfterError_linkingItemAtPath_toPath_)
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldRemoveItemAtPath_)
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldProceedAfterError_removingItemAtPath_)
@min_os_level('10.6')
def testProtocols10_6(self):
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldCopyItemAtURL_toURL_)
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldProceedAfterError_copyingItemAtURL_toURL_)
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldMoveItemAtURL_toURL_)
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldProceedAfterError_movingItemAtURL_toURL_)
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldLinkItemAtURL_toURL_)
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldProceedAfterError_linkingItemAtURL_toURL_)
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldRemoveItemAtURL_)
self.assertResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldProceedAfterError_removingItemAtURL_)
if __name__ == '__main__':
main()