本文整理汇总了Python中amo.utils.LocalFileStorage.path方法的典型用法代码示例。如果您正苦于以下问题:Python LocalFileStorage.path方法的具体用法?Python LocalFileStorage.path怎么用?Python LocalFileStorage.path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类amo.utils.LocalFileStorage
的用法示例。
在下文中一共展示了LocalFileStorage.path方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestLocalFileStorage
# 需要导入模块: from amo.utils import LocalFileStorage [as 别名]
# 或者: from amo.utils.LocalFileStorage import path [as 别名]
class TestLocalFileStorage(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.mkdtemp()
self.stor = LocalFileStorage()
def tearDown(self):
shutil.rmtree(self.tmp)
def test_read_write(self):
fn = os.path.join(self.tmp, 'somefile.txt')
with self.stor.open(fn, 'w') as fd:
fd.write('stuff')
with self.stor.open(fn, 'r') as fd:
eq_(fd.read(), 'stuff')
def test_non_ascii_filename(self):
fn = os.path.join(self.tmp, u'Ivan Krsti\u0107.txt')
with self.stor.open(fn, 'w') as fd:
fd.write('stuff')
with self.stor.open(fn, 'r') as fd:
eq_(fd.read(), 'stuff')
def test_non_ascii_content(self):
fn = os.path.join(self.tmp, 'somefile.txt')
with self.stor.open(fn, 'w') as fd:
fd.write(u'Ivan Krsti\u0107.txt'.encode('utf8'))
with self.stor.open(fn, 'r') as fd:
eq_(fd.read().decode('utf8'), u'Ivan Krsti\u0107.txt')
def test_make_file_dirs(self):
dp = os.path.join(self.tmp, 'path', 'to')
self.stor.open(os.path.join(dp, 'file.txt'), 'w').close()
assert os.path.exists(self.stor.path(dp)), (
'Directory not created: %r' % dp)
def test_do_not_make_file_dirs_when_reading(self):
fpath = os.path.join(self.tmp, 'file.txt')
with open(fpath, 'w') as fp:
fp.write('content')
# Make sure this doesn't raise an exception.
self.stor.open(fpath, 'r').close()
def test_make_dirs_only_once(self):
dp = os.path.join(self.tmp, 'path', 'to')
with self.stor.open(os.path.join(dp, 'file.txt'), 'w') as fd:
fd.write('stuff')
# Make sure it doesn't try to make the dir twice
with self.stor.open(os.path.join(dp, 'file.txt'), 'w') as fd:
fd.write('stuff')
with self.stor.open(os.path.join(dp, 'file.txt'), 'r') as fd:
eq_(fd.read(), 'stuff')
示例2: TestLocalFileStorage
# 需要导入模块: from amo.utils import LocalFileStorage [as 别名]
# 或者: from amo.utils.LocalFileStorage import path [as 别名]
class TestLocalFileStorage(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.mkdtemp()
self.stor = LocalFileStorage()
def tearDown(self):
rm_local_tmp_dir(self.tmp)
def test_read_write(self):
fn = os.path.join(self.tmp, "somefile.txt")
with self.stor.open(fn, "w") as fd:
fd.write("stuff")
with self.stor.open(fn, "r") as fd:
eq_(fd.read(), "stuff")
def test_non_ascii_filename(self):
fn = os.path.join(self.tmp, u"Ivan Krsti\u0107.txt")
with self.stor.open(fn, "w") as fd:
fd.write("stuff")
with self.stor.open(fn, "r") as fd:
eq_(fd.read(), "stuff")
def test_non_ascii_content(self):
fn = os.path.join(self.tmp, "somefile.txt")
with self.stor.open(fn, "w") as fd:
fd.write(u"Ivan Krsti\u0107.txt".encode("utf8"))
with self.stor.open(fn, "r") as fd:
eq_(fd.read().decode("utf8"), u"Ivan Krsti\u0107.txt")
def test_make_file_dirs(self):
dp = os.path.join(self.tmp, "path", "to")
self.stor.open(os.path.join(dp, "file.txt"), "w").close()
assert os.path.exists(self.stor.path(dp)), "Directory not created: %r" % dp
def test_do_not_make_file_dirs_when_reading(self):
fpath = os.path.join(self.tmp, "file.txt")
with open(fpath, "w") as fp:
fp.write("content")
# Make sure this doesn't raise an exception.
self.stor.open(fpath, "r").close()
def test_make_dirs_only_once(self):
dp = os.path.join(self.tmp, "path", "to")
with self.stor.open(os.path.join(dp, "file.txt"), "w") as fd:
fd.write("stuff")
# Make sure it doesn't try to make the dir twice
with self.stor.open(os.path.join(dp, "file.txt"), "w") as fd:
fd.write("stuff")
with self.stor.open(os.path.join(dp, "file.txt"), "r") as fd:
eq_(fd.read(), "stuff")
def test_delete_empty_dir(self):
dp = os.path.join(self.tmp, "path")
os.mkdir(dp)
self.stor.delete(dp)
eq_(os.path.exists(dp), False)
@raises(OSError)
def test_cannot_delete_non_empty_dir(self):
dp = os.path.join(self.tmp, "path")
with self.stor.open(os.path.join(dp, "file.txt"), "w") as fp:
fp.write("stuff")
self.stor.delete(dp)
def test_delete_file(self):
dp = os.path.join(self.tmp, "path")
fn = os.path.join(dp, "file.txt")
with self.stor.open(fn, "w") as fp:
fp.write("stuff")
self.stor.delete(fn)
eq_(os.path.exists(fn), False)
eq_(os.path.exists(dp), True)
示例3: TestLocalFileStorage
# 需要导入模块: from amo.utils import LocalFileStorage [as 别名]
# 或者: from amo.utils.LocalFileStorage import path [as 别名]
class TestLocalFileStorage(BaseTestCase):
def setUp(self):
super(TestLocalFileStorage, self).setUp()
self.tmp = tempfile.mkdtemp()
self.stor = LocalFileStorage()
def tearDown(self):
rm_local_tmp_dir(self.tmp)
super(TestLocalFileStorage, self).tearDown()
def test_read_write(self):
fn = os.path.join(self.tmp, 'somefile.txt')
with self.stor.open(fn, 'w') as fd:
fd.write('stuff')
with self.stor.open(fn, 'r') as fd:
eq_(fd.read(), 'stuff')
def test_non_ascii_filename(self):
fn = os.path.join(self.tmp, u'Ivan Krsti\u0107.txt')
with self.stor.open(fn, 'w') as fd:
fd.write('stuff')
with self.stor.open(fn, 'r') as fd:
eq_(fd.read(), 'stuff')
def test_non_ascii_content(self):
fn = os.path.join(self.tmp, 'somefile.txt')
with self.stor.open(fn, 'w') as fd:
fd.write(u'Ivan Krsti\u0107.txt'.encode('utf8'))
with self.stor.open(fn, 'r') as fd:
eq_(fd.read().decode('utf8'), u'Ivan Krsti\u0107.txt')
def test_make_file_dirs(self):
dp = os.path.join(self.tmp, 'path', 'to')
self.stor.open(os.path.join(dp, 'file.txt'), 'w').close()
assert os.path.exists(self.stor.path(dp)), (
'Directory not created: %r' % dp)
def test_do_not_make_file_dirs_when_reading(self):
fpath = os.path.join(self.tmp, 'file.txt')
with open(fpath, 'w') as fp:
fp.write('content')
# Make sure this doesn't raise an exception.
self.stor.open(fpath, 'r').close()
def test_make_dirs_only_once(self):
dp = os.path.join(self.tmp, 'path', 'to')
with self.stor.open(os.path.join(dp, 'file.txt'), 'w') as fd:
fd.write('stuff')
# Make sure it doesn't try to make the dir twice
with self.stor.open(os.path.join(dp, 'file.txt'), 'w') as fd:
fd.write('stuff')
with self.stor.open(os.path.join(dp, 'file.txt'), 'r') as fd:
eq_(fd.read(), 'stuff')
def test_delete_empty_dir(self):
dp = os.path.join(self.tmp, 'path')
os.mkdir(dp)
self.stor.delete(dp)
eq_(os.path.exists(dp), False)
@raises(OSError)
def test_cannot_delete_non_empty_dir(self):
dp = os.path.join(self.tmp, 'path')
with self.stor.open(os.path.join(dp, 'file.txt'), 'w') as fp:
fp.write('stuff')
self.stor.delete(dp)
def test_delete_file(self):
dp = os.path.join(self.tmp, 'path')
fn = os.path.join(dp, 'file.txt')
with self.stor.open(fn, 'w') as fp:
fp.write('stuff')
self.stor.delete(fn)
eq_(os.path.exists(fn), False)
eq_(os.path.exists(dp), True)