Skip to content

Commit

Permalink
fix repr of Model with no process
Browse files Browse the repository at this point in the history
  • Loading branch information
benbovy committed Oct 8, 2017
1 parent d345c94 commit 559b37e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions xsimlab/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,12 @@ def drop_processes(self, keys):
def __repr__(self):
n_inputs = sum([len(v) for v in self._input_vars.values()])

hdr = ("<xsimlab.Model (%d processes, %d inputs)>\n"
hdr = ("<xsimlab.Model (%d processes, %d inputs)>"
% (len(self._processes), n_inputs))

if not len(self._processes):
return hdr

max_line_length = 70
col_width = max([_calculate_col_width(var)
for var in self._input_vars.values()])
Expand All @@ -378,4 +381,4 @@ def __repr__(self):
proc_str += '\n' + '\n'.join(lines)
blocks.append(proc_str)

return hdr + '\n'.join(blocks)
return hdr + '\n' + '\n'.join(blocks)
3 changes: 3 additions & 0 deletions xsimlab/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,6 @@ def test_drop_processes(self, model):

def test_repr(self, model, model_repr):
assert repr(model) == model_repr

expected = "<xsimlab.Model (0 processes, 0 inputs)>"
assert repr(Model({})) == expected

0 comments on commit 559b37e

Please sign in to comment.