Skip to content

Commit

Permalink
fix some ruff PT011 (pytest.raise() without match="..." too broad)
Browse files Browse the repository at this point in the history
drop trailing zeros
  • Loading branch information
janosh committed Jun 17, 2023
1 parent 1fadc5e commit 5506eb3
Show file tree
Hide file tree
Showing 25 changed files with 143 additions and 132 deletions.
2 changes: 1 addition & 1 deletion pymatgen/alchemy/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class ContainsSpecieFilterTest(PymatgenTest):
def test_filtering(self):
coords = [[0, 0, 0], [0.75, 0.75, 0.75], [0.5, 0.5, 0.5], [0.25, 0.25, 0.25]]
lattice = Lattice([[3.0, 0.0, 0.0], [1.0, 3.0, 0.00], [0.00, -2.0, 3.0]])
lattice = Lattice([[3.0, 0.0, 0.0], [1.0, 3.0, 0], [0, -2.0, 3.0]])
struct = Structure(lattice, [{"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25}] * 4, coords)

species1 = [Species("Si", 5), Species("Mg", 2)]
Expand Down
6 changes: 3 additions & 3 deletions pymatgen/alchemy/tests/test_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def test_append_transformation(self):
coords.append([0, 0, 0])
coords.append([0.75, 0.5, 0.75])
lattice = [
[3.8401979337, 0.00, 0.00],
[1.9200989668, 3.3257101909, 0.00],
[0.00, -2.2171384943, 3.1355090603],
[3.8401979337, 0, 0],
[1.9200989668, 3.3257101909, 0],
[0, -2.2171384943, 3.1355090603],
]
struct = Structure(lattice, ["Si4+", "Si4+"], coords)
ts = TransformedStructure(struct, [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,39 @@
class StrategyOptionsTest(PymatgenTest):
def test_options(self):
# DistanceCutoffFloat
with pytest.raises(ValueError) as exc_info:
with pytest.raises(ValueError) as exc:
DistanceCutoffFloat(0.5)
assert str(exc_info.value) == "Distance cutoff should be between 1.0 and +infinity"
assert str(exc.value) == "Distance cutoff should be between 1.0 and +infinity"
dc1 = DistanceCutoffFloat(1.2)
dc1_dict = dc1.as_dict()
dc2 = DistanceCutoffFloat.from_dict(dc1_dict)
assert dc1 == dc2

# AngleCutoffFloat
with pytest.raises(ValueError) as exc_info:
with pytest.raises(ValueError) as exc:
AngleCutoffFloat(1.2)
assert str(exc_info.value) == "Angle cutoff should be between 0.0 and 1.0"
assert str(exc.value) == "Angle cutoff should be between 0.0 and 1.0"
ac1 = AngleCutoffFloat(0.3)
ac1_dict = ac1.as_dict()
ac2 = AngleCutoffFloat.from_dict(ac1_dict)
assert ac1 == ac2

# CSMFloat
with pytest.raises(ValueError) as exc_info:
with pytest.raises(ValueError) as exc:
CSMFloat(100.1)
assert str(exc_info.value) == "Continuous symmetry measure limits should be between 0.0 and 100.0"
assert str(exc.value) == "Continuous symmetry measure limits should be between 0.0 and 100.0"
csm1 = CSMFloat(0.458)
csm1_dict = csm1.as_dict()
csm2 = CSMFloat.from_dict(csm1_dict)
assert csm1 == csm2

# AdditionalConditions
with pytest.raises(ValueError) as exc_info:
with pytest.raises(ValueError) as exc:
AdditionalConditionInt(5)
assert str(exc_info.value) == "Additional condition 5 is not allowed"
with pytest.raises(ValueError) as exc_info:
assert str(exc.value) == "Additional condition 5 is not allowed"
with pytest.raises(ValueError) as exc:
AdditionalConditionInt(0.458)
assert str(exc_info.value) == "Additional condition 0.458 is not an integer"
assert str(exc.value) == "Additional condition 0.458 is not an integer"
acd1 = AdditionalConditionInt(3)
acd1_dict = acd1.as_dict()
acd2 = AdditionalConditionInt.from_dict(acd1_dict)
Expand All @@ -75,16 +75,16 @@ def test_strategies(self):
simplest_strategy.set_option("distance_cutoff", 1.5)
assert simplest_strategy.distance_cutoff == approx(1.5)

with pytest.raises(ValueError) as exc_info:
with pytest.raises(ValueError) as exc:
simplest_strategy.set_option("distance_cutoff", 0.5)
assert str(exc_info.value) == "Distance cutoff should be between 1.0 and +infinity"
assert str(exc.value) == "Distance cutoff should be between 1.0 and +infinity"

simplest_strategy.set_option("angle_cutoff", 0.2)
assert simplest_strategy.angle_cutoff == approx(0.2)

with pytest.raises(ValueError) as exc_info:
with pytest.raises(ValueError) as exc:
simplest_strategy.set_option("angle_cutoff", 1.5)
assert str(exc_info.value) == "Angle cutoff should be between 0.0 and 1.0"
assert str(exc.value) == "Angle cutoff should be between 0.0 and 1.0"

simplest_strategy.setup_options(
{
Expand All @@ -97,10 +97,10 @@ def test_strategies(self):
assert simplest_strategy.continuous_symmetry_measure_cutoff == approx(8.5)
assert simplest_strategy.additional_condition == 3

with pytest.raises(ValueError) as exc_info:
with pytest.raises(ValueError) as exc:
simplest_strategy.setup_options({"continuous_symmetry_measure_cutoff": -0.1})
assert str(exc_info.value) == "Continuous symmetry measure limits should be between 0.0 and 100.0"
assert str(exc.value) == "Continuous symmetry measure limits should be between 0.0 and 100.0"

with pytest.raises(ValueError) as exc_info:
with pytest.raises(ValueError) as exc:
simplest_strategy.setup_options({"continuous_symmetry_measure_cutoff": 100.1})
assert str(exc_info.value) == "Continuous symmetry measure limits should be between 0.0 and 100.0"
assert str(exc.value) == "Continuous symmetry measure limits should be between 0.0 and 100.0"
Original file line number Diff line number Diff line change
Expand Up @@ -292,23 +292,23 @@ def test_coordination_geometry(self):
]

assert allcg.get_geometry_from_name("Octahedron").mp_symbol == cg_oct.mp_symbol
with pytest.raises(LookupError) as exc_info:
with pytest.raises(LookupError) as exc:
allcg.get_geometry_from_name("Octahedran")
assert str(exc_info.value) == "No coordination geometry found with name 'Octahedran'"
assert str(exc.value) == "No coordination geometry found with name 'Octahedran'"

assert allcg.get_geometry_from_IUPAC_symbol("OC-6").mp_symbol == cg_oct.mp_symbol
with pytest.raises(LookupError) as exc_info:
with pytest.raises(LookupError) as exc:
allcg.get_geometry_from_IUPAC_symbol("OC-7")
assert str(exc_info.value) == "No coordination geometry found with IUPAC symbol 'OC-7'"
assert str(exc.value) == "No coordination geometry found with IUPAC symbol 'OC-7'"

assert allcg.get_geometry_from_IUCr_symbol("[6o]").mp_symbol == cg_oct.mp_symbol
with pytest.raises(LookupError) as exc_info:
with pytest.raises(LookupError) as exc:
allcg.get_geometry_from_IUCr_symbol("[6oct]")
assert str(exc_info.value) == "No coordination geometry found with IUCr symbol '[6oct]'"
assert str(exc.value) == "No coordination geometry found with IUCr symbol '[6oct]'"

with pytest.raises(LookupError) as exc_info:
with pytest.raises(LookupError) as exc:
allcg.get_geometry_from_mp_symbol("O:7")
assert str(exc_info.value) == "No coordination geometry found with mp_symbol 'O:7'"
assert str(exc.value) == "No coordination geometry found with mp_symbol 'O:7'"

assert (
allcg.pretty_print(maxcn=4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ def test_abstract_geometry(self):
self.assert_all_close(abstract_geom.centre, [0.0, 0.0, 0.0])
abstract_geom = AbstractGeometry.from_cg(cg=cg_ts3, centering_type="centroid")
self.assert_all_close(abstract_geom.centre, [0.0, 0.0, 0.33333333333])
with pytest.raises(ValueError) as exc_info:
with pytest.raises(ValueError) as exc:
AbstractGeometry.from_cg(
cg=cg_ts3,
centering_type="central_site",
include_central_site_in_centroid=True,
)
assert (
str(exc_info.value) == "The center is the central site, no calculation of the centroid, "
str(exc.value) == "The center is the central site, no calculation of the centroid, "
"variable include_central_site_in_centroid should be set to False"
)
abstract_geom = AbstractGeometry.from_cg(
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/gb/grain.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def gb_from_parameters(
Make sure the angle is accurate enough. You can use the enum* functions
in this class to extract the accurate angle.
e.g.: The rotation angle of sigma 3 twist GB with the rotation axis
[1, 1, 1] and GB plane (1, 1, 1) can be 60.000000000 degree.
[1, 1, 1] and GB plane (1, 1, 1) can be 60 degree.
If you do not know the rotation angle, but know the sigma value, we have
provide the function get_rotation_angle_from_sigma which is able to return
all the rotation angles of sigma value you provided.
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/magnetism/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(
make_primitive: bool = True,
default_magmoms: dict | None = None,
set_net_positive: bool = True,
threshold: float = 0.00,
threshold: float = 0,
threshold_nonmag: float = 0.1,
):
"""
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/molecule_structure_comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class CovalentRadius:
"Ra": 2.21,
"Ac": 2.15,
"Th": 2.06,
"Pa": 2.00,
"Pa": 2,
"U": 1.96,
"Np": 1.90,
"Pu": 1.87,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pymatgen.core import Structure
from pymatgen.util.testing import PymatgenTest

dir_path = os.path.join(os.path.dirname(os.path.abspath(__file__)))
module_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)))


class RLSVolumePredictorTest(PymatgenTest):
Expand Down Expand Up @@ -55,8 +55,8 @@ def test_predict(self):
# Use Ag7P3S11 as a test case:

# (i) no oxidation states are assigned and CVP-atomic scheme is selected.
aps = Structure.from_file(os.path.join(dir_path, "Ag7P3S11_mp-683910_primitive.cif"))
apo = Structure.from_file(os.path.join(dir_path, "Ag7P3S11_mp-683910_primitive.cif"))
aps = Structure.from_file(os.path.join(module_dir, "Ag7P3S11_mp-683910_primitive.cif"))
apo = Structure.from_file(os.path.join(module_dir, "Ag7P3S11_mp-683910_primitive.cif"))
apo.replace_species({"S": "O"})
p = RLSVolumePredictor(radii_type="atomic", check_isostructural=False)
assert p.predict(apo, aps) == approx(1196.31384276)
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_predict(self):
p_fast = DLSVolumePredictor(cutoff=0.0) # for speed on compressed cells
p_nolimit = DLSVolumePredictor(min_scaling=None, max_scaling=None) # no limits on scaling

fen = Structure.from_file(os.path.join(dir_path, "FeN_mp-6988.cif"))
fen = Structure.from_file(os.path.join(module_dir, "FeN_mp-6988.cif"))

assert p.predict(fen) == approx(18.2252568873)
fen.scale_lattice(fen.volume * 3.0)
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/tests/test_dimensionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def setUp(self):
mol_structure = Structure(
[[-2.316, 2.316, 2.160], [2.316, -2.316, 2.160], [2.316, 2.316, -2.160]],
["H", "C", "N"],
[[0.752, 0.752, 0.000], [0.004, 0.004, 0.0], [0.272, 0.272, 0.0]],
[[0.752, 0.752, 0], [0.004, 0.004, 0.0], [0.272, 0.272, 0.0]],
)
self.mol_structure = cnn.get_bonded_structure(mol_structure)
warnings.simplefilter("ignore")
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/tests/test_energy_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def tearDown(self):

def test_get_energy(self):
coords = [[0, 0, 0], [0.75, 0.75, 0.75], [0.5, 0.5, 0.5], [0.25, 0.25, 0.25]]
lattice = Lattice([[3.0, 0.0, 0.0], [1.0, 3.0, 0.00], [0.00, -2.0, 3.0]])
lattice = Lattice([[3.0, 0.0, 0.0], [1.0, 3.0, 0], [0, -2.0, 3.0]])
s = Structure(
lattice,
[
Expand Down
8 changes: 4 additions & 4 deletions pymatgen/analysis/tests/test_interface_reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ def setUp(self):
norm=True,
use_hull_energy=False,
)
with pytest.raises(Exception) as exc_info:
with pytest.raises(Exception) as exc:
_ = InterfacialReactivity(Composition("Li2O2"), Composition("Li"), pd=self.gpd, norm=True)
assert (
str(exc_info.value) == "Please use the GrandPotentialInterfacialReactivity "
str(exc.value) == "Please use the GrandPotentialInterfacialReactivity "
"class for interfacial reactions with open elements!"
)
with pytest.raises(Exception) as exc_info:
with pytest.raises(Exception) as exc:
_ = GrandPotentialInterfacialReactivity(
Composition("O2"),
Composition("Mn"),
Expand All @@ -157,7 +157,7 @@ def setUp(self):
# norm=False,
# include_no_mixing_energy=True,
)
assert str(exc_info.value) == "Please provide non-grand phase diagram to compute no_mixing_energy!"
assert str(exc.value) == "Please provide non-grand phase diagram to compute no_mixing_energy!"

self.ir = [ir_0, ir_1, ir_2, ir_3, ir_4, ir_5, ir_6, ir_7, ir_8, ir_9, ir_10, ir_11, ir_12]

Expand Down
42 changes: 21 additions & 21 deletions pymatgen/analysis/tests/test_molecule_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def generate_Si2O_cluster():
[0.625, 0.625, 0.125],
[0.625, 0.125, 0.625],
[0.125, 0.625, 0.625],
[0.500, 0.500, 0.500],
[0, 0, 0],
[0.750, 0.750, 0.750],
]

Expand Down Expand Up @@ -186,11 +186,11 @@ def test_to_and_from_dict(self):

def fit_with_mapper(self, mapper):
coords = [
[0.000000, 0.000000, 0.000000],
[0.000000, 0.000000, 1.089000],
[1.026719, 0.000000, -0.363000],
[-0.513360, -0.889165, -0.363000],
[-0.513360, 0.889165, -0.363000],
[0, 0, 0],
[0, 0, 1],
[1.026719, 0, -0],
[-0.513360, -0.889165, -0],
[-0.513360, 0.889165, -0],
]
mol1 = Molecule(["C", "H", "H", "H", "H"], coords)
op = SymmOp.from_origin_axis_angle([0, 0, 0], [0.1, 0.2, 0.3], 60)
Expand Down Expand Up @@ -285,11 +285,11 @@ def test_to_and_from_dict(self):

def test_rotated_molecule(self):
coords = [
[0.000000, 0.000000, 0.000000],
[0.000000, 0.000000, 1.089000],
[1.026719, 0.000000, -0.363000],
[-0.513360, -0.889165, -0.363000],
[-0.513360, 0.889165, -0.363000],
[0, 0, 0],
[0, 0, 1],
[1.026719, 0, -0],
[-0.513360, -0.889165, -0],
[-0.513360, 0.889165, -0],
]

op = SymmOp.from_origin_axis_angle([0, 0, 0], [0.1, 0.2, 0.3], 60)
Expand Down Expand Up @@ -366,11 +366,11 @@ def test_to_and_from_dict(self):

def test_rotated_molecule(self):
coords = [
[0.000000, 0.000000, 0.000000],
[0.000000, 0.000000, 1.089000],
[1.026719, 0.000000, -0.363000],
[-0.513360, -0.889165, -0.363000],
[-0.513360, 0.889165, -0.363000],
[0, 0, 0],
[0, 0, 1],
[1.026719, 0, -0],
[-0.513360, -0.889165, -0],
[-0.513360, 0.889165, -0],
]

op = SymmOp.from_origin_axis_angle([0, 0, 0], [0.1, 0.2, 0.3], 60)
Expand Down Expand Up @@ -471,11 +471,11 @@ def test_to_and_from_dict(self):

def test_rotated_molecule(self):
coords = [
[0.000000, 0.000000, 0.000000],
[0.000000, 0.000000, 1.089000],
[1.026719, 0.000000, -0.363000],
[-0.513360, -0.889165, -0.363000],
[-0.513360, 0.889165, -0.363000],
[0, 0, 0],
[0, 0, 1],
[1.026719, 0, -0],
[-0.513360, -0.889165, -0],
[-0.513360, 0.889165, -0],
]

op = SymmOp.from_origin_axis_angle([0, 0, 0], [0.1, 0.2, 0.3], 60)
Expand Down
8 changes: 4 additions & 4 deletions pymatgen/core/tests/test_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ def setUp(self):
]

def test_immutable(self):
with pytest.raises(TypeError) as exc_info:
with pytest.raises(TypeError) as exc:
self.comp[0]["Fe"] = 1

assert "'Composition' object does not support item assignment" in str(exc_info.value)
assert "'Composition' object does not support item assignment" in str(exc.value)

with pytest.raises(TypeError) as exc_info:
with pytest.raises(TypeError) as exc:
del self.comp[0]["Fe"]

assert "'Composition' object does not support item deletion" in str(exc_info.value)
assert "'Composition' object does not support item deletion" in str(exc.value)

def test_in(self):
assert "Fe" in self.comp[0]
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/core/tests/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,10 +899,10 @@ def test_add_oxidation_states_by_element(self):
for specie in site.species:
assert specie.oxi_state == oxidation_states[specie.symbol], "Wrong oxidation state assigned!"
oxidation_states = {"Fe": 2}
with pytest.raises(ValueError) as exc_info:
with pytest.raises(ValueError) as exc:
self.structure.add_oxidation_state_by_element(oxidation_states)

assert "Oxidation states not specified for all elements, missing={'Si'}" in str(exc_info.value)
assert "Oxidation states not specified for all elements, missing={'Si'}" in str(exc.value)

def test_add_oxidation_states_by_site(self):
self.structure.add_oxidation_state_by_site([2, -4])
Expand Down
8 changes: 4 additions & 4 deletions pymatgen/electronic_structure/tests/test_dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,16 @@ def test_dos_fp_exceptions(self):
dos_fp = self.dos.get_dos_fp(type="s", min_e=-10, max_e=0, n_bins=56, normalize=True)
dos_fp2 = self.dos.get_dos_fp(type="tdos", min_e=-10, max_e=0, n_bins=56, normalize=True)
# test exceptions
with pytest.raises(ValueError) as exc_info:
with pytest.raises(ValueError) as exc:
self.dos.get_dos_fp_similarity(dos_fp, dos_fp2, col=1, tanimoto=True, normalize=True)
assert (
str(exc_info.value) == "Cannot compute similarity index. Please set either "
str(exc.value) == "Cannot compute similarity index. Please set either "
"normalize=True or tanimoto=True or both to False."
)
with pytest.raises(ValueError) as exc_info:
with pytest.raises(ValueError) as exc:
self.dos.get_dos_fp(type="k", min_e=-10, max_e=0, n_bins=56, normalize=True)
assert (
str(exc_info.value) == "Please recheck type requested, either the orbital "
str(exc.value) == "Please recheck type requested, either the orbital "
"projections unavailable in input DOS or there's a typo in type."
)

Expand Down
Loading

0 comments on commit 5506eb3

Please sign in to comment.