1# Copyright (c) 2014 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import collections 6 7import common 8from autotest_lib.client.common_lib.test_utils import unittest 9from autotest_lib.site_utils import host_history_utils 10 11class HostHistoryUtilsTests(unittest.TestCase): 12 """Test functions in host_history_utils. 13 """ 14 15 def testCalculateStatusTimes(self): 16 """Test function calculate_status_times. 17 """ 18 # Locks in the middle does not affect the host history. 19 locked_intervals = [(2, 4), (4, 8)] 20 results = host_history_utils.calculate_status_times( 21 t_start=0, t_end=10, int_status='Ready', metadata={}, 22 locked_intervals=locked_intervals) 23 expected = collections.OrderedDict( 24 [((0, 4), {'status': 'Ready', 'metadata': {}}), 25 ((4, 8), {'status': 'Ready', 'metadata': {}}), 26 ((8, 10), {'status': 'Ready', 'metadata': {}})]) 27 self.assertEqual(results, expected) 28 29 locked_intervals = [(0, 4), (11, 14), (16, 18)] 30 results = host_history_utils.calculate_status_times( 31 t_start=10, t_end=15, int_status='Ready', metadata={}, 32 locked_intervals=locked_intervals) 33 expected = collections.OrderedDict( 34 [((10, 14), {'status': 'Ready', 'metadata': {}}), 35 ((14, 15), {'status': 'Ready', 'metadata': {}})]) 36 self.assertEqual(results, expected) 37 38 locked_intervals = [(2, 4), (4, 8)] 39 results = host_history_utils.calculate_status_times( 40 t_start=0, t_end=10, int_status='Running', metadata={}, 41 locked_intervals=locked_intervals) 42 expected = collections.OrderedDict( 43 [((0, 4), {'status': 'Running', 'metadata': {}}), 44 ((4, 8), {'status': 'Running', 'metadata': {}}), 45 ((8, 10), {'status': 'Running', 'metadata': {}})]) 46 self.assertEqual(results, expected) 47 48 locked_intervals = [(1, 8)] 49 results = host_history_utils.calculate_status_times( 50 t_start=2, t_end=5, int_status='Running', metadata={}, 51 locked_intervals=locked_intervals) 52 expected = collections.OrderedDict( 53 [((2, 5), {'status': 'Locked', 'metadata': {}})]) 54 self.assertEqual(results, expected) 55 56 57if __name__ == '__main__': 58 unittest.main() 59