Stop doctests polluting current dir with temporary files

未关闭
#264 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
python
领域
testing

调研方向

Start by reading the run-doctests tool and the doctests that create temporary netCDF files in the current directory; the issue does not name specific files or tests. Compare the proposed temporary-working-directory approach with a shared temporary-directory utility, keeping local-code imports and cleanup behavior in mind. Done means doctests no longer leave temporary netCDF files in the project directory without disrupting their execution.

由索引模型根据 Issue 内容生成。

描述

At present, when you run any doctests temporary netCDF files are created in the current directory.

This is slightly tiresome, and could be avoided by dumping files to a temporary directory, like pytest does.

Unfortunately, adding specific code to do that in every module / docs-sourcefile could also be tiresome and intrusive.

in run-doctests

Possibly, a way to control this could be added to the run_doctests tool ?

  • e.g., run by default in a temporary cwd -
  • but that could affect doctest execution, and make some things difficult (e.g. importing local code) ??

using tempfile

instead of e.g. data.to_nc4('tmp.nc'),

import pathlib
import testfile

tempdir = pathlib.Path(testfile.TemporaryDirectory())
# ...
path = tempdir / "tmp.nc"
to_nc4(data, path)
result = from_nc4(path)

with a test utility

Or.. A utility to create a temp directory that will be consistently destroyed afterwards might be useful
(as opposed to tempdir which does not arrange for destruction).

# in <testutils.py>
import pathlib

class TempDir(pathlib.Path):
    def __init__(self):
        # self.context is deleted when self is deleted --> destroys directory
        self.context = tempfile.TemporaryDirectory()
        self.path_str = self.context.__enter__()
        self.path = pathlib.Path(self.dirpath_str)

# a single common per-import object
tempdir = TempDir()

# ... 
# in docstrings / docs
# Usage is generally shorter, and directory is removed on program exit
>>> from testutils import tempdir

...

>>> filepath = tempdir.path / "tmp.nc"
>>> to_nc4(data, filepath)
>>> result = from_nc4(filepath)
主要语言
Python
星标
16
派生
6
平均合并
2 天 20 小时
30 天内合并 PR
2

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

SciTools/ncdata 的其他 Issue

查看 SciTools/ncdata 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。