10 class TestFile(unittest.TestCase):
12 self._f = open("file.txt", "w+")
13 self.file = gio.File("file.txt")
17 if os.path.exists('file.txt'):
20 def testReadAsync(self):
21 self._f.write("testing")
24 def callback(file, result):
26 stream = file.read_finish(result)
27 self.failUnless(isinstance(stream, gio.InputStream))
28 self.assertEquals(stream.read(), "testing")
32 self.file.read_async(callback)
34 loop = glib.MainLoop()
37 def testAppendToAsync(self):
38 self._f.write("append_to ")
41 def callback(file, result):
43 stream = file.append_to_finish(result)
44 self.failUnless(isinstance(stream, gio.OutputStream))
45 w = stream.write("testing")
46 cont, leng, etag = self.file.load_contents()
47 self.assertEqual(cont, "append_to testing")
51 self.file.append_to_async(callback, gio.FILE_CREATE_NONE,
54 loop = glib.MainLoop()
57 def testAppendToAsyncNoargs(self):
58 self._f.write("append_to ")
61 def callback(file, result):
63 stream = file.append_to_finish(result)
64 self.failUnless(isinstance(stream, gio.OutputStream))
65 w = stream.write("testing")
66 cont, leng, etag = self.file.load_contents()
67 self.assertEqual(cont, "append_to testing")
71 self.file.append_to_async(callback)
73 loop = glib.MainLoop()
76 def testCreateAsync(self):
77 def callback(file, result):
79 stream = file.create_finish(result)
80 self.failUnless(isinstance(stream, gio.OutputStream))
81 w = stream.write("testing")
82 cont, leng, etag = file.load_contents()
83 self.assertEqual(cont, "testing")
85 if os.path.exists('temp.txt'):
89 gfile = gio.File("temp.txt")
90 gfile.create_async(callback, gio.FILE_CREATE_NONE,
93 loop = glib.MainLoop()
96 def testCreateReadWriteAsync(self):
97 def callback(file, result):
99 iostream = file.create_readwrite_finish(result)
100 self.failUnless(isinstance(iostream, gio.FileIOStream))
102 ostream = iostream.get_output_stream()
103 self.failUnless(isinstance(ostream, gio.OutputStream))
105 w = ostream.write("testing")
106 cont, leng, etag = file.load_contents()
107 self.assertEqual(cont, "testing")
109 if os.path.exists('temp.txt'):
110 os.unlink("temp.txt")
113 gfile = gio.File("temp.txt")
114 gfile.create_readwrite_async(callback, gio.FILE_CREATE_NONE,
117 loop = glib.MainLoop()
120 def testCreateAsyncNoargs(self):
121 def callback(file, result):
123 stream = file.create_finish(result)
124 self.failUnless(isinstance(stream, gio.OutputStream))
125 w = stream.write("testing")
126 cont, leng, etag = file.load_contents()
127 self.assertEqual(cont, "testing")
129 if os.path.exists('temp.txt'):
130 os.unlink("temp.txt")
133 gfile = gio.File("temp.txt")
134 gfile.create_async(callback)
136 loop = glib.MainLoop()
139 def testReplaceAsync(self):
140 self._f.write("testing")
143 def callback(file, result):
145 stream = file.replace_finish(result)
146 self.failUnless(isinstance(stream, gio.OutputStream))
147 stream.write("some new string")
149 cont, leng, etag = file.load_contents()
150 self.assertEqual(cont, "some new string")
155 self.file.replace_async(callback, None, True, gio.FILE_CREATE_NONE,
158 loop = glib.MainLoop()
161 def testReplaceAsyncNoargs(self):
162 self._f.write("testing")
165 def callback(file, result):
167 stream = file.replace_finish(result)
168 self.failUnless(isinstance(stream, gio.OutputStream))
169 stream.write("some new string")
171 cont, leng, etag = file.load_contents()
172 self.assertEqual(cont, "some new string")
177 self.file.replace_async(callback)
179 loop = glib.MainLoop()
182 def testReadAsyncError(self):
183 self.assertRaises(TypeError, self.file.read_async)
184 self.assertRaises(TypeError, self.file.read_async, "foo", "bar")
185 self.assertRaises(TypeError, self.file.read_async, "foo",
187 self.assertRaises(TypeError, self.file.read_async, "foo",
189 self.assertRaises(TypeError, self.file.read_async, "foo",
190 priority=1, cancellable="bar")
191 self.assertRaises(TypeError, self.file.read_async, "foo", 1, "bar")
193 def testConstructor(self):
194 for gfile in [gio.File("/"),
195 gio.File("file:///"),
196 gio.File(uri="file:///"),
199 gio.File(path=u"/")]:
200 self.failUnless(isinstance(gfile, gio.File))
201 self.assertEquals(gfile.get_path(), "/")
202 self.assertEquals(gfile.get_uri(), "file:///")
204 def testConstructorError(self):
205 self.assertRaises(TypeError, gio.File)
206 self.assertRaises(TypeError, gio.File, 1)
207 self.assertRaises(TypeError, gio.File, "foo", "bar")
208 self.assertRaises(TypeError, gio.File, foo="bar")
209 self.assertRaises(TypeError, gio.File, uri=1)
210 self.assertRaises(TypeError, gio.File, path=1)
212 def testLoadContents(self):
213 self._f.write("testing load_contents")
215 c = gio.Cancellable()
216 cont, leng, etag = self.file.load_contents(cancellable=c)
217 self.assertEqual(cont, "testing load_contents")
218 self.assertEqual(leng, 21)
219 self.assertNotEqual(etag, '')
221 def testLoadContentsAsync(self):
222 self._f.write("testing load_contents_async")
225 def callback(contents, result):
227 cont, leng, etag = contents.load_contents_finish(result)
228 self.assertEqual(cont, "testing load_contents_async")
229 self.assertEqual(leng, 27)
230 self.assertNotEqual(etag, '')
234 canc = gio.Cancellable()
235 self.file.load_contents_async(callback, cancellable=canc)
237 loop = glib.MainLoop()
240 def testQueryInfoAsync(self):
241 def callback(file, result):
243 info = file.query_info_finish(result)
244 self.failUnless(isinstance(info, gio.FileInfo))
245 self.failUnless(info.get_name(), "file.txt")
249 self.file.query_info_async("standard", callback)
251 loop = glib.MainLoop()
254 def testMountMountable(self):
255 gfile = gio.File('localtest:')
256 def unmount_done(mount, result):
258 retval = mount.unmount_finish(result)
259 self.failUnless(retval)
263 def mount_enclosing_volume_done(gfile, result):
266 retval = gfile.mount_enclosing_volume_finish(result)
268 # If we run the tests too fast
269 if e.code == gio.ERROR_ALREADY_MOUNTED:
270 print ('WARNING: testfile is already mounted, '
275 self.failUnless(retval)
278 mount = gfile.find_enclosing_mount()
282 mount.unmount(unmount_done)
284 mount_operation = gio.MountOperation()
285 gfile.mount_enclosing_volume(mount_operation,
286 mount_enclosing_volume_done)
288 loop = glib.MainLoop()
292 if os.path.exists('copy.txt'):
293 os.unlink("copy.txt")
295 source = gio.File('file.txt')
296 destination = gio.File('copy.txt')
298 retval = source.copy(destination)
299 self.failUnless(retval)
301 self.failUnless(os.path.exists('copy.txt'))
302 self.assertEqual(open('file.txt').read(),
303 open('copy.txt').read())
305 os.unlink("copy.txt")
308 def callback(current, total):
310 source = gio.File('file.txt')
311 destination = gio.File('copy.txt')
313 retval = source.copy(destination, callback)
314 self.failUnless(retval)
316 self.failUnless(os.path.exists('copy.txt'))
317 self.assertEqual(open('file.txt').read(),
318 open('copy.txt').read())
319 self.failUnless(self.called)
321 os.unlink("copy.txt")
323 def test_copy_async(self):
324 if os.path.exists('copy.txt'):
325 os.unlink("copy.txt")
327 source = gio.File('file.txt')
328 destination = gio.File('copy.txt')
330 def copied(source_, result):
332 self.assert_(source_ is source)
333 self.failUnless(source_.copy_finish(result))
337 def progress(current, total):
338 self.assert_(isinstance(current, long))
339 self.assert_(isinstance(total, long))
340 self.assert_(0 <= current <= total)
343 loop = glib.MainLoop()
344 source.copy_async(destination, copied, progress_callback = progress)
347 self.failUnless(os.path.exists('copy.txt'))
348 self.assertEqual(open('file.txt').read(),
349 open('copy.txt').read())
351 os.unlink("copy.txt")
354 def test_copy_progress(self):
355 source = gio.File('file.txt')
356 destination = gio.File('copy.txt')
358 def progress(current, total):
359 self.assert_(isinstance(current, long))
360 self.assert_(isinstance(total, long))
361 self.assert_(0 <= current <= total)
364 retval = source.copy(destination,
365 flags=gio.FILE_COPY_OVERWRITE,
366 progress_callback=progress)
367 self.failUnless(retval)
369 self.failUnless(os.path.exists('copy.txt'))
370 self.assertEqual(open('file.txt').read(),
371 open('copy.txt').read())
373 os.unlink("copy.txt")
376 if os.path.exists('move.txt'):
377 os.unlink("move.txt")
379 source = gio.File('file.txt')
380 destination = gio.File('move.txt')
381 retval = source.move(destination)
382 self.failUnless(retval)
384 self.failIf(os.path.exists('file.txt'))
385 self.failUnless(os.path.exists('move.txt'))
388 def callback(current, total):
390 source = gio.File('move.txt')
391 destination = gio.File('move-2.txt')
393 retval = source.move(destination, callback)
394 self.failUnless(retval)
396 self.failIf(os.path.exists('move.txt'))
397 self.failUnless(os.path.exists('move-2.txt'))
398 self.failUnless(self.called)
400 os.unlink("move-2.txt")
402 def testInfoList(self):
403 infolist = self.file.query_settable_attributes()
404 for info in infolist:
405 if info.name == "time::modified":
406 self.assertEqual(info.type, gio.FILE_ATTRIBUTE_TYPE_UINT64)
407 self.assertEqual(info.name, "time::modified")
408 self.assertEqual(info.flags,
409 gio.FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED |
410 gio.FILE_ATTRIBUTE_INFO_COPY_WITH_FILE)
412 def testQueryWritableNamespaces(self):
413 infolist = self.file.query_writable_namespaces()
414 for info in infolist:
415 if info.name == "xattr":
416 self.assertEqual(info.type, gio.FILE_ATTRIBUTE_TYPE_STRING)
418 def testSetAttribute(self):
419 self._f.write("testing attributes")
421 infolist = self.file.query_settable_attributes()
423 self.assertNotEqual(len(infolist), 0)
425 for info in infolist:
426 if info.name == "time::modified-usec":
427 ret = self.file.set_attribute("time::modified-usec",
428 gio.FILE_ATTRIBUTE_TYPE_UINT32,
429 10, gio.FILE_QUERY_INFO_NONE)
430 self.assertEqual(ret, True)
432 def testSetAttributesAsync(self):
433 def callback(gfile, result):
435 info = gfile.set_attributes_finish(result)
436 usec = info.get_attribute_uint32("time::modified-usec")
437 self.assertEqual(usec, 10)
441 info = gio.FileInfo()
442 info.set_attribute_uint32("time::modified-usec", 10)
444 canc = gio.Cancellable()
445 self.file.set_attributes_async(info, callback)
447 loop = glib.MainLoop()
450 def testReplaceContents(self):
451 self.file.replace_contents("testing replace_contents")
452 cont, leng, etag = self.file.load_contents()
453 self.assertEqual(cont, "testing replace_contents")
457 self.file.replace_contents("this won't work", etag="wrong")
459 self.assertEqual(e.code, gio.ERROR_WRONG_ETAG)
461 self.failUnless(caught)
463 self.file.replace_contents("testing replace_contents again", etag=etag)
464 cont, leng, etag = self.file.load_contents()
465 self.assertEqual(cont, "testing replace_contents again")
467 self.file.replace_contents("testing replace_contents yet again", etag=None)
468 cont, leng, etag = self.file.load_contents()
469 self.assertEqual(cont, "testing replace_contents yet again")
471 def testReplaceContentsAsync(self):
473 def callback(contents, result):
475 newetag = contents.replace_contents_finish(result)
476 cont, leng, etag = self.file.load_contents()
477 self.assertEqual(cont, "testing replace_contents_async")
478 self.assertEqual(leng, 30)
479 self.assertEqual(etag, newetag)
480 self.assertNotEqual(newetag, '')
484 canc = gio.Cancellable()
485 self.file.replace_contents_async("testing replace_contents_async", callback, cancellable=canc)
487 loop = glib.MainLoop()
491 self.assertEqual(gio.File('foo'),
493 self.assertNotEqual(gio.File('foo'),
497 self.assertEquals(hash(gio.File('foo')),
498 hash(gio.File('foo')))
500 def testSetDisplayNameAsync(self):
501 def callback(gfile, result):
503 new_gfile = gfile.set_display_name_finish(result)
504 new_name = new_gfile.get_basename()
505 self.assertEqual(new_name, "new.txt")
506 deleted = new_gfile.delete()
507 self.assertEqual(deleted, True)
511 canc = gio.Cancellable()
512 self.file.set_display_name_async("new.txt", callback, cancellable=canc)
514 loop = glib.MainLoop()
517 class TestGFileEnumerator(unittest.TestCase):
519 self.file = gio.File(os.path.dirname(__file__))
521 def testEnumerateChildren(self):
522 enumerator = self.file.enumerate_children(
523 "standard::*", gio.FILE_QUERY_INFO_NOFOLLOW_SYMLINKS)
524 for file_info in enumerator:
525 if file_info.get_name() == os.path.basename(__file__):
530 def testEnumerateChildrenAsync(self):
531 def callback(gfile, result):
533 for file_info in gfile.enumerate_children_finish(result):
534 if file_info.get_name() == __file__:
541 self.file.enumerate_children_async(
542 "standard::*", callback)
543 loop = glib.MainLoop()
546 def testNextFilesAsync(self):
547 def callback(enumerator, result):
549 for file_info in enumerator.next_files_finish(result):
550 if file_info.get_name() == __file__:
557 enumerator = self.file.enumerate_children(
558 "standard::*", gio.FILE_QUERY_INFO_NOFOLLOW_SYMLINKS)
559 enumerator.next_files_async(1000, callback)
560 loop = glib.MainLoop()
563 def testCloseFilesAsync(self):
564 def callback(enumerator, result):
566 enumerator.close_finish(result)
570 enumerator = self.file.enumerate_children(
571 "standard::*", gio.FILE_QUERY_INFO_NOFOLLOW_SYMLINKS)
573 enumerator.close_async(callback)
575 loop = glib.MainLoop()
579 class TestInputStream(unittest.TestCase):
581 self._f = open("inputstream.txt", "w+")
582 self._f.write("testing")
584 self.stream = gio.unix.InputStream(self._f.fileno(), False)
588 os.unlink("inputstream.txt")
591 self.assertEquals(self.stream.read(), "testing")
593 self.stream = gio.MemoryInputStream()
594 self.assertEquals(self.stream.read(), '')
596 self.stream = gio.MemoryInputStream()
597 some_data = open(__file__, "rb").read()
598 self.stream.add_data(some_data)
599 self.assertEquals(self.stream.read(), some_data)
601 stream = gio.MemoryInputStream()
602 stream.add_data(some_data)
603 self.assertEquals(self._read_in_loop(stream,
604 lambda: stream.read(50),
610 res = self.stream.read()
611 self.assertEqual(res, "sting")
613 def testSkipAsync(self):
614 def callback(stream, result):
616 size = stream.skip_finish(result)
617 self.assertEqual(size, 2)
619 self.assertEqual(res, "sting")
623 self.stream.skip_async(2, callback)
625 loop = glib.MainLoop()
628 def test_read_part(self):
629 self.assertEquals(self._read_in_loop(self.stream,
630 lambda: self.stream.read_part()),
633 stream = gio.MemoryInputStream()
634 some_data = open(__file__, 'rb').read()
635 stream.add_data(some_data)
636 self.assertEquals(self._read_in_loop(stream,
637 lambda: stream.read_part(50),
641 def _read_in_loop(self, stream, reader, size_limit=0):
646 read_data += read_part
648 self.assert_(len(read_part) <= size_limit,
649 '%d <= %d' % (len(read_part), size_limit))
653 def testReadAsync(self):
654 def callback(stream, result):
655 self.assertEquals(result.get_op_res_gssize(), 7)
657 data = stream.read_finish(result)
658 self.assertEquals(data, "testing")
663 self.stream.read_async(7, callback)
665 loop = glib.MainLoop()
668 def testReadAsyncError(self):
670 def callback(stream, result):
675 self.assertRaises(gio.Error, stream.read_finish, result)
679 self.stream.read_async(10240, callback)
680 self.stream.read_async(10240, callback)
682 loop = glib.MainLoop()
685 self.assertEquals(self.count, 2)
687 self.assertRaises(TypeError, self.stream.read_async)
688 self.assertRaises(TypeError, self.stream.read_async, "foo")
689 self.assertRaises(TypeError, self.stream.read_async, 1024, "bar")
690 self.assertRaises(TypeError, self.stream.read_async, 1024,
692 self.assertRaises(TypeError, self.stream.read_async, 1024,
694 self.assertRaises(TypeError, self.stream.read_async, 1024,
695 priority=1, cancellable="bar")
696 self.assertRaises(TypeError, self.stream.read_async, 1024, 1, "bar")
699 # FIXME: this makes 'make check' freeze
700 def _testCloseAsync(self):
701 def callback(stream, result):
703 self.failUnless(stream.close_finish(result))
707 self.stream.close_async(callback)
709 loop = glib.MainLoop()
713 class TestDataInputStream(unittest.TestCase):
715 self.base_stream = gio.MemoryInputStream()
716 self.data_stream = gio.DataInputStream(self.base_stream)
718 def test_read_line(self):
719 self.base_stream.add_data('foo\nbar\n\nbaz')
720 self.assertEquals('foo', self.data_stream.read_line())
721 self.assertEquals('bar', self.data_stream.read_line())
722 self.assertEquals('', self.data_stream.read_line())
723 self.assertEquals('baz', self.data_stream.read_line())
725 def test_read_line_async(self):
726 def do_read_line_async():
727 loop = glib.MainLoop()
730 def callback(stream, result):
732 line.append(stream.read_line_finish(result))
736 self.data_stream.read_line_async(callback)
740 self.base_stream.add_data('foo\nbar\n\nbaz')
741 self.assertEquals('foo', do_read_line_async())
742 self.assertEquals('bar', do_read_line_async())
743 self.assertEquals('', do_read_line_async())
744 self.assertEquals('baz', do_read_line_async())
746 def test_read_until(self):
747 self.base_stream.add_data('sentence.end of line\nthe rest')
748 self.assertEquals('sentence', self.data_stream.read_until('.!?'))
749 self.assertEquals('end of line', self.data_stream.read_until('\n\r'))
750 self.assertEquals('the rest', self.data_stream.read_until('#$%^&'))
752 def test_read_until_async(self):
753 def do_read_until_async(stop_chars):
754 loop = glib.MainLoop()
757 def callback(stream, result):
759 data.append(stream.read_until_finish(result))
763 self.data_stream.read_until_async(stop_chars, callback)
767 # Note the weird difference between synchronous and
768 # asynchronous version. See bug #584284.
769 self.base_stream.add_data('sentence.end of line\nthe rest')
770 self.assertEquals('sentence', do_read_until_async('.!?'))
771 self.assertEquals('.end of line', do_read_until_async('\n\r'))
772 self.assertEquals('\nthe rest', do_read_until_async('#$%^&'))
775 class TestMemoryInputStream(unittest.TestCase):
777 self.stream = gio.MemoryInputStream()
779 def test_add_data(self):
780 self.stream.add_data('foobar')
781 self.assertEquals('foobar', self.stream.read())
783 self.stream.add_data('ham ')
784 self.stream.add_data(None)
785 self.stream.add_data('spam')
786 self.assertEquals('ham spam', self.stream.read())
788 def test_new_from_data(self):
789 stream = gio.memory_input_stream_new_from_data('spam')
790 self.assertEquals('spam', stream.read())
793 class TestOutputStream(unittest.TestCase):
795 self._f = open("outputstream.txt", "w")
796 self.stream = gio.unix.OutputStream(self._f.fileno(), False)
800 os.unlink("outputstream.txt")
803 self.stream.write("testing")
805 self.failUnless(os.path.exists("outputstream.txt"))
806 self.assertEquals(open("outputstream.txt").read(), "testing")
808 def test_write_part(self):
809 stream = gio.MemoryOutputStream()
810 some_data = open(__file__, 'rb').read()
813 # In fact this makes only one looping (memory stream is fast,
814 # write_part behaves just like write), but let's still be
817 written = stream.write_part(buffer)
818 if written == len(buffer):
821 buffer = buffer[written:]
823 self.assertEquals(stream.get_contents(), some_data)
825 def testWriteAsync(self):
826 def callback(stream, result):
827 self.assertEquals(result.get_op_res_gssize(), 7)
829 self.assertEquals(stream.write_finish(result), 7)
830 self.failUnless(os.path.exists("outputstream.txt"))
831 self.assertEquals(open("outputstream.txt").read(), "testing")
835 self.stream.write_async("testing", callback)
837 loop = glib.MainLoop()
840 def testWriteAsyncError(self):
841 def callback(stream, result):
842 self.assertEquals(result.get_op_res_gssize(), 0)
844 self.assertRaises(gio.Error, stream.write_finish, result)
849 self.stream.write_async("testing", callback)
851 loop = glib.MainLoop()
854 self.assertRaises(TypeError, self.stream.write_async)
855 self.assertRaises(TypeError, self.stream.write_async, 1138)
856 self.assertRaises(TypeError, self.stream.write_async, "foo", "bar")
857 self.assertRaises(TypeError, self.stream.write_async, "foo",
859 self.assertRaises(TypeError, self.stream.write_async, "foo",
861 self.assertRaises(TypeError, self.stream.write_async, "foo",
862 priority=1, cancellable="bar")
863 self.assertRaises(TypeError, self.stream.write_async, "foo", 1, "bar")
865 # FIXME: this makes 'make check' freeze
866 def _testCloseAsync(self):
867 def callback(stream, result):
869 self.failUnless(stream.close_finish(result))
873 self.stream.close_async(callback)
875 loop = glib.MainLoop()
878 def testFlushAsync(self):
879 def callback(stream, result):
881 self.failUnless(stream.flush_finish(result))
885 self.stream.flush_async(callback)
887 loop = glib.MainLoop()
890 def testSpliceAsync(self):
891 _f = open("stream.txt", "w+")
894 instream = gio.unix.InputStream(_f.fileno(), False)
896 def callback(stream, result):
898 size = stream.splice_finish(result)
899 self.assertEqual(size, 7)
902 os.unlink("stream.txt")
905 self.stream.splice_async(instream, callback)
907 loop = glib.MainLoop()
910 class TestMemoryOutputStream(unittest.TestCase):
912 self.stream = gio.MemoryOutputStream()
914 def test_get_contents(self):
915 self.stream.write('foobar')
916 self.assertEquals('foobar', self.stream.get_contents())
918 self.stream.write('baz')
919 self.assertEquals('foobarbaz', self.stream.get_contents())
922 class TestVolumeMonitor(unittest.TestCase):
924 self.monitor = gio.volume_monitor_get()
926 def testGetConnectedDrives(self):
927 drives = self.monitor.get_connected_drives()
928 self.failUnless(isinstance(drives, list))
930 def testGetVolumes(self):
931 volumes = self.monitor.get_volumes()
932 self.failUnless(isinstance(volumes, list))
934 def testGetMounts(self):
935 mounts = self.monitor.get_mounts()
936 self.failUnless(isinstance(mounts, list))
940 self.failUnless(isinstance(mounts[0], gio.Mount))
942 icon = mounts[0].get_icon()
945 self.failUnless(isinstance(icon, gio.Icon))
948 class TestContentTypeGuess(unittest.TestCase):
949 def testFromName(self):
950 mime_type = gio.content_type_guess('diagram.svg')
951 self.assertEquals('image/svg+xml', mime_type)
953 def testFromContents(self):
954 mime_type = gio.content_type_guess(data='<html></html>')
955 self.assertEquals('text/html', mime_type)
957 def testFromContentsUncertain(self):
958 mime_type, result_uncertain = gio.content_type_guess(
959 data='<html></html>', want_uncertain=True)
960 self.assertEquals('text/html', mime_type)
961 self.assertEquals(bool, type(result_uncertain))
964 class TestFileInfo(unittest.TestCase):
966 self.fileinfo = gio.File(__file__).query_info("*")
968 def testListAttributes(self):
969 attributes = self.fileinfo.list_attributes("standard")
970 self.failUnless(attributes)
971 self.failUnless('standard::name' in attributes)
973 def testGetModificationTime(self):
974 mtime = self.fileinfo.get_modification_time()
975 self.assertEqual(type(mtime), float)
977 def testSetModificationTime(self):
978 self.fileinfo.set_modification_time(1000)
979 mtime = self.fileinfo.get_modification_time()
980 self.assertEqual(mtime, 1000)
983 class TestAppInfo(unittest.TestCase):
985 self.appinfo = gio.AppInfo("does-not-exist")
987 def testSimple(self):
988 self.assertEquals(self.appinfo.get_description(),
989 "Custom definition for does-not-exist")
992 info1 = gio.app_info_get_all()[0]
994 self.assert_(info1 is not info2)
995 self.assertEquals(info1, info2)
997 self.assertNotEqual(gio.app_info_get_all()[0], gio.app_info_get_all()[1])
999 class TestVfs(unittest.TestCase):
1001 self.vfs = gio.vfs_get_default()
1003 def testGetSupportedURISchemes(self):
1004 result = self.vfs.get_supported_uri_schemes()
1005 self.failUnless(type(result), [])
1007 class TestVolume(unittest.TestCase):
1009 self.monitor = gio.volume_monitor_get()
1011 def testVolumeEnumerate(self):
1012 volumes = self.monitor.get_volumes()
1013 self.failUnless(isinstance(volumes, list))
1016 ids = v.enumerate_identifiers()
1017 self.failUnless(isinstance(ids, list))
1020 self.failUnless(isinstance(id, str))
1022 class TestFileInputStream(unittest.TestCase):
1024 self._f = open("file.txt", "w+")
1025 self._f.write("testing")
1027 self.file = gio.File("file.txt")
1031 if os.path.exists('file.txt'):
1032 os.unlink("file.txt")
1034 def testQueryInfoAsync(self):
1035 def callback(stream, result):
1037 info = stream.query_info_finish(result)
1038 self.failUnless(isinstance(info, gio.FileInfo))
1039 self.failUnless(info.get_attribute_uint64("standard::size"), 7)
1043 inputstream = self.file.read()
1044 inputstream.query_info_async("standard", callback)
1046 loop = glib.MainLoop()
1049 class TestFileOutputStream(unittest.TestCase):
1051 self._f = open("file.txt", "w+")
1052 self._f.write("testing")
1054 self.file = gio.File("file.txt")
1058 if os.path.exists('file.txt'):
1059 os.unlink("file.txt")
1061 def testQueryInfoAsync(self):
1062 def callback(stream, result):
1064 info = stream.query_info_finish(result)
1065 self.failUnless(isinstance(info, gio.FileInfo))
1066 self.failUnless(info.get_attribute_uint64("standard::size"), 7)
1070 outputstream = self.file.append_to()
1071 outputstream.query_info_async("standard", callback)
1073 loop = glib.MainLoop()
1076 class TestBufferedInputStream(unittest.TestCase):
1078 self._f = open("buffer.txt", "w+")
1079 self._f.write("testing")
1081 stream = gio.unix.InputStream(self._f.fileno(), False)
1082 self.buffered = gio.BufferedInputStream(stream)
1086 os.unlink("buffer.txt")
1088 def test_fill_async(self):
1089 def callback(stream, result):
1091 size = stream.fill_finish(result)
1092 self.failUnlessEqual(size, 4)
1096 self.buffered.fill_async(4, callback)
1098 loop = glib.MainLoop()
1101 class TestIOStream(unittest.TestCase):
1103 self.file = gio.File("file.txt")
1104 self.iofile = self.file.create_readwrite(gio.FILE_CREATE_NONE)
1107 if os.path.exists('file.txt'):
1108 os.unlink("file.txt")
1110 def testIOStreamCloseAsync(self):
1111 def callback(stream, result):
1113 self.failUnless(stream.close_finish(result))
1117 self.iofile.close_async(callback)
1119 loop = glib.MainLoop()
1123 def testQueryInfoAsync(self):
1124 def callback(stream, result):
1126 info = stream.query_info_finish(result)
1127 self.failUnless(isinstance(info, gio.FileInfo))
1128 self.failUnless(info.get_attribute_uint64("standard::size"), 7)
1132 ostream = self.iofile.get_output_stream()
1133 ostream.write("testing")
1135 self.iofile.query_info_async("standard", callback)
1137 loop = glib.MainLoop()