1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2013 LEAP
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * leap/common/check.py
22 import unittest2 as unittest
28 from leap.common import check
31 class CheckTests(unittest.TestCase):
32 def test_raises_on_false_condition(self):
33 with self.assertRaises(AssertionError):
34 check.leap_assert(False, "Condition")
36 def test_raises_on_none_condition(self):
37 with self.assertRaises(AssertionError):
38 check.leap_assert(None, "Condition")
40 def test_suceeds_with_good_condition(self):
41 check.leap_assert(True, "")
43 def test_raises_on_bad_type(self):
44 with self.assertRaises(AssertionError):
45 check.leap_assert_type(42, str)
47 def test_succeeds_on_good_type(self):
48 check.leap_assert_type(42, int)
50 @mock.patch("traceback.extract_stack", mock.MagicMock(return_value=None))
51 def test_does_not_raise_on_bug(self):
52 with self.assertRaises(AssertionError):
53 check.leap_assert(False, "")