[tests] adapt events tests to recent changes
[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
31 class CheckTests(unittest.TestCase):
32     def test_raises_on_false_condition(self):
33         with self.assertRaises(AssertionError):
34             check.leap_assert(False, "Condition")
35
36     def test_raises_on_none_condition(self):
37         with self.assertRaises(AssertionError):
38             check.leap_assert(None, "Condition")
39
40     def test_suceeds_with_good_condition(self):
41         check.leap_assert(True, "")
42
43     def test_raises_on_bad_type(self):
44         with self.assertRaises(AssertionError):
45             check.leap_assert_type(42, str)
46
47     def test_succeeds_on_good_type(self):
48         check.leap_assert_type(42, int)
49
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, "")