Skip to content

Commit

Permalink
Merge pull request #368 from tovrstra/fix-type-check-textiobase
Browse files Browse the repository at this point in the history
Fix typecheck: TextIOBase instead of TextIO
  • Loading branch information
tovrstra authored Jul 9, 2024
2 parents 22475e1 + d3fbc2b commit a26356e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
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):
rng = np.random.default_rng(42)
data = IOData(
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
with open(os.path.join(tmpdir, "foo.molden"), "w") as fh, pytest.raises(DumpError):
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):
return file.name, lineno
if file is None:
if lineno is not None:
Expand Down

0 comments on commit a26356e

Please sign in to comment.