跳转到主要内容

快速创建文件和目录结构。

项目描述

treeshape 允许您在磁盘上快速创建文件和目录结构。

例如

from treeshape import (
    CONTENT,
    make_tree,
    PERMISSIONS,
    )

make_tree('.', {
    'logs/': None,
    'README': {CONTENT: "A simple directory layout\n"},
    'data/input': {CONTENT: "All of our input data\n"},
    'bin/script': {CONTENT: "#!/bin/sh\necho 'Hello'\n", PERMISSIONS: 0755},
    })

将创建如下目录结构

$ find .
.
./logs
./data
./data/input
./README
$ cat README
A simple directory layout
$ cat data/input
All of our input data

这对于接触磁盘的测试特别有用。

如果您不喜欢明确表达,也可以从粗略规范创建相同的目录结构

from treeshape import (
    from_rough_spec,
    make_tree,
    )

make_tree('.', from_rough_spec([
    'logs/',
    ('README', "A simple directory layout\n"),
    ('data/input', "All of our input data\n"),
    ('bin/script', "#!/bin/sh\necho 'Hello'\n", 0755),
    ]))

这还提供为 Fixture(见 python-fixtures)。因此,如果您正在使用 testtools,您也可以在测试期间这样做

def test_a_thing(self):
    self.useFixture(FileTree(from_rough_spec([
        'logs/',
        ('README', "A simple directory layout\n"),
        ('data/input', "All of our input data\n"),
        ])))
    # your test here

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

treeshape-0.2.1.tar.gz (9.5 kB 查看哈希)

上传时间:

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面