diff options
author | Ruben Rodriguez Buchillon <coconutruben@chromium.org> | 2018-07-16 19:21:42 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-07-27 08:51:03 -0700 |
commit | cd68cd250118217a471e34cfbcfc18c7cf9347f3 (patch) | |
tree | 251b4c42bc95dd844d5e00620efb6bc650bbb963 /extra/usb_power/powerlog_unittest.py | |
parent | aae40533b1a390994f4a112d7d46e2595747d784 (diff) | |
download | chrome-ec-cd68cd250118217a471e34cfbcfc18c7cf9347f3.tar.gz |
stats_manager: prepare StatsManager to be a utility used in hdctools
This is the first CL in a series of CLs to start using StatsManager in
servo/hdctools (package depends on ec-devutils, as in this package).
This CL:
- beefs up StatsManager to handle unavailable units more gracefully
- adds a few more tests to stats_manager_unittest.py
- adds some minor unit testing for powerlog's file retrieval logic
BRANCH=None
BUG=chromium:760267
TEST=manual testing, unit tests still pass, powerlog still works
Change-Id: Ifcdfcc482008484fbc21326c6f087ebf466c3e74
Signed-off-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1140025
Reviewed-by: Mengqi Guo <mqg@chromium.org>
Diffstat (limited to 'extra/usb_power/powerlog_unittest.py')
-rw-r--r-- | extra/usb_power/powerlog_unittest.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/extra/usb_power/powerlog_unittest.py b/extra/usb_power/powerlog_unittest.py new file mode 100644 index 0000000000..7058c57aa7 --- /dev/null +++ b/extra/usb_power/powerlog_unittest.py @@ -0,0 +1,49 @@ +# Copyright 2018 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +"""Unit tests for powerlog.""" + +import os +import shutil +import tempfile +import unittest + +import powerlog + +class TestPowerlog(unittest.TestCase): + """Test to verify powerlog util methods work as expected.""" + + def setUp(self): + """Set up data and create a temporary directory to save data and stats.""" + self.tempdir = tempfile.mkdtemp() + self.filename = 'testfile' + self.filepath = os.path.join(self.tempdir, self.filename) + with open(self.filepath, 'w') as f: + f.write('') + + def tearDown(self): + """Delete the temporary directory and its content.""" + shutil.rmtree(self.tempdir) + + def test_ProcessFilenameAbsoluteFilePath(self): + """Absolute file path is returned unchanged.""" + processed_fname = powerlog.process_filename(self.filepath) + self.assertEqual(self.filepath, processed_fname) + + def test_ProcessFilenameRelativeFilePath(self): + """Finds relative file path inside a known config location.""" + original = powerlog.CONFIG_LOCATIONS + powerlog.CONFIG_LOCATIONS = [self.tempdir] + processed_fname = powerlog.process_filename(self.filename) + try: + self.assertEqual(self.filepath, processed_fname) + finally: + powerlog.CONFIG_LOCATIONS = original + + def test_ProcessFilenameInvalid(self): + """IOError is raised when file cannot be found by any of the four ways.""" + with self.assertRaises(IOError): + powerlog.process_filename(self.filename) + +if __name__ == '__main__': + unittest.main() |