本文整理汇总了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())
示例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))
示例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))
示例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")
示例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())
示例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))
示例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))
示例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()
示例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()