blob: 77e8670acb3471e2007d90ff17b25e956c599eb2 [file] [log] [blame]
herbertxue1837cc92021-10-13 20:34:36 +08001# Copyright 2021 - The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Tests for metrics."""
15
16import sys
17import unittest
18
19from unittest import mock
20
21# pylint: disable=import-error, no-name-in-module, wrong-import-position
22sys.modules["asuite"] = mock.MagicMock()
23sys.modules["asuite.metrics"] = mock.MagicMock()
24from asuite import atest_utils
25from asuite.metrics import metrics_utils
26from acloud.internal.lib import driver_test_lib
27from acloud.metrics import metrics
28
29
30class MetricsTest(driver_test_lib.BaseDriverTest):
31 """Test metrics methods."""
32 def testLogUsage(self):
33 """Test LogUsage."""
34 self.Patch(atest_utils, "print_data_collection_notice")
35 self.Patch(metrics_utils, "send_start_event")
36 argv = ["acloud", "create"]
37 self.assertTrue(metrics.LogUsage(argv))
38
39 # Test arguments with "--no-metrics"
40 argv = ["acloud", "create", "--no-metrics"]
41 self.assertFalse(metrics.LogUsage(argv))
42
43 def testLogExitEvent(self):
44 """Test LogExitEvent."""
45 exit_code = 0
46 self.Patch(metrics_utils, "send_exit_event")
47 metrics.LogExitEvent(exit_code)
48 metrics_utils.send_exit_event.assert_called_once_with(
49 exit_code, stacktrace="", logs="")
50
51
52if __name__ == "__main__":
53 unittest.main()