Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typecheck: TextIOBase instead of TextIO #368

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions iodata/test/test_molden.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@
from numpy.testing import assert_allclose, assert_equal

from ..api import dump_one, load_one
from ..basis import convert_conventions
from ..basis import HORTON2_CONVENTIONS, MolecularBasis, Shell, convert_conventions
from ..formats.molden import _load_low
from ..formats.molden import dump_one as molden_dump_one
from ..iodata import IOData
from ..orbitals import MolecularOrbitals
from ..overlap import OVERLAP_CONVENTIONS, compute_overlap
from ..utils import LineIterator, LoadWarning, PrepareDumpError, angstrom
from ..utils import DumpError, LineIterator, LoadWarning, PrepareDumpError, angstrom
from .common import check_orthonormal, compare_mols, compute_mulliken_charges, create_generalized


Expand Down Expand Up @@ -600,3 +603,30 @@ def test_generalized():
data = create_generalized()
with pytest.raises(PrepareDumpError):
dump_one(data, "generalized.molden")


def test_mixed_pure_cartesian(tmpdir):
tovrstra marked this conversation as resolved.
Show resolved Hide resolved
rng = np.random.default_rng(42)
data = IOData(
tovrstra marked this conversation as resolved.
Show resolved Hide resolved
atnums=[1, 1],
atcoords=[[1.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
obasis=MolecularBasis(
[
Shell(0, [2], ["c"], np.array([1.0]), np.array([[1.0]])),
Shell(0, [2], ["p"], np.array([1.0]), np.array([[1.0]])),
],
HORTON2_CONVENTIONS,
"L2",
),
mo=MolecularOrbitals(
"restricted",
norba=2,
norbb=2,
occs=[1.0, 0.0],
energies=[-1.0, -0.5],
coeffs=rng.uniform(0, 1, (11, 2)),
),
)
assert data.obasis.nbasis == data.mo.nbasis
tovrstra marked this conversation as resolved.
Show resolved Hide resolved
with open(os.path.join(tmpdir, "foo.molden"), "w") as fh, pytest.raises(DumpError):
tovrstra marked this conversation as resolved.
Show resolved Hide resolved
molden_dump_one(fh, data)
3 changes: 2 additions & 1 deletion iodata/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# --
"""Utility functions module."""

from io import TextIOBase
from pathlib import Path
from typing import Optional, TextIO, Union

Expand Down Expand Up @@ -140,7 +141,7 @@ def _interpret_file_lineno(
if lineno is None:
lineno = file.lineno
return file.filename, lineno
if isinstance(file, TextIO):
if isinstance(file, TextIOBase):
tovrstra marked this conversation as resolved.
Show resolved Hide resolved
return file.name, lineno
if file is None:
if lineno is not None:
Expand Down