Fix #353 - String representation of network elements

Currently the string representation of some elements in elements.py refer to parameters that are not assigned until the propagate function runs.
Printing an element or trying to access its string representation before propagation therefore raises a TypeError.

This patch should fix the issue.

Change-Id: I29962f3c00e1f4fb7935535d4514a9579bc0c918
Signed-off-by: Jonas Mårtensson <jonas.martensson@ri.se>
This commit is contained in:
Jonas Mårtensson
2020-04-29 10:29:44 +02:00
parent 4cf4db9bc2
commit c87be89e07

View File

@@ -147,6 +147,9 @@ class Roadm(Node):
return f'{type(self).__name__}(uid={self.uid!r}, loss={self.loss!r})'
def __str__(self):
if self.effective_loss is None:
return f'{type(self).__name__} {self.uid}'
return '\n'.join([f'{type(self).__name__} {self.uid}',
f' effective loss (dB): {self.effective_loss:.2f}',
f' pch out (dBm): {self.effective_pch_out_db!r}'])
@@ -233,6 +236,7 @@ class Fiber(Node):
super().__init__(*args, params=FiberParams(**params), **kwargs)
self.carriers_in = None
self.carriers_out = None
self.pch_out_db = None
self.nli_solver = NliSolver(self)
@property
@@ -260,6 +264,9 @@ class Fiber(Node):
f'loss={round(self.loss,1)!r}dB)'
def __str__(self):
if self.pch_out_db is None:
return f'{type(self).__name__} {self.uid}'
return '\n'.join([f'{type(self).__name__} {self.uid}',
f' type_variety: {self.type_variety}',
f' length (km): '