Skip to content
Snippets Groups Projects
Commit d73a3b90 authored by Mikael Henriksson's avatar Mikael Henriksson :runner:
Browse files

resources.py: add add_process and remove_process methods to ProcessCollection

parent 3f26530c
Branches
No related tags found
1 merge request!354resources.py: add add_process and remove_process methods to ProcessCollection
Pipeline #96741 passed
...@@ -443,7 +443,7 @@ class ProcessCollection: ...@@ -443,7 +443,7 @@ class ProcessCollection:
return self._schedule_time return self._schedule_time
def __len__(self): def __len__(self):
return len(self._collection) return len(self.collection)
def add_process(self, process: Process): def add_process(self, process: Process):
""" """
...@@ -454,7 +454,25 @@ class ProcessCollection: ...@@ -454,7 +454,25 @@ class ProcessCollection:
process : Process process : Process
The process object to be added to the collection. The process object to be added to the collection.
""" """
self._collection.add(process) self.collection.add(process)
def remove_process(self, process: Process):
"""
Remove a processes from this process collection.
Raises KeyError if the process is not in this collection.
Parameters
----------
process : Process
The processes object to remove from this collection
"""
if process not in self.collection:
raise KeyError(
f"Can't remove process: '{process}', as it is not in collection."
)
else:
self.collection.remove(process)
def plot( def plot(
self, self,
......
...@@ -37,8 +37,8 @@ class TestProcessCollectionPlainMemoryVariable: ...@@ -37,8 +37,8 @@ class TestProcessCollectionPlainMemoryVariable:
fig, ax = plt.subplots(1, 2) fig, ax = plt.subplots(1, 2)
assignment = simple_collection.left_edge_cell_assignment() assignment = simple_collection.left_edge_cell_assignment()
for cell in assignment: for cell in assignment:
assignment[cell].plot(ax=ax[1], row=cell) assignment[cell].plot(ax=ax[1], row=cell) # type: ignore
simple_collection.plot(ax[0]) simple_collection.plot(ax[0]) # type:ignore
return fig return fig
def test_cell_assignment_matrix_transposer(self): def test_cell_assignment_matrix_transposer(self):
...@@ -132,3 +132,16 @@ class TestProcessCollectionPlainMemoryVariable: ...@@ -132,3 +132,16 @@ class TestProcessCollectionPlainMemoryVariable:
def test_show(self, simple_collection: ProcessCollection): def test_show(self, simple_collection: ProcessCollection):
simple_collection.show() simple_collection.show()
def test_add_remove_process(self, simple_collection: ProcessCollection):
new_proc = PlainMemoryVariable(1, 0, {0: 3})
assert len(simple_collection) == 7
assert new_proc not in simple_collection
simple_collection.add_process(new_proc)
assert len(simple_collection) == 8
assert new_proc in simple_collection
simple_collection.remove_process(new_proc)
assert len(simple_collection) == 7
assert new_proc not in simple_collection
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment