Stop doctests polluting current dir with temporary files
还没有人认领这个 Issue。
评估
调研方向
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,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
SciTools/ncdata 的其他 Issue
-
automated issue report
难度 1/5 1-3 小时 新手友好度 68/100
-
难度 2/5 1-3 小时 新手友好度 76/100
-
scitools
难度 1/5 1 小时以内 新手友好度 68/100
-
scitools
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 4/5 3-5 天 新手友好度 20/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 80/100
UKGovernmentBEIS/inspect_ai#6733 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
ProyectoRespira/respira-webapp#334 ·
维护者通常 1 天内回复
-
bug security-alert
难度 2/5 1-3 小时 新手友好度 62/100
spectrayan/carefold#391 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
Jakeschincariol/instagram-agent-skill#83 ·
维护者通常 10 天内回复
-
难度 1/5 1 小时以内 新手友好度 64/100