Exemplo n.º 1
0
 def test_open_file_not_exist(self):
     try:
         f = File(self.vol.open("filenotexist", os.O_WRONLY))
     except OSError as e:
         self.assertEqual(e.errno, errno.ENOENT)
     else:
         f.close()
         self.fail("Expected a OSError with errno.ENOENT")
 def test_open_file_not_exist(self):
     try:
         f = File(self.vol.open("filenotexist", os.O_WRONLY))
     except OSError as e:
         self.assertEqual(e.errno, errno.ENOENT)
     else:
         f.close()
         self.fail("Expected a OSError with errno.ENOENT")
Exemplo n.º 3
0
 def test_create_file_already_exists(self):
     try:
         f = File(self.vol.open("newfile", os.O_CREAT))
         f.close()
         g = File(self.vol.open("newfile", os.O_CREAT | os.O_EXCL))
     except OSError as e:
         self.assertEqual(e.errno, errno.EEXIST)
     else:
         g.close()
         self.fail("Expected a OSError with errno.EEXIST")
 def test_create_file_already_exists(self):
     try:
         f = File(self.vol.open("newfile", os.O_CREAT))
         f.close()
         g = File(self.vol.open("newfile", os.O_CREAT | os.O_EXCL))
     except OSError as e:
         self.assertEqual(e.errno, errno.EEXIST)
     else:
         g.close()
         self.fail("Expected a OSError with errno.EEXIST")
Exemplo n.º 5
0
    def test_write_file_dup_lseek_read(self):
        try:
            f = File(self.vol.open("dune", os.O_CREAT | os.O_EXCL | os.O_RDWR))
            f.write(b"I must not fear. Fear is the mind-killer.")
            fdup = f.dup()
            self.assertTrue(isinstance(fdup, File))
            f.close()
            ret = fdup.lseek(0, os.SEEK_SET)
            self.assertEqual(ret, 0)

            buf = fdup.read(15)
            self.assertEqual(buf, b"I must not fear")

            ret = fdup.lseek(29, os.SEEK_SET)
            self.assertEqual(ret, 29)

            buf = fdup.read(11)
            self.assertEqual(buf, b"mind-killer")

            fdup.close()
        except OSError as e:
            self.fail(e.message)
    def test_write_file_dup_lseek_read(self):
        try:
            f = File(self.vol.open("dune", os.O_CREAT | os.O_EXCL | os.O_RDWR))
            f.write("I must not fear. Fear is the mind-killer.")
            fdup = f.dup()
            self.assertTrue(isinstance(fdup, File))
            f.close()
            ret = fdup.lseek(0, os.SEEK_SET)
            self.assertEqual(ret, 0)

            buf = fdup.read(15)
            self.assertEqual(buf, "I must not fear")

            ret = fdup.lseek(29, os.SEEK_SET)
            self.assertEqual(ret, 29)

            buf = fdup.read(11)
            self.assertEqual(buf, "mind-killer")

            fdup.close()
        except OSError as e:
            self.fail(e.message)