當前位置: 首頁>>代碼示例>>Python>>正文


Python File.open方法代碼示例

本文整理匯總了Python中luigi.File.open方法的典型用法代碼示例。如果您正苦於以下問題:Python File.open方法的具體用法?Python File.open怎麽用?Python File.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在luigi.File的用法示例。


在下文中一共展示了File.open方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_copy

# 需要導入模塊: from luigi import File [as 別名]
# 或者: from luigi.File import open [as 別名]
 def test_copy(self):
     t = File(self.path)
     f = t.open('w')
     test_data = 'test'
     f.write(test_data)
     f.close()
     self.assertTrue(os.path.exists(self.path))
     self.assertFalse(os.path.exists(self.copy))
     t.copy(self.copy)
     self.assertTrue(os.path.exists(self.path))
     self.assertTrue(os.path.exists(self.copy))
     self.assertEqual(t.open('r').read(), File(self.copy).open('r').read())
開發者ID:ChrisBg,項目名稱:luigi,代碼行數:14,代碼來源:file_test.py

示例2: test_tmp

# 需要導入模塊: from luigi import File [as 別名]
# 或者: from luigi.File import open [as 別名]
    def test_tmp(self):
        t = File(is_tmp=True)
        p = t.open('w')
        print >> p, 'test'
        p.close()

        path = t.path
        self.assertTrue(os.path.exists(path))
        q = t.open('r')
        self.assertEqual(q.readline(), 'test\n')
        q.close()
        del t # should remove the underlying file
        self.assertFalse(os.path.exists(path))
開發者ID:andrefsp,項目名稱:luigi,代碼行數:15,代碼來源:file_test.py

示例3: test_close

# 需要導入模塊: from luigi import File [as 別名]
# 或者: from luigi.File import open [as 別名]
 def test_close(self):
     t = File(self.path)
     p = t.open('w')
     print >> p, 'test'
     self.assertFalse(os.path.exists(self.path))
     p.close()
     self.assertTrue(os.path.exists(self.path))
開發者ID:andrefsp,項目名稱:luigi,代碼行數:9,代碼來源:file_test.py

示例4: test_format_injection

# 需要導入模塊: from luigi import File [as 別名]
# 或者: from luigi.File import open [as 別名]
    def test_format_injection(self):
        class CustomFormat(luigi.format.Format):
            def pipe_reader(self, input_pipe):
                input_pipe.foo = "custom read property"
                return input_pipe

            def pipe_writer(self, output_pipe):
                output_pipe.foo = "custom write property"
                return output_pipe

        t = File(self.path, format=CustomFormat())
        with t.open("w") as f:
            self.assertEqual(f.foo, "custom write property")

        with t.open("r") as f:
            self.assertEqual(f.foo, "custom read property")
開發者ID:ChrisBg,項目名稱:luigi,代碼行數:18,代碼來源:file_test.py

示例5: test_write_cleanup_with_error

# 需要導入模塊: from luigi import File [as 別名]
# 或者: from luigi.File import open [as 別名]
 def test_write_cleanup_with_error(self):
     t = File(self.path)
     try:
         with t.open('w'):
             raise Exception('something broke')
     except:
         pass
     self.assertFalse(t.exists())
開發者ID:anandaverma,項目名稱:luigi,代碼行數:10,代碼來源:file_test.py

示例6: test_del

# 需要導入模塊: from luigi import File [as 別名]
# 或者: from luigi.File import open [as 別名]
    def test_del(self):
        t = File(self.path)
        p = t.open('w')
        print >> p, 'test'
        tp = p.tmp_path
        del p

        self.assertFalse(os.path.exists(tp))
        self.assertFalse(os.path.exists(self.path))
開發者ID:andrefsp,項目名稱:luigi,代碼行數:11,代碼來源:file_test.py

示例7: test_move

# 需要導入模塊: from luigi import File [as 別名]
# 或者: from luigi.File import open [as 別名]
 def test_move(self):
     t = File(self.path)
     f = t.open('w')
     test_data = 'test'
     f.write(test_data)
     f.close()
     self.assertTrue(os.path.exists(self.path))
     self.assertFalse(os.path.exists(self.copy))
     t.move(self.copy)
     self.assertFalse(os.path.exists(self.path))
     self.assertTrue(os.path.exists(self.copy))
開發者ID:ChrisBg,項目名稱:luigi,代碼行數:13,代碼來源:file_test.py

示例8: test_gzip

# 需要導入模塊: from luigi import File [as 別名]
# 或者: from luigi.File import open [as 別名]
    def test_gzip(self):
        t = File(self.path, luigi.format.Gzip)
        p = t.open('w')
        test_data = 'test'
        p.write(test_data)
        print self.path
        self.assertFalse(os.path.exists(self.path))
        p.close()
        self.assertTrue(os.path.exists(self.path))

        # Using gzip module as validation
        f = gzip.open(self.path, 'rb')
        self.assertTrue(test_data == f.read())
        f.close()

        # Verifying our own gzip reader
        f = File(self.path, luigi.format.Gzip).open('r')
        self.assertTrue(test_data == f.read())
        f.close()
開發者ID:andrefsp,項目名稱:luigi,代碼行數:21,代碼來源:file_test.py

示例9: test_bzip2

# 需要導入模塊: from luigi import File [as 別名]
# 或者: from luigi.File import open [as 別名]
    def test_bzip2(self):
        t = File(self.path, luigi.format.Bzip2)
        p = t.open('w')
        test_data = 'test'
        p.write(test_data)
        print self.path
        self.assertFalse(os.path.exists(self.path))
        p.close()
        self.assertTrue(os.path.exists(self.path))

        # Using bzip module as validation
        f = bz2.BZ2File(self.path, 'rb')
        self.assertTrue(test_data == f.read())
        f.close()

        # Verifying our own bzip2 reader
        f = File(self.path, luigi.format.Bzip2).open('r')
        self.assertTrue(test_data == f.read())
        f.close()
開發者ID:ChrisBg,項目名稱:luigi,代碼行數:21,代碼來源:file_test.py


注:本文中的luigi.File.open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。