-
Notifications
You must be signed in to change notification settings - Fork 874
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
8 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,13 @@ | |
|
||
from __future__ import annotations | ||
|
||
import sys | ||
from pathlib import Path | ||
from types import GenericAlias | ||
from typing import TYPE_CHECKING, get_args | ||
|
||
import pytest | ||
|
||
from pymatgen.core import Composition, DummySpecies, Element, Species | ||
from pymatgen.entries import Entry | ||
from pymatgen.util.typing import CompositionLike, EntryLike, PathLike, PbcLike, SpeciesLike | ||
|
@@ -17,6 +20,8 @@ | |
__date__ = "2022-10-20" | ||
__email__ = "[email protected]" | ||
|
||
skip_below_py310 = pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python 3.10 or higher") | ||
|
||
|
||
def _type_str(some_type: Any) -> str: | ||
return str(some_type).replace("typing.", "").replace("pymatgen.core.periodic_table.", "") | ||
|
@@ -43,13 +48,15 @@ def test_entry_like(): | |
assert Entry.__name__ in str(EntryLike) | ||
|
||
|
||
@skip_below_py310 | ||
def test_species_like(): | ||
assert isinstance("H", SpeciesLike) | ||
assert isinstance(Element("H"), SpeciesLike) | ||
assert isinstance(Species("H+"), SpeciesLike) | ||
assert isinstance(DummySpecies("X"), SpeciesLike) | ||
|
||
|
||
@skip_below_py310 | ||
def test_composition_like(): | ||
assert isinstance("H", CompositionLike) | ||
assert isinstance(Element("H"), CompositionLike) | ||
|
@@ -64,6 +71,7 @@ def test_pbc_like(): | |
assert get_args(PbcLike) == (bool, bool, bool) | ||
|
||
|
||
@skip_below_py310 | ||
def test_pathlike(): | ||
assert isinstance("path/to/file", PathLike) | ||
assert isinstance(Path("path/to/file"), PathLike) | ||
|