1# 2# Copyright (c) 2010 Testrepository Contributors 3# 4# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause 5# license at the users choice. A copy of both licenses are available in the 6# project source as Apache-2.0 and BSD. You may not use this file except in 7# compliance with one of these two licences. 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# license you chose for the specific language governing permissions and 13# limitations under that license. 14 15from datetime import ( 16 datetime, 17 timedelta, 18 ) 19import sys 20 21from testtools import TestCase 22 23from testrepository.results import SummarizingResult 24 25 26class TestSummarizingResult(TestCase): 27 28 def test_empty(self): 29 result = SummarizingResult() 30 result.startTestRun() 31 result.stopTestRun() 32 self.assertEqual(0, result.testsRun) 33 self.assertEqual(0, result.get_num_failures()) 34 self.assertIs(None, result.get_time_taken()) 35 36 def test_time_taken(self): 37 result = SummarizingResult() 38 now = datetime.now() 39 result.startTestRun() 40 result.status(timestamp=now) 41 result.status(timestamp=now + timedelta(seconds=5)) 42 result.stopTestRun() 43 self.assertEqual(5.0, result.get_time_taken()) 44 45 def test_num_failures(self): 46 result = SummarizingResult() 47 result.startTestRun() 48 try: 49 1/0 50 except ZeroDivisionError: 51 error = sys.exc_info() 52 result.status(test_id='foo', test_status='fail') 53 result.status(test_id='foo', test_status='fail') 54 result.stopTestRun() 55 self.assertEqual(2, result.get_num_failures()) 56 57 def test_tests_run(self): 58 result = SummarizingResult() 59 result.startTestRun() 60 for i in range(5): 61 result.status(test_id='foo', test_status='success') 62 result.stopTestRun() 63 self.assertEqual(5, result.testsRun) 64