blob: 7510fcad0c52257b1b4f2c2f9408f0bbaa61b4fd [file] [log] [blame]
Ryan Cui47f80e42013-04-01 19:01:54 -07001# Copyright (c) 2013 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
Don Garrett25f309a2014-03-19 14:02:12 -07005"""Unittests for cros."""
6
Mike Frysinger383367e2014-09-16 15:06:17 -04007from __future__ import print_function
8
Ralph Nathan1fc77f22015-04-21 15:05:48 -07009from chromite.lib import commandline
Ryan Cui47f80e42013-04-01 19:01:54 -070010from chromite.lib import cros_test_lib
11from chromite.lib import stats
12from chromite.lib import stats_unittest
13from chromite.scripts import cros
14
15
Ralph Nathan74e864d2015-05-11 12:13:53 -070016class RunScriptTest(cros_test_lib.WorkspaceTestCase):
Ryan Cui47f80e42013-04-01 19:01:54 -070017 """Test the main functionality."""
18
19 def setUp(self):
Ryan Cuicbd9bb62013-04-30 11:17:02 -070020 self.stats_module_mock = stats_unittest.StatsModuleMock()
21 self.StartPatcher(self.stats_module_mock)
Ryan Cui47f80e42013-04-01 19:01:54 -070022 self.PatchObject(cros, '_RunSubCommand', autospec=True)
23
Ryan Cuicbd9bb62013-04-30 11:17:02 -070024 def testStatsUpload(self, upload_count=1, return_value=0):
Ryan Cui47f80e42013-04-01 19:01:54 -070025 """Test stats uploading."""
26 return_value = cros.main(['chrome-sdk', '--board', 'lumpy'])
David Pursellffb90042015-03-23 09:21:41 -070027 # pylint: disable=protected-access
Ryan Cuicbd9bb62013-04-30 11:17:02 -070028 self.assertEquals(stats.StatsUploader._Upload.call_count, upload_count)
David Pursellffb90042015-03-23 09:21:41 -070029 # pylint: enable=protected-access
Ryan Cuicbd9bb62013-04-30 11:17:02 -070030 self.assertEquals(return_value, return_value)
31
32 def testStatsUploadError(self):
33 """We don't upload stats if the stats creation failed."""
34 self.stats_module_mock.stats_mock.init_exception = True
35 with cros_test_lib.LoggingCapturer():
36 self.testStatsUpload(upload_count=0)
Ralph Nathan1fc77f22015-04-21 15:05:48 -070037
David Pursellc7ba7842015-07-08 10:48:41 -070038 def testDefaultLogLevel(self):
39 """Test that the default log level is set to notice."""
Ralph Nathan1fc77f22015-04-21 15:05:48 -070040 arg_parser = self.PatchObject(commandline, 'ArgumentParser',
41 return_value=commandline.ArgumentParser())
42 cros.GetOptions({})
Ralph Nathan38372f42015-05-19 15:56:25 -070043 arg_parser.assert_called_with(caching=True, default_log_level='notice')