本文整理汇总了Python中luigi.File类的典型用法代码示例。如果您正苦于以下问题:Python File类的具体用法?Python File怎么用?Python File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_close
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))
示例2: test_write_cleanup_with_error
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())
示例3: test_del
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))
示例4: test_write_cleanup_no_close
def test_write_cleanup_no_close(self):
t = File(self.path)
def context():
f = t.open('w')
f.write('stuff')
context()
gc.collect() # force garbage collection of f variable
self.assertFalse(t.exists())
示例5: test_move
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))
示例6: test_copy
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())
示例7: test_tmp
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))
示例8: test_format_injection
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")
示例9: test_gzip
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()
示例10: test_bzip2
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()