Skip to content
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
2 changes: 1 addition & 1 deletion src/qrules/_system_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def create_particle(
particle = particle_db.find(int(edge_props[EdgeQuantumNumbers.pid]))
if EdgeQuantumNumbers.spin_projection not in edge_props:
raise ValueError(
"GraphEdgePropertyMap does not contain a spin projection!"
f"{GraphEdgePropertyMap.__name__} does not contain a spin projection"
)
spin_projection = edge_props[EdgeQuantumNumbers.spin_projection]

Expand Down
6 changes: 4 additions & 2 deletions src/qrules/combinatorics.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def match_external_edges(
graphs: List[StateTransitionGraph[ParticleWithSpin]],
) -> None:
if not isinstance(graphs, list):
raise TypeError("graphs argument is not of type list!")
raise TypeError("graphs argument is not of type list")
if not graphs:
return
ref_graph_id = 0
Expand Down Expand Up @@ -476,7 +476,9 @@ def perform_external_edge_identical_particle_combinatorics(
combinatorics!
"""
if not isinstance(graph, StateTransitionGraph):
raise TypeError("graph argument is not of type StateTransitionGraph!")
raise TypeError(
f"graph argument is not of type {StateTransitionGraph.__class__}"
)
temp_new_graphs = _external_edge_identical_particle_combinatorics(
graph, __get_final_state_edge_ids
)
Expand Down
2 changes: 1 addition & 1 deletion src/qrules/particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __attrs_post_init__(self) -> None:
if not (self.projection - self.magnitude).is_integer():
raise ValueError(
f"{self.__class__.__name__}{(self.magnitude, self.projection)}: "
"(projection - magnitude) should be integer! "
"(projection - magnitude) should be integer"
)

def __eq__(self, other: object) -> bool:
Expand Down
8 changes: 4 additions & 4 deletions src/qrules/solving.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ def __init__(
scoresheet: Callable[[bool], None],
) -> None:
if not callable(rule):
raise TypeError("rule has to be a callable!")
raise TypeError("rule argument has to be a callable")
self.__rule = rule
(
self.__check_rule_requirements,
Expand Down Expand Up @@ -1003,7 +1003,7 @@ def __update_variable_lists(
raise ValueError(
"The variable with name "
+ qn_type.__name__
+ "does not appear in the variable mapping!"
+ "does not appear in the variable mapping"
)


Expand All @@ -1023,7 +1023,7 @@ def __init__(
score_callback: Callable[[bool], None],
) -> None:
if not callable(rule):
raise TypeError("rule has to be a callable!")
raise TypeError("rule argument has to be a callable")
self.__rule = rule
(
self.__check_rule_requirements,
Expand Down Expand Up @@ -1164,5 +1164,5 @@ def __update_variable_lists(
raise ValueError(
f"The variable with name {qn_type.__name__} and a graph "
f"element index of {index} does not appear in the variable "
f"mapping!"
f"mapping"
)
26 changes: 15 additions & 11 deletions src/qrules/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def __verify(self) -> None:
connected_nodes = edge.get_connected_nodes()
if not connected_nodes:
raise ValueError(
f"Edge nr. {edge_id} is not connected to any node ({edge})"
f"Edge nr. {edge_id} is not connected to any other node ({edge})"
)
if not connected_nodes <= self.nodes:
raise ValueError(
Expand All @@ -177,7 +177,7 @@ def __check_isolated_nodes(self) -> None:
surrounding_nodes = self.__get_surrounding_nodes(node_id)
if not surrounding_nodes:
raise ValueError(
f"Node {node_id} is unconnected to any other node"
f"Node {node_id} is not connected to any other node"
)

def __get_surrounding_nodes(self, node_id: int) -> Set[int]:
Expand Down Expand Up @@ -322,20 +322,20 @@ def freeze(self) -> Topology:
)

def add_node(self, node_id: int) -> None:
"""Adds a node with id node_id.
"""Adds a node nr. node_id.

Raises:
ValueError: if node_id already exists
"""
if node_id in self.nodes:
raise ValueError(f"Node with id {node_id} already exists!")
raise ValueError(f"Node nr. {node_id} already exists")
self.nodes.add(node_id)

def add_edges(self, edge_ids: List[int]) -> None:
"""Add edges with the ids in the edge_ids list."""
for edge_id in edge_ids:
if edge_id in self.edges:
raise ValueError(f"Edge with id {edge_id} already exists!")
raise ValueError(f"Edge nr. {edge_id} already exists")
self.edges[edge_id] = Edge()

def attach_edges_to_node_ingoing(
Expand All @@ -356,10 +356,10 @@ def attach_edges_to_node_ingoing(
# first check if the ingoing edges are all available
for edge_id in ingoing_edge_ids:
if edge_id not in self.edges:
raise ValueError(f"Edge with id {edge_id} does not exist!")
raise ValueError(f"Edge nr. {edge_id} does not exist")
if self.edges[edge_id].ending_node_id is not None:
raise ValueError(
f"Edge with id {edge_id} is already ingoing to"
f"Edge nr. {edge_id} is already ingoing to"
f" node {self.edges[edge_id].ending_node_id}"
)

Expand All @@ -377,10 +377,10 @@ def attach_edges_to_node_outgoing(
# first check if the ingoing edges are all available
for edge_id in outgoing_edge_ids:
if edge_id not in self.edges:
raise ValueError(f"Edge with id {edge_id} does not exist!")
raise ValueError(f"Edge nr. {edge_id} does not exist")
if self.edges[edge_id].originating_node_id is not None:
raise ValueError(
f"Edge with id {edge_id} is already outgoing from"
f"Edge nr. {edge_id} is already outgoing from"
f" node {self.edges[edge_id].originating_node_id}"
)

Expand All @@ -406,9 +406,13 @@ class InteractionNode:

def __attrs_post_init__(self) -> None:
if self.number_of_ingoing_edges < 1:
raise ValueError("NumberOfIngoingEdges has to be larger than 0")
raise ValueError(
"Number of incoming edges has to be larger than 0"
)
if self.number_of_outgoing_edges < 1:
raise ValueError("NumberOfOutgoingEdges has to be larger than 0")
raise ValueError(
"Number of outgoing edges has to be larger than 0"
)


class SimpleStateTransitionTopologyBuilder:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/io/test_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_not_implemented_errors(
io.load(__file__)
with pytest.raises(NotImplementedError):
io.write(particle_selection, output_dir + "test.py")
with pytest.raises(ValueError, match="No file extension in file name"):
with pytest.raises(ValueError, match=r"No file extension in file name"):
io.write(particle_selection, output_dir + "no_file_extension")
with pytest.raises(NotImplementedError):
io.write(666, output_dir + "wont_work_anyway.yml")
Expand Down
19 changes: 7 additions & 12 deletions tests/unit/test_combinatorics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# pylint: disable=redefined-outer-name

# pylint: disable=no-self-use, redefined-outer-name
from math import factorial

import pytest
Expand Down Expand Up @@ -85,8 +84,7 @@ def test_generate_outer_edge_permutations(


class TestKinematicRepresentation:
@staticmethod
def test_constructor():
def test_constructor(self):
representation = _KinematicRepresentation(
initial_state=["J/psi"],
final_state=["gamma", "pi0"], # type: ignore
Expand All @@ -97,8 +95,7 @@ def test_constructor():
assert representation.initial_state is None
assert representation.final_state == [["gamma", "pi0"]]

@staticmethod
def test_from_topology(three_body_decay: Topology):
def test_from_topology(self, three_body_decay: Topology):
pi0 = ("pi0", [0])
gamma = ("gamma", [-1, 1])
edge_props = {
Expand Down Expand Up @@ -141,8 +138,7 @@ def test_from_topology(three_body_decay: Topology):
)
assert kinematic_representation2 != kinematic_representation3

@staticmethod
def test_repr_and_equality():
def test_repr_and_equality(self):
kinematic_representation = _KinematicRepresentation(
initial_state=[["J/psi"]],
final_state=[["gamma", "pi0"], ["gamma", "pi0", "pi0"]],
Expand All @@ -152,8 +148,7 @@ def test_repr_and_equality():
)
assert constructed_from_repr == kinematic_representation

@staticmethod
def test_in_operator():
def test_in_operator(self):
kinematic_representation = _KinematicRepresentation(
[["gamma", "pi0"], ["gamma", "pi0", "pi0"]],
)
Expand All @@ -163,11 +158,11 @@ def test_in_operator():
assert subset_representation in kinematic_representation
assert [["J/psi"]] not in kinematic_representation
assert [["gamma", "pi0"]] in kinematic_representation
with pytest.raises(ValueError, match="Cannot compare "):
with pytest.raises(ValueError, match=r"Cannot compare "):
assert float() in kinematic_representation
with pytest.raises(
ValueError,
match="Comparison representation needs to be a list of lists",
match=r"Comparison representation needs to be a list of lists",
):
assert ["should be nested list"] in kinematic_representation

Expand Down
Loading