Stop doctests polluting current dir with temporary files

Đang mở
#264 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
testing

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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)
Ngôn ngữ chính
Python
Star
16
Fork
6
Merge trung bình
2 ngày 20 giờ
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của SciTools/ncdata

Tất cả issue của SciTools/ncdata

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.