From 0373fb8ba030dd38a274f6602b17ae4b459c6fdb Mon Sep 17 00:00:00 2001 From: Terry Yin Date: Tue, 6 May 2014 15:21:05 +0800 Subject: [PATCH 1/2] call clear_output first when flash --- ipythonblocks/ipythonblocks.py | 2 +- ipythonblocks/test/test_misc.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) 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..874e7f1 100644 --- a/ipythonblocks/test/test_misc.py +++ b/ipythonblocks/test/test_misc.py @@ -21,3 +21,28 @@ 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)" + + +import os.path +from os.path import expanduser +def getssh(): # pseudo application code + return os.path.join(expanduser("~admin"), '.ssh') + +def test_mytest(monkeypatch): + def mockreturn(path): + return '/abc' + monkeypatch.setattr(__name__+'.expanduser', mockreturn) + x = getssh() + assert x == '/abc/.ssh' From 34acdbce32ebf76bc855c689ef57f2d3edd04d9e Mon Sep 17 00:00:00 2001 From: Terry Yin Date: Tue, 6 May 2014 15:22:34 +0800 Subject: [PATCH 2/2] call clear_output first when flash --- ipythonblocks/test/test_misc.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/ipythonblocks/test/test_misc.py b/ipythonblocks/test/test_misc.py index 874e7f1..362d501 100644 --- a/ipythonblocks/test/test_misc.py +++ b/ipythonblocks/test/test_misc.py @@ -22,7 +22,6 @@ def test_flatten(): assert x == i - def test_flash_should_clear_first(monkeypatch): calls = [] monkeypatch.setattr(ipythonblocks, "clear_output", lambda: calls.append("clear_output")) @@ -33,16 +32,3 @@ def test_flash_should_clear_first(monkeypatch): assert calls[0] == "clear_output" assert calls[1] == "show" assert calls[2] == "sleep(3)" - - -import os.path -from os.path import expanduser -def getssh(): # pseudo application code - return os.path.join(expanduser("~admin"), '.ssh') - -def test_mytest(monkeypatch): - def mockreturn(path): - return '/abc' - monkeypatch.setattr(__name__+'.expanduser', mockreturn) - x = getssh() - assert x == '/abc/.ssh'