# HG changeset patch # User Brian Neal # Date 1370392297 18000 # Node ID 45af97a43ee164391c80c66505ee35f2834223c4 # Parent 1e1c4b41135d31fe39b26be758d244298440cc2f Gave KeyWheel a __str__() method and test. diff -r 1e1c4b41135d -r 45af97a43ee1 m209/key_wheel.py --- a/m209/key_wheel.py Tue Jun 04 18:49:12 2013 -0500 +++ b/m209/key_wheel.py Tue Jun 04 19:31:37 2013 -0500 @@ -50,6 +50,15 @@ # rotational position; 0 means first letter shown to operator self.pos = 0 + def __str__(self): + parts = [] + for n, c in enumerate(self.letters): + if self.pins[n]: + parts.append(c + '-') + else: + parts.append('-' + c) + return ' '.join(parts) + def reset_pins(self): """Reset all pins to the ineffective state.""" self.pins = [False] * self.num_pins diff -r 1e1c4b41135d -r 45af97a43ee1 m209/tests/test_key_wheel.py --- a/m209/tests/test_key_wheel.py Tue Jun 04 18:49:12 2013 -0500 +++ b/m209/tests/test_key_wheel.py Tue Jun 04 19:31:37 2013 -0500 @@ -105,3 +105,8 @@ for c in letters: kw.set_pos(c) self.assertEqual(c, kw.display()) + + def test_str(self): + kw = KeyWheel(string.ascii_uppercase, 'P', 'FGIKOPRSUVWYZ') + self.assertEqual(str(kw), ('-A -B -C -D -E F- G- -H I- -J K- -L -M -N ' + 'O- P- -Q R- S- -T U- V- W- -X Y- Z-'))