diff --git a/b_asic/resources.py b/b_asic/resources.py index fae30e870e94487aa0d600b7adbb25de8291db61..b3f97bdb1ba336bbc62e8ef07464fdac7b650d4a 100644 --- a/b_asic/resources.py +++ b/b_asic/resources.py @@ -502,6 +502,17 @@ class ProcessCollection: else: self.collection.remove(process) + def __contains__(self, process: Process) -> bool: + """ + Test if a process is part of this ProcessCollection + + Parameters + ---------- + process : :class:`~b_asic.process.Process` + The process to test. + """ + return process in self.collection + def plot( self, ax: Optional[Axes] = None, diff --git a/test/test_resources.py b/test/test_resources.py index a02348786b6244a0024b10eb2a85baad6f42b047..59ba49592cf5eb61f777d6e6687faa3df5046c17 100644 --- a/test/test_resources.py +++ b/test/test_resources.py @@ -38,6 +38,15 @@ class TestProcessCollectionPlainMemoryVariable: ) assert len(collection_split) == 3 + def test_contains(self): + collection = ProcessCollection([], schedule_time=10, cyclic=True) + m1 = PlainMemoryVariable(0, 0, {0: 3}) + assert m1 not in collection + collection.add_process(m1) + assert m1 in collection + collection.remove_process(m1) + assert m1 not in collection + def test_split_sequence_raises(self, simple_collection: ProcessCollection): with pytest.raises(KeyError, match="processes in `sequence` must be"): simple_collection.split_ports_sequentially(