Skip to content

Commit

Permalink
Remove import_resources try-except block
Browse files Browse the repository at this point in the history
These weird imports were only relevant for Python versions
that are past their end of life: 3.6 and older.
  • Loading branch information
tovrstra committed Jun 4, 2024
1 parent ac9a6d5 commit 4735809
Show file tree
Hide file tree
Showing 30 changed files with 44 additions and 152 deletions.
6 changes: 1 addition & 5 deletions iodata/test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import os
from contextlib import contextmanager
from importlib.resources import as_file, files
from typing import Optional

import numpy as np
Expand All @@ -31,11 +32,6 @@
from ..overlap import compute_overlap
from ..utils import FileFormatWarning

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files

__all__ = [
"compute_mulliken_charges",
"compute_1rdm",
Expand Down
7 changes: 2 additions & 5 deletions iodata/test/test_charmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
# --
"""Test iodata.formats.orcalog module."""

from importlib.resources import as_file, files

from numpy.testing import assert_allclose, assert_equal

from ..api import load_one
from ..utils import amu, angstrom

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def test_load_crambin():
# test CHARMM crd file of crambin
Expand Down
7 changes: 2 additions & 5 deletions iodata/test/test_chgcar.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@
# --
"""Test iodata.formats.chgcar module."""

from importlib.resources import as_file, files

import numpy as np
from numpy.testing import assert_allclose, assert_equal

from ..api import load_one
from ..utils import angstrom, volume

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def test_load_chgcar_oxygen():
with as_file(files("iodata.test.data").joinpath("CHGCAR.oxygen")) as fn:
Expand Down
6 changes: 1 addition & 5 deletions iodata/test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@
import os
import subprocess
import sys
from importlib.resources import as_file, files

from numpy.testing import assert_allclose, assert_equal

from ..__main__ import convert
from ..api import load_many, load_one

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def _check_convert_one(myconvert, tmpdir):
outfn = os.path.join(tmpdir, "tmp.xyz")
Expand Down
7 changes: 2 additions & 5 deletions iodata/test/test_cp2klog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@
# --
"""Test iodata.formats.cp2klog module."""

from importlib.resources import as_file, files

import pytest
from numpy.testing import assert_allclose, assert_equal

from ..api import load_one
from ..overlap import compute_overlap
from .common import check_orthonormal, truncated_file

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def test_atom_si_uks():
with as_file(files("iodata.test.data").joinpath("atom_si.cp2k.out")) as fn_out:
Expand Down
7 changes: 2 additions & 5 deletions iodata/test/test_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
# --
"""Test iodata.formats.cube module."""

from importlib.resources import as_file, files

import numpy as np
from numpy.testing import assert_allclose, assert_equal

from ..api import dump_one, load_one

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def test_load_aelta():
with as_file(files("iodata.test.data").joinpath("aelta.cube")) as fn_cube:
Expand Down
7 changes: 2 additions & 5 deletions iodata/test/test_extxyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@
# --
"""Test iodata.formats.extxyz module."""

from importlib.resources import as_file, files

import numpy as np
from numpy.testing import assert_allclose, assert_equal

from ..api import load_many, load_one
from ..utils import angstrom

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def test_load_fcc_extended():
with as_file(files("iodata.test.data").joinpath("al_fcc.xyz")) as fn_xyz:
Expand Down
6 changes: 1 addition & 5 deletions iodata/test/test_fchk.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""Test iodata.formats.fchk module."""

import os
from importlib.resources import as_file, files
from typing import Optional

import numpy as np
Expand All @@ -31,11 +32,6 @@
from .common import check_orthonormal, compare_mols, compute_1rdm, load_one_warning
from .test_molekel import compare_mols_diff_formats

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def test_load_fchk_nonexistent():
with (
Expand Down
6 changes: 1 addition & 5 deletions iodata/test/test_fcidump.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@
"""Test iodata.formats.fcidump module."""

import os
from importlib.resources import as_file, files

import numpy as np
from numpy.testing import assert_allclose, assert_equal

from ..api import dump_one, load_one

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def test_load_fcidump_psi4_h2():
with as_file(files("iodata.test.data").joinpath("FCIDUMP.psi4.h2")) as fn:
Expand Down
7 changes: 2 additions & 5 deletions iodata/test/test_gamess.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
# --
"""Test iodata.formats.gamess module."""

from importlib.resources import as_file, files

from numpy.testing import assert_allclose, assert_equal

from ..api import load_one
from ..utils import angstrom

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def test_load_one_gamess_punch():
with as_file(files("iodata.test.data").joinpath("PCGamess_PUNCH.dat")) as f:
Expand Down
7 changes: 2 additions & 5 deletions iodata/test/test_gaussianinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@
# --
"""Test iodata.formats.gaussianinput module."""

from importlib.resources import as_file, files

import numpy as np
from numpy.testing import assert_allclose, assert_equal, assert_raises

from ..api import load_one
from ..utils import angstrom

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def test_load_water_com():
# test .com with Link 0 section
Expand Down
7 changes: 2 additions & 5 deletions iodata/test/test_gaussianlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@
# --
"""Test iodata.formats.log module."""

from importlib.resources import as_file, files

from numpy.testing import assert_allclose, assert_equal

from ..api import load_one

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def load_log_helper(fn_log):
"""Load a testing Gaussian log file with iodata.load_one."""
Expand Down
7 changes: 2 additions & 5 deletions iodata/test/test_gromacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
# --
"""Test iodata.formats.gromacs module."""

from importlib.resources import as_file, files

from numpy.testing import assert_allclose, assert_equal

from ..api import load_many, load_one
from ..utils import nanometer, picosecond

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def test_load_water():
# test gro file of one water
Expand Down
6 changes: 1 addition & 5 deletions iodata/test/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@
"""Test iodata.inputs module."""

import os
from importlib.resources import as_file, files

import numpy as np

from ..api import load_one, write_input
from ..iodata import IOData
from ..utils import angstrom

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def check_load_input_and_compare(fname: str, fname_expected: str):
"""Load saved input file and compare to expected input file.
Expand Down
7 changes: 2 additions & 5 deletions iodata/test/test_iodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# ruff: noqa: SLF001
"""Test iodata.iodata module."""

from importlib.resources import as_file, files

import numpy as np
import pytest
from numpy.testing import assert_allclose, assert_equal
Expand All @@ -27,11 +29,6 @@
from ..overlap import compute_overlap
from .common import compute_1rdm

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def test_typecheck():
m = IOData(atcoords=np.array([[1, 2, 3], [2, 3, 1]]))
Expand Down
7 changes: 1 addition & 6 deletions iodata/test/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@

import json
import os
from importlib.resources import as_file, files

import numpy as np
import pytest

from ..api import dump_one, load_one
from ..utils import FileFormatError, FileFormatWarning

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


# Tests for qcschema_molecule
# GEOMS: dict of str: NDArray(N, 3)
GEOMS = {
Expand Down
7 changes: 2 additions & 5 deletions iodata/test/test_locpot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
# --
"""Test iodata.formats.locpot module."""

from importlib.resources import as_file, files

from numpy.testing import assert_allclose, assert_equal

from ..api import load_one
from ..utils import angstrom, electronvolt, volume

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def test_load_locpot_oxygen():
with as_file(files("iodata.test.data").joinpath("LOCPOT.oxygen")) as fn:
Expand Down
6 changes: 1 addition & 5 deletions iodata/test/test_mol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""Test iodata.formats.mol2 module."""

import os
from importlib.resources import as_file, files

import pytest
from numpy.testing import assert_allclose, assert_equal
Expand All @@ -28,11 +29,6 @@
from ..utils import angstrom
from .common import truncated_file

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def test_mol2_load_one():
# test mol2 one structure
Expand Down
6 changes: 1 addition & 5 deletions iodata/test/test_molden.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import os
import warnings
from importlib.resources import as_file, files

import attrs
import numpy as np
Expand All @@ -33,11 +34,6 @@
from ..utils import FileFormatWarning, LineIterator, angstrom
from .common import check_orthonormal, compare_mols, compute_mulliken_charges

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def test_load_molden_li2_orca():
with (
Expand Down
6 changes: 1 addition & 5 deletions iodata/test/test_molekel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import os
import warnings
from importlib.resources import as_file, files
from typing import Optional

from numpy.testing import assert_allclose, assert_equal
Expand All @@ -30,11 +31,6 @@
from ..utils import angstrom
from .common import check_orthonormal, compare_mols, compute_mulliken_charges, load_one_warning

try:
from importlib_resources import as_file, files
except ImportError:
from importlib.resources import as_file, files


def compare_mols_diff_formats(mol1, mol2):
"""Compare two IOData objects loaded from different formats."""
Expand Down
Loading

0 comments on commit 4735809

Please sign in to comment.