1 # -*- coding: utf-8 -*-
2 # leap.common.testing.test_basetest
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/>.
18 Unittests for base test
19 ...becase it's oh so meta"""
21 import unittest2 as unittest
28 from leap.testing.basetest import BaseLeapTest
30 # global for tempdir checking
34 class _TestCaseRunner(object):
35 def run_testcase(self, testcase=None):
38 loader = unittest.TestLoader()
39 suite = loader.loadTestsFromTestCase(testcase)
41 # Create runner, and run testcase
42 io = StringIO.StringIO()
43 runner = unittest.TextTestRunner(stream=io)
44 results = runner.run(suite)
48 class TestAbstractBaseLeapTest(unittest.TestCase, _TestCaseRunner):
50 def test_abstract_base_class(self):
51 class _BaseTest(BaseLeapTest):
52 def test_dummy_method(self):
55 def test_tautology(self):
58 results = self.run_testcase(_BaseTest)
60 # should be 2 errors: NotImplemented
61 # raised for setUp/tearDown
62 self.assertEquals(results.testsRun, 2)
63 self.assertEquals(len(results.failures), 0)
64 self.assertEquals(len(results.errors), 2)
67 class TestInitBaseLeapTest(BaseLeapTest):
75 def test_path_is_changed(self):
76 os_path = os.environ['PATH']
77 self.assertTrue(os_path.startswith(self.tempdir))
79 def test_old_path_is_saved(self):
80 self.assertTrue(len(self.old_path) > 1)
83 class TestCleanedBaseLeapTest(unittest.TestCase, _TestCaseRunner):
85 def test_tempdir_is_cleaned_after_tests(self):
86 class _BaseTest(BaseLeapTest):
89 _tempdir = self.tempdir
94 def test_tempdir_created(self):
95 self.assertTrue(os.path.isdir(self.tempdir))
97 def test_tempdir_created_on_setupclass(self):
98 self.assertEqual(_tempdir, self.tempdir)
100 results = self.run_testcase(_BaseTest)
101 self.assertEquals(results.testsRun, 2)
102 self.assertEquals(len(results.failures), 0)
103 self.assertEquals(len(results.errors), 0)
105 # did we cleaned the tempdir?
106 self.assertFalse(os.path.isdir(_tempdir))
108 if __name__ == "__main__":