Skip to content

Commit

Permalink
#50 add fake fast_print to CharacterBasedErikaMock; add simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchibaldBienetre committed Jan 26, 2020
1 parent a8d5149 commit 572ddac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 9 additions & 3 deletions erika/erika_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ def _write_byte(self, data, delay=0.5):
def decode(self, value):
raise Exception('Not supported yet')

def fast_print(self, text):
raise Exception('Not supported yet')


# to get exception-safe behavior, make sure __exit__ is always called (by using with-statements)
class CharacterBasedErikaMock(AbstractErikaMock):
Expand Down Expand Up @@ -223,6 +220,12 @@ def print_ascii(self, text):
sleep(self.delay_after_each_step)
self.stdscr.refresh()

def fast_print(self, text):
"""just emulates fast printing (doing line splitting + then normal printing)"""
for split in text.splitlines():
self.print_ascii(split)
self.crlf()

def delete_ascii(self, reversed_text):
text_length = len(reversed_text)
if text_length == 0:
Expand Down Expand Up @@ -340,5 +343,8 @@ def crlf(self):
def print_ascii(self, text):
raise Exception('Characters and character steps are not supported in microstep-based tests')

def fast_print(self, text):
raise Exception('Characters and character steps are not supported in microstep-based tests')

def delete_ascii(self, text):
raise Exception('Characters and character steps are not supported in microstep-based tests')
9 changes: 9 additions & 0 deletions tests/erika_mock_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ def test_delete_pixel(self):
my_erika.delete_pixel()
assert_print_output(self, my_erika, ["XXX X"])

def test_fast_print(self):
my_erika = CharacterBasedErikaMock(width=5, height=4, inside_unit_test=True)
lines = "line1\nline2\n\nline4"

my_erika.fast_print(lines)

expected_lines = ["line1", "line2", " ", "line4"]
assert_print_output(self, my_erika, expected_lines)


def main():
unittest.main()
Expand Down

0 comments on commit 572ddac

Please sign in to comment.