Skip to content

Commit

Permalink
Added a small test for __repr__(). Fixed formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-lundberg committed Mar 14, 2020
1 parent ccd6437 commit 1f704e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 8 additions & 6 deletions simple_pid/PID.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ def __call__(self, input_, dt=None):
return output

def __repr__(self):
return ('{self.__class__.__name__}('
'Kp={self.Kp!r}, Ki={self.Ki!r}, Kd={self.Kd!r}, '
'setpoint={self.setpoint!r}, sample_time={self.sample_time!r}, '
'output_limits={self.output_limits!r}, auto_mode={self.auto_mode!r}, '
'proportional_on_measurement={self.proportional_on_measurement!r}'
')').format(self=self)
return (
'{self.__class__.__name__}('
'Kp={self.Kp!r}, Ki={self.Ki!r}, Kd={self.Kd!r}, '
'setpoint={self.setpoint!r}, sample_time={self.sample_time!r}, '
'output_limits={self.output_limits!r}, auto_mode={self.auto_mode!r}, '
'proportional_on_measurement={self.proportional_on_measurement!r}'
')'
).format(self=self)

@property
def components(self):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ def test_clamp():
assert _clamp(100, (-10, 10)) == 10


def test_repr():
pid = PID(1, 2, 3, setpoint=10)
new_pid = eval(repr(pid))

assert new_pid.Kp == 1
assert new_pid.Ki == 2
assert new_pid.Kd == 3
assert new_pid.setpoint == 10


def test_converge_system():
pid = PID(1, 0.8, 0.04, setpoint=5, output_limits=(-5, 5))
PV = 0 # process variable
Expand Down

0 comments on commit 1f704e9

Please sign in to comment.