diff --git a/ipythonblocks/ipythonblocks.py b/ipythonblocks/ipythonblocks.py index 70f7025..b2addad 100644 --- a/ipythonblocks/ipythonblocks.py +++ b/ipythonblocks/ipythonblocks.py @@ -622,9 +622,9 @@ def flash(self, display_time=0.2): Amount of time, in seconds, to display the grid. """ + clear_output() self.show() time.sleep(display_time) - clear_output() def to_text(self, filename=None): """ diff --git a/ipythonblocks/test/test_misc.py b/ipythonblocks/test/test_misc.py index 08a9e4e..362d501 100644 --- a/ipythonblocks/test/test_misc.py +++ b/ipythonblocks/test/test_misc.py @@ -21,3 +21,14 @@ def test_flatten(): for i, x in enumerate(ipythonblocks._flatten(thing)): assert x == i + +def test_flash_should_clear_first(monkeypatch): + calls = [] + monkeypatch.setattr(ipythonblocks, "clear_output", lambda: calls.append("clear_output")) + monkeypatch.setattr(ipythonblocks.BlockGrid, "show", lambda self: calls.append("show")) + monkeypatch.setattr("time.sleep", lambda interval: calls.append("sleep(%d)" % interval)) + grid = ipythonblocks.BlockGrid(1, 1) + grid.flash(3) + assert calls[0] == "clear_output" + assert calls[1] == "show" + assert calls[2] == "sleep(3)"