From 60892ca99520be980ff70c61fc864fbe1db5a601 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Mon, 24 Feb 2014 16:21:58 -0500 Subject: [PATCH] tests for the new while helper Signed-off-by: Alfredo Deza --- teuthology/test/test_contextutil.py | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 teuthology/test/test_contextutil.py diff --git a/teuthology/test/test_contextutil.py b/teuthology/test/test_contextutil.py new file mode 100644 index 0000000000000..656f1f5c92acf --- /dev/null +++ b/teuthology/test/test_contextutil.py @@ -0,0 +1,51 @@ +from pytest import raises +from teuthology import contextutil + + +class TestSafeWhile(object): + + def setup(self): + self.fake_sleep = lambda s: True + self.s_while = contextutil.safe_while + + def test_5_5_5_deal(self): + with raises(contextutil.MaxWhileTries): + with self.s_while(_sleeper=self.fake_sleep) as bomb: + while 1: + bomb() + + def test_5_5_1_deal(self): + with raises(contextutil.MaxWhileTries) as error: + with self.s_while( + tries=1, + _sleeper=self.fake_sleep + ) as bomb: + while 1: + bomb() + + msg = error.value[0] + assert 'waiting for 5 seconds' in msg + + def test_1_5_5_deal(self): + with raises(contextutil.MaxWhileTries) as error: + with self.s_while( + sleep=1, + _sleeper=self.fake_sleep + ) as bomb: + while 1: + bomb() + + msg = error.value[0] + assert 'waiting for 55 seconds' in msg + + def test_5_1_5_deal(self): + with raises(contextutil.MaxWhileTries) as error: + with self.s_while( + increment=1, + _sleeper=self.fake_sleep + ) as bomb: + while 1: + bomb() + + msg = error.value[0] + assert 'waiting for 35 seconds' in msg -- 2.39.5