6ce84935a8a1a8bc071edc5ce131ec976926fbd4
[leap_pycommon.git] / src / leap / common / tests / test_check.py
1 # -*- coding: utf-8 -*-
2 # test_check.py
3 # Copyright (C) 2013 LEAP
4 #
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.
9 #
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.
14 #
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/>.
17 """
18 Tests for:
19     * leap/common/check.py
20 """
21 try:
22     import unittest2 as unittest
23 except ImportError:
24     import unittest
25
26 import mock
27
28 from leap.common import check
29
30 class CheckTests(unittest.TestCase):
31     def test_raises_on_false_condition(self):
32         with self.assertRaises(AssertionError):
33             check.leap_assert(False, "Condition")
34
35     def test_raises_on_none_condition(self):
36         with self.assertRaises(AssertionError):
37             check.leap_assert(None, "Condition")
38
39     def test_suceeds_with_good_condition(self):
40         check.leap_assert(True, "")
41
42     def test_raises_on_bad_type(self):
43         with self.assertRaises(AssertionError):
44             check.leap_assert_type(42, str)
45
46     def test_succeeds_on_good_type(self):
47         check.leap_assert_type(42, int)
48
49     @mock.patch("traceback.extract_stack", mock.MagicMock(return_value=None))
50     def test_does_not_raise_on_bug(self):
51         with self.assertRaises(AssertionError):
52             check.leap_assert(False, "")