Stop doctests polluting current dir with temporary files

オープン
#264 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
2

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

SciTools/ncdata のほかの issue

SciTools/ncdata の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。