Stop doctests polluting current dir with temporary files

Abierto
#264 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python
Área
testing

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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)
Lenguaje dominante
Python
Estrellas
16
Forks
6
Merge medio
2 d 20 h
PR fusionados (30 d)
2

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de SciTools/ncdata

Todos los issues de SciTools/ncdata

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.