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