• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python2
2#
3# Copyright 2014 Google Inc. All Rights Reserved.
4"""Unittest for crosperf."""
5
6from __future__ import print_function
7
8import unittest
9
10import settings_factory
11
12
13class BenchmarkSettingsTest(unittest.TestCase):
14  """Class to test benchmark settings."""
15
16  def test_init(self):
17    res = settings_factory.BenchmarkSettings('b_settings')
18    self.assertIsNotNone(res)
19    self.assertEqual(len(res.fields), 6)
20    self.assertEqual(res.GetField('test_name'), '')
21    self.assertEqual(res.GetField('test_args'), '')
22    self.assertEqual(res.GetField('iterations'), 1)
23    self.assertEqual(res.GetField('suite'), '')
24
25
26class LabelSettingsTest(unittest.TestCase):
27  """Class to test label settings."""
28
29  def test_init(self):
30    res = settings_factory.LabelSettings('l_settings')
31    self.assertIsNotNone(res)
32    self.assertEqual(len(res.fields), 9)
33    self.assertEqual(res.GetField('chromeos_image'), '')
34    self.assertEqual(res.GetField('autotest_path'), '')
35    self.assertEqual(res.GetField('chromeos_root'), '')
36    self.assertEqual(res.GetField('remote'), None)
37    self.assertEqual(res.GetField('image_args'), '')
38    self.assertEqual(res.GetField('cache_dir'), '')
39    self.assertEqual(res.GetField('chrome_src'), '')
40    self.assertEqual(res.GetField('build'), '')
41
42
43class GlobalSettingsTest(unittest.TestCase):
44  """Class to test global settings."""
45
46  def test_init(self):
47    res = settings_factory.GlobalSettings('g_settings')
48    self.assertIsNotNone(res)
49    self.assertEqual(len(res.fields), 25)
50    self.assertEqual(res.GetField('name'), '')
51    self.assertEqual(res.GetField('board'), '')
52    self.assertEqual(res.GetField('remote'), None)
53    self.assertEqual(res.GetField('rerun_if_failed'), False)
54    self.assertEqual(res.GetField('rm_chroot_tmp'), False)
55    self.assertEqual(res.GetField('email'), None)
56    self.assertEqual(res.GetField('rerun'), False)
57    self.assertEqual(res.GetField('same_specs'), True)
58    self.assertEqual(res.GetField('same_machine'), False)
59    self.assertEqual(res.GetField('iterations'), 1)
60    self.assertEqual(res.GetField('chromeos_root'), '')
61    self.assertEqual(res.GetField('logging_level'), 'average')
62    self.assertEqual(res.GetField('acquire_timeout'), 0)
63    self.assertEqual(res.GetField('perf_args'), '')
64    self.assertEqual(res.GetField('cache_dir'), '')
65    self.assertEqual(res.GetField('cache_only'), False)
66    self.assertEqual(res.GetField('no_email'), False)
67    self.assertEqual(res.GetField('show_all_results'), False)
68    self.assertEqual(res.GetField('share_cache'), '')
69    self.assertEqual(res.GetField('results_dir'), '')
70    self.assertEqual(res.GetField('chrome_src'), '')
71
72
73class SettingsFactoryTest(unittest.TestCase):
74  """Class to test SettingsFactory."""
75
76  def test_get_settings(self):
77    self.assertRaises(Exception, settings_factory.SettingsFactory.GetSettings,
78                      'global', 'bad_type')
79
80    l_settings = settings_factory.SettingsFactory().GetSettings('label',
81                                                                'label')
82    self.assertIsInstance(l_settings, settings_factory.LabelSettings)
83    self.assertEqual(len(l_settings.fields), 9)
84
85    b_settings = settings_factory.SettingsFactory().GetSettings('benchmark',
86                                                                'benchmark')
87    self.assertIsInstance(b_settings, settings_factory.BenchmarkSettings)
88    self.assertEqual(len(b_settings.fields), 6)
89
90    g_settings = settings_factory.SettingsFactory().GetSettings('global',
91                                                                'global')
92    self.assertIsInstance(g_settings, settings_factory.GlobalSettings)
93    self.assertEqual(len(g_settings.fields), 25)
94
95
96if __name__ == '__main__':
97  unittest.main()
98