diff options
author | Zhizhou Yang <zhizhouy@google.com> | 2020-01-14 16:49:12 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-01-16 03:36:24 +0000 |
commit | 0410b6515691a2fd3410917849d32495490d6999 (patch) | |
tree | f456416e7706148c2505789bc51f3966c50b071c /crosperf | |
parent | c977ae00dfd11ebd7c9212b04d0cf1808ea9bfc6 (diff) | |
download | toolchain-utils-0410b6515691a2fd3410917849d32495490d6999.tar.gz |
crosperf: fix pylint for crosperf
This is the first step of python 3 migration for crosperf
TEST=Passed presubmit for all .py files in crosperf
BUG=chromium:1011676
Change-Id: I615d0323c81ba688c8ce2aa0cac307035d0b882b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2001696
Commit-Queue: Zhizhou Yang <zhizhouy@google.com>
Tested-by: Zhizhou Yang <zhizhouy@google.com>
Auto-Submit: Zhizhou Yang <zhizhouy@google.com>
Reviewed-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'crosperf')
-rw-r--r-- | crosperf/column_chart.py | 8 | ||||
-rw-r--r-- | crosperf/compare_machines.py | 2 | ||||
-rw-r--r-- | crosperf/config.py | 2 | ||||
-rwxr-xr-x | crosperf/config_unittest.py | 15 | ||||
-rwxr-xr-x | crosperf/download_images_buildid_test.py | 21 | ||||
-rwxr-xr-x | crosperf/download_images_unittest.py | 3 | ||||
-rw-r--r-- | crosperf/experiment_status.py | 26 | ||||
-rw-r--r-- | crosperf/field.py | 6 | ||||
-rwxr-xr-x | crosperf/flag_test_unittest.py | 14 | ||||
-rwxr-xr-x | crosperf/generate_report.py | 11 | ||||
-rwxr-xr-x | crosperf/generate_report_unittest.py | 44 | ||||
-rw-r--r-- | crosperf/help.py | 6 | ||||
-rw-r--r-- | crosperf/image_checksummer.py | 6 | ||||
-rw-r--r-- | crosperf/machine_image_manager.py | 15 | ||||
-rwxr-xr-x | crosperf/machine_image_manager_unittest.py | 66 | ||||
-rw-r--r-- | crosperf/machine_manager.py | 24 | ||||
-rw-r--r-- | crosperf/results_report.py | 4 | ||||
-rw-r--r-- | crosperf/results_report_templates.py | 2 | ||||
-rwxr-xr-x | crosperf/results_report_unittest.py | 22 | ||||
-rw-r--r-- | crosperf/settings.py | 2 | ||||
-rwxr-xr-x | crosperf/settings_unittest.py | 4 | ||||
-rw-r--r-- | crosperf/test_flag.py | 6 | ||||
-rw-r--r-- | crosperf/translate_xbuddy.py | 7 |
23 files changed, 196 insertions, 120 deletions
diff --git a/crosperf/column_chart.py b/crosperf/column_chart.py index 7e6821d0..400979ee 100644 --- a/crosperf/column_chart.py +++ b/crosperf/column_chart.py @@ -1,4 +1,8 @@ -# Copyright 2011 Google Inc. All Rights Reserved. +# -*- coding: utf-8 -*- +# Copyright 2011 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. + """Module to draw column chart.""" @@ -7,7 +11,7 @@ class ColumnChart(object): def __init__(self, title, width, height): self.title = title - self.chart_div = filter(str.isalnum, title) + self.chart_div = ''.join(t for t in title if t.isalnum()) self.width = width self.height = height self.columns = [] diff --git a/crosperf/compare_machines.py b/crosperf/compare_machines.py index 34513a87..c73f8756 100644 --- a/crosperf/compare_machines.py +++ b/crosperf/compare_machines.py @@ -1,6 +1,8 @@ +# -*- coding: utf-8 -*- # Copyright 2014 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. + """Module to compare two machines.""" from __future__ import print_function diff --git a/crosperf/config.py b/crosperf/config.py index 76175660..61ad9c1a 100644 --- a/crosperf/config.py +++ b/crosperf/config.py @@ -1,6 +1,8 @@ +# -*- coding: utf-8 -*- # Copyright 2011 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. + """A configure file.""" config = {} diff --git a/crosperf/config_unittest.py b/crosperf/config_unittest.py index 637dae9e..9e71539d 100755 --- a/crosperf/config_unittest.py +++ b/crosperf/config_unittest.py @@ -1,14 +1,17 @@ #!/usr/bin/env python2 -# -# Copyright 2014 Google Inc. All Rights Reserved. +# -*- coding: utf-8 -*- +# Copyright 2014 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 config.py""" from __future__ import print_function -import config - import unittest +import config + class ConfigTestCase(unittest.TestCase): """Class for the config unit tests.""" @@ -16,7 +19,7 @@ class ConfigTestCase(unittest.TestCase): def test_config(self): # Verify that config exists, that it's a dictionary, and that it's # empty. - self.assertTrue(type(config.config) is dict) + self.assertTrue(isinstance(config.config, dict)) self.assertEqual(len(config.config), 0) # Verify that attempting to get a non-existant key out of the @@ -42,7 +45,7 @@ class ConfigTestCase(unittest.TestCase): # Verify that config exists, that it's a dictionary, and that it's # empty. - self.assertTrue(type(config.config) is dict) + self.assertTrue(isinstance(config.config, dict)) self.assertEqual(len(config.config), 0) diff --git a/crosperf/download_images_buildid_test.py b/crosperf/download_images_buildid_test.py index 3e7f00c1..a376691c 100755 --- a/crosperf/download_images_buildid_test.py +++ b/crosperf/download_images_buildid_test.py @@ -1,6 +1,9 @@ #!/usr/bin/env python2 -# -# Copyright 2014 Google Inc. All Rights Reserved +# -*- coding: utf-8 -*- +# Copyright 2014 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. + """Test translation of xbuddy names.""" from __future__ import print_function @@ -10,12 +13,12 @@ import sys import download_images -#On May 1, 2014: -#latest : lumpy-release/R34-5500.132.0 -#latest-beta : lumpy-release/R35-5712.43.0 -#latest-official: lumpy-release/R36-5814.0.0 -#latest-dev : lumpy-release/R36-5814.0.0 -#latest-canary : lumpy-release/R36-5814.0.0 +# On May 1, 2014: +# latest : lumpy-release/R34-5500.132.0 +# latest-beta : lumpy-release/R35-5712.43.0 +# latest-official: lumpy-release/R36-5814.0.0 +# latest-dev : lumpy-release/R36-5814.0.0 +# latest-canary : lumpy-release/R36-5814.0.0 class ImageDownloaderBuildIDTest(object): @@ -55,7 +58,7 @@ class ImageDownloaderBuildIDTest(object): sys.exit(1) def assertIsNotNone(self, arg, arg_name): - if arg == None: + if arg is None: self.tests_failed = self.tests_failed + 1 self.assert_failure('%s is not None' % arg_name) diff --git a/crosperf/download_images_unittest.py b/crosperf/download_images_unittest.py index dd83c3fa..94504d3f 100755 --- a/crosperf/download_images_unittest.py +++ b/crosperf/download_images_unittest.py @@ -9,9 +9,10 @@ from __future__ import print_function import os -import mock import unittest +import mock + import download_images from cros_utils import command_executer from cros_utils import logger diff --git a/crosperf/experiment_status.py b/crosperf/experiment_status.py index c6610433..2ac47c74 100644 --- a/crosperf/experiment_status.py +++ b/crosperf/experiment_status.py @@ -1,8 +1,11 @@ +# -*- coding: utf-8 -*- # Copyright 2011 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. + """The class to show the banner.""" +from __future__ import division from __future__ import print_function import collections @@ -25,7 +28,7 @@ class ExperimentStatus(object): bar_length = 50 done_char = '>' undone_char = ' ' - num_complete_chars = bar_length * num_complete / num_total + num_complete_chars = bar_length * num_complete // num_total num_undone_chars = bar_length - num_complete_chars ret += ' [%s%s]' % (num_complete_chars * done_char, num_undone_chars * undone_char) @@ -42,8 +45,8 @@ class ExperimentStatus(object): if self.completed != self.experiment.num_complete: self.completed = self.experiment.num_complete self.new_job_start_time = current_time - time_completed_jobs = (elapsed_time - - (current_time - self.new_job_start_time)) + time_completed_jobs = ( + elapsed_time - (current_time - self.new_job_start_time)) # eta is calculated as: # ETA = (num_jobs_not_yet_started * estimated_time_per_job) # + time_left_for_current_job @@ -64,10 +67,11 @@ class ExperimentStatus(object): # first long job, after a series of short jobs). For now, if that # happens, we set the ETA to "Unknown." # - eta_seconds = (float(self.num_total - self.experiment.num_complete - 1) * - time_completed_jobs / self.experiment.num_run_complete + - (time_completed_jobs / self.experiment.num_run_complete - - (current_time - self.new_job_start_time))) + eta_seconds = ( + float(self.num_total - self.experiment.num_complete - 1) * + time_completed_jobs / self.experiment.num_run_complete + + (time_completed_jobs / self.experiment.num_run_complete - + (current_time - self.new_job_start_time))) eta_seconds = int(eta_seconds) if eta_seconds > 0: @@ -91,7 +95,7 @@ class ExperimentStatus(object): status_bins[benchmark_run.timeline.GetLastEvent()].append(benchmark_run) status_strings = [] - for key, val in status_bins.iteritems(): + for key, val in status_bins.items(): if key == 'RUNNING': get_description = self._GetNamesAndIterations else: @@ -129,16 +133,16 @@ class ExperimentStatus(object): grouped_benchmarks[benchmark_run.label.name].append(benchmark_run) output_segs = [] - for label_name, label_runs in grouped_benchmarks.iteritems(): + for label_name, label_runs in grouped_benchmarks.items(): strings = [] benchmark_iterations = collections.defaultdict(list) for benchmark_run in label_runs: assert benchmark_run.label.name == label_name benchmark_name = benchmark_run.benchmark.name benchmark_iterations[benchmark_name].append(benchmark_run.iteration) - for key, val in benchmark_iterations.iteritems(): + for key, val in benchmark_iterations.items(): val.sort() - iterations = ','.join(map(str, val)) + iterations = ','.join(str(v) for v in val) strings.append('{} [{}]'.format(key, iterations)) output_segs.append(' ' + label_name + ': ' + ', '.join(strings) + '\n') diff --git a/crosperf/field.py b/crosperf/field.py index 6821d4d3..f6300f9f 100644 --- a/crosperf/field.py +++ b/crosperf/field.py @@ -1,4 +1,8 @@ -# Copyright 2011 Google Inc. All Rights Reserved. +# -*- coding: utf-8 -*- +# Copyright 2011 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. + """Module to represent a Field in an experiment file.""" diff --git a/crosperf/flag_test_unittest.py b/crosperf/flag_test_unittest.py index 0e743274..cb0e59e6 100755 --- a/crosperf/flag_test_unittest.py +++ b/crosperf/flag_test_unittest.py @@ -1,13 +1,17 @@ #!/usr/bin/env python2 -# -# Copyright 2014 Google Inc. All Rights Reserved. +# -*- coding: utf-8 -*- +# Copyright 2014 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. + """The unittest of flags.""" from __future__ import print_function -import test_flag import unittest +import test_flag + class FlagTestCase(unittest.TestCase): """The unittest class.""" @@ -15,7 +19,7 @@ class FlagTestCase(unittest.TestCase): def test_test_flag(self): # Verify that test_flag.is_test exists, that it is a list, # and that it contains 1 element. - self.assertTrue(type(test_flag.is_test) is list) + self.assertTrue(isinstance(test_flag.is_test, list)) self.assertEqual(len(test_flag.is_test), 1) # Verify that the getting the flag works and that the flag @@ -33,7 +37,7 @@ class FlagTestCase(unittest.TestCase): # Verify that test_flag.is_test still exists, that it still is a # list, and that it still contains 1 element. - self.assertTrue(type(test_flag.is_test) is list) + self.assertTrue(isinstance(test_flag.is_test, list)) self.assertEqual(len(test_flag.is_test), 1) diff --git a/crosperf/generate_report.py b/crosperf/generate_report.py index fd7a2cf7..cea95a2e 100755 --- a/crosperf/generate_report.py +++ b/crosperf/generate_report.py @@ -1,8 +1,9 @@ #!/usr/bin/env python2 -# +# -*- coding: utf-8 -*- # Copyright 2016 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. + """Given a specially-formatted JSON object, generates results report(s). The JSON object should look like: @@ -67,8 +68,7 @@ def CountBenchmarks(benchmark_runs): def _MaxLen(results): return 0 if not results else max(len(r) for r in results) - return [(name, _MaxLen(results)) - for name, results in benchmark_runs.iteritems()] + return [(name, _MaxLen(results)) for name, results in benchmark_runs.items()] def CutResultsInPlace(results, max_keys=50, complain_on_update=True): @@ -130,9 +130,14 @@ def CutResultsInPlace(results, max_keys=50, complain_on_update=True): def _ConvertToASCII(obj): """Convert an object loaded from JSON to ASCII; JSON gives us unicode.""" + # In python 3, we can directly return the unicode loaded from json. + if sys.version_info.major == 3: + return obj + # TODO(zhizhouy): Drop the following code once migrated to python 3. # Using something like `object_hook` is insufficient, since it only fires on # actual JSON objects. `encoding` fails, too, since the default decoder always # uses unicode() to decode strings. + # pylint: disable=unicode-builtin if isinstance(obj, unicode): return str(obj) if isinstance(obj, dict): diff --git a/crosperf/generate_report_unittest.py b/crosperf/generate_report_unittest.py index bbb0c0ae..465db29b 100755 --- a/crosperf/generate_report_unittest.py +++ b/crosperf/generate_report_unittest.py @@ -1,23 +1,28 @@ #!/usr/bin/env python2 -# +# -*- coding: utf-8 -*- # Copyright 2016 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. + """Test for generate_report.py.""" from __future__ import division from __future__ import print_function -from StringIO import StringIO - import copy import json -import mock -import test_flag import unittest +import mock import generate_report import results_report +import test_flag + +# pylint: disable=deprecated-module +try: + from StringIO import StringIO # for Python 2 +except ImportError: + from io import StringIO # for Python 3 class _ContextualStringIO(StringIO): @@ -44,7 +49,7 @@ class GenerateReportTests(unittest.TestCase): } results = generate_report.CountBenchmarks(runs) expected_results = [('foo', 4), ('bar', 0), ('baz', 3)] - self.assertItemsEqual(expected_results, results) + self.assertEqual(sorted(expected_results), sorted(results)) def testCutResultsInPlace(self): bench_data = { @@ -77,10 +82,11 @@ class GenerateReportTests(unittest.TestCase): bench_data, max_keys=max_keys, complain_on_update=False) # Cuts should be in-place. self.assertIs(results, bench_data) - self.assertItemsEqual(original_bench_data.keys(), bench_data.keys()) - for bench_name, original_runs in original_bench_data.iteritems(): + self.assertEqual( + sorted(original_bench_data.keys()), sorted(bench_data.keys())) + for bench_name, original_runs in original_bench_data.items(): bench_runs = bench_data[bench_name] - self.assertEquals(len(original_runs), len(bench_runs)) + self.assertEqual(len(original_runs), len(bench_runs)) # Order of these sub-lists shouldn't have changed. for original_list, new_list in zip(original_runs, bench_runs): self.assertEqual(len(original_list), len(new_list)) @@ -106,9 +112,9 @@ class GenerateReportTests(unittest.TestCase): # Just reach into results assuming we know it otherwise outputs things # sanely. If it doesn't, testCutResultsInPlace should give an indication as # to what, exactly, is broken. - self.assertEqual(results['foo'][0][0].items(), [('retval', 0)]) - self.assertEqual(results['bar'][0][0].items(), [('retval', 1)]) - self.assertEqual(results['baz'][0][0].items(), []) + self.assertEqual(list(results['foo'][0][0].items()), [('retval', 0)]) + self.assertEqual(list(results['bar'][0][0].items()), [('retval', 1)]) + self.assertEqual(list(results['baz'][0][0].items()), []) def _RunMainWithInput(self, args, input_obj): assert '-i' not in args @@ -129,11 +135,13 @@ class GenerateReportTests(unittest.TestCase): self.assertEqual(0, return_code) self.assertEqual(mock_run_actions.call_count, 1) ctors = [ctor for ctor, _ in mock_run_actions.call_args[0][0]] - self.assertItemsEqual(ctors, [ - results_report.JSONResultsReport, - results_report.TextResultsReport, - results_report.HTMLResultsReport, - ]) + self.assertEqual( + sorted(ctors), + sorted([ + results_report.JSONResultsReport, + results_report.TextResultsReport, + results_report.HTMLResultsReport, + ])) @mock.patch('generate_report.RunActions') def testMainSelectsHTMLIfNoReportsGiven(self, mock_run_actions): @@ -142,7 +150,7 @@ class GenerateReportTests(unittest.TestCase): self.assertEqual(0, return_code) self.assertEqual(mock_run_actions.call_count, 1) ctors = [ctor for ctor, _ in mock_run_actions.call_args[0][0]] - self.assertItemsEqual(ctors, [results_report.HTMLResultsReport]) + self.assertEqual(ctors, [results_report.HTMLResultsReport]) # We only mock print_exc so we don't have exception info printed to stdout. @mock.patch('generate_report.WriteFile', side_effect=ValueError('Oh noo')) diff --git a/crosperf/help.py b/crosperf/help.py index 61ed8ea2..4409b770 100644 --- a/crosperf/help.py +++ b/crosperf/help.py @@ -1,4 +1,8 @@ -# Copyright 2011 Google Inc. All Rights Reserved. +# -*- coding: utf-8 -*- +# Copyright 2011 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. + """Module to print help message.""" from __future__ import print_function diff --git a/crosperf/image_checksummer.py b/crosperf/image_checksummer.py index f5862e4d..8ac5be25 100644 --- a/crosperf/image_checksummer.py +++ b/crosperf/image_checksummer.py @@ -1,4 +1,8 @@ -# Copyright 2011 Google Inc. All Rights Reserved. +# -*- coding: utf-8 -*- +# Copyright 2011 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. + """Compute image checksum.""" from __future__ import print_function diff --git a/crosperf/machine_image_manager.py b/crosperf/machine_image_manager.py index 2ad750d3..ffdd6436 100644 --- a/crosperf/machine_image_manager.py +++ b/crosperf/machine_image_manager.py @@ -1,8 +1,14 @@ +# -*- coding: utf-8 -*- # Copyright 2015 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. + """MachineImageManager allocates images to duts.""" +from __future__ import print_function + +import functools + class MachineImageManager(object): """Management of allocating images to duts. @@ -143,8 +149,9 @@ class MachineImageManager(object): self.dut_name_ordinal_[dut.name] = idx # Generate initial matrix containg 'X' or ' '. - self.matrix_ = [['X' if (l.remote and len(l.remote)) else ' ' \ - for _ in range(self.n_duts_)] for l in self.labels_] + self.matrix_ = [['X' if l.remote else ' ' + for _ in range(self.n_duts_)] + for l in self.labels_] for ol, l in enumerate(self.labels_): if l.remote: for r in l.remote: @@ -291,8 +298,8 @@ class MachineImageManager(object): if v == ' ': # Before we put a 'Y', we check how many Y column 'j' has. # Note y[0] is row idx, y[1] is the cell value. - ny = reduce(lambda x, y: x + 1 if (y[1] == 'Y') else x, - self.matrix_vertical_generator(j), 0) + ny = functools.reduce(lambda x, y: x + 1 if (y[1] == 'Y') else x, + self.matrix_vertical_generator(j), 0) if ny < N: self.matrix_[level][j] = 'Y' if self._compute_initial_allocation_internal(level + 1, N): diff --git a/crosperf/machine_image_manager_unittest.py b/crosperf/machine_image_manager_unittest.py index 02afaa06..062c185f 100755 --- a/crosperf/machine_image_manager_unittest.py +++ b/crosperf/machine_image_manager_unittest.py @@ -1,6 +1,9 @@ #!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Copyright 2015 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. -# Copyright 2015 Google Inc. All Rights Reserved. """Unit tests for the MachineImageManager class.""" from __future__ import print_function @@ -98,62 +101,67 @@ class MachineImageManagerTester(unittest.TestCase): def test_case1(self): labels = [ - MockLabel('l1', ['m1', 'm2']), MockLabel('l2', ['m2', 'm3']), MockLabel( - 'l3', ['m1']) + MockLabel('l1', ['m1', 'm2']), + MockLabel('l2', ['m2', 'm3']), + MockLabel('l3', ['m1']) ] duts = [MockDut('m1'), MockDut('m2'), MockDut('m3')] mim = MachineImageManager(labels, duts) - self.assertTrue(mim.matrix_ == [[' ', ' ', 'X'], ['X', ' ', ' '], - [' ', 'X', 'X']]) + self.assertTrue( + mim.matrix_ == [[' ', ' ', 'X'], ['X', ' ', ' '], [' ', 'X', 'X']]) mim.compute_initial_allocation() - self.assertTrue(mim.matrix_ == [[' ', 'Y', 'X'], ['X', ' ', 'Y'], - ['Y', 'X', 'X']]) + self.assertTrue( + mim.matrix_ == [[' ', 'Y', 'X'], ['X', ' ', 'Y'], ['Y', 'X', 'X']]) def test_case2(self): labels = [ - MockLabel('l1', ['m1', 'm2']), MockLabel('l2', ['m2', 'm3']), MockLabel( - 'l3', ['m1']) + MockLabel('l1', ['m1', 'm2']), + MockLabel('l2', ['m2', 'm3']), + MockLabel('l3', ['m1']) ] duts = [MockDut('m1'), MockDut('m2'), MockDut('m3')] mim = MachineImageManager(labels, duts) - self.assertTrue(mim.matrix_ == [[' ', ' ', 'X'], ['X', ' ', ' '], - [' ', 'X', 'X']]) + self.assertTrue( + mim.matrix_ == [[' ', ' ', 'X'], ['X', ' ', ' '], [' ', 'X', 'X']]) mim.compute_initial_allocation() - self.assertTrue(mim.matrix_ == [[' ', 'Y', 'X'], ['X', ' ', 'Y'], - ['Y', 'X', 'X']]) + self.assertTrue( + mim.matrix_ == [[' ', 'Y', 'X'], ['X', ' ', 'Y'], ['Y', 'X', 'X']]) def test_case3(self): labels = [ - MockLabel('l1', ['m1', 'm2']), MockLabel('l2', ['m2', 'm3']), MockLabel( - 'l3', ['m1']) + MockLabel('l1', ['m1', 'm2']), + MockLabel('l2', ['m2', 'm3']), + MockLabel('l3', ['m1']) ] duts = [MockDut('m1', labels[0]), MockDut('m2'), MockDut('m3')] mim = MachineImageManager(labels, duts) mim.compute_initial_allocation() - self.assertTrue(mim.matrix_ == [[' ', 'Y', 'X'], ['X', ' ', 'Y'], - ['Y', 'X', 'X']]) + self.assertTrue( + mim.matrix_ == [[' ', 'Y', 'X'], ['X', ' ', 'Y'], ['Y', 'X', 'X']]) def test_case4(self): labels = [ - MockLabel('l1', ['m1', 'm2']), MockLabel('l2', ['m2', 'm3']), MockLabel( - 'l3', ['m1']) + MockLabel('l1', ['m1', 'm2']), + MockLabel('l2', ['m2', 'm3']), + MockLabel('l3', ['m1']) ] duts = [MockDut('m1'), MockDut('m2', labels[0]), MockDut('m3')] mim = MachineImageManager(labels, duts) mim.compute_initial_allocation() - self.assertTrue(mim.matrix_ == [[' ', 'Y', 'X'], ['X', ' ', 'Y'], - ['Y', 'X', 'X']]) + self.assertTrue( + mim.matrix_ == [[' ', 'Y', 'X'], ['X', ' ', 'Y'], ['Y', 'X', 'X']]) def test_case5(self): labels = [ - MockLabel('l1', ['m3']), MockLabel('l2', ['m3']), MockLabel( - 'l3', ['m1']) + MockLabel('l1', ['m3']), + MockLabel('l2', ['m3']), + MockLabel('l3', ['m1']) ] duts = self.gen_duts_by_name('m1', 'm2', 'm3') mim = MachineImageManager(labels, duts) self.assertTrue(mim.compute_initial_allocation()) - self.assertTrue(mim.matrix_ == [['X', 'X', 'Y'], ['X', 'X', 'Y'], - ['Y', 'X', 'X']]) + self.assertTrue( + mim.matrix_ == [['X', 'X', 'Y'], ['X', 'X', 'Y'], ['Y', 'X', 'X']]) def test_2x2_with_allocation(self): labels = [MockLabel('l0'), MockLabel('l1')] @@ -249,13 +257,13 @@ class MachineImageManagerTester(unittest.TestCase): self.assertTrue(mim.allocate(mim.duts_[3]) is None) self.assertTrue(mim.allocate(mim.duts_[2]) is None) self.assertTrue(mim.allocate(mim.duts_[1]) == mim.labels_[1]) - self.assertTrue(mim.allocate(mim.duts_[1]) == None) - self.assertTrue(mim.allocate(mim.duts_[0]) == None) + self.assertTrue(mim.allocate(mim.duts_[1]) is None) + self.assertTrue(mim.allocate(mim.duts_[0]) is None) self.assertTrue(mim.label_duts_[0] == [2, 3]) self.assertTrue(mim.label_duts_[1] == [0, 3, 1]) self.assertTrue(mim.label_duts_[2] == [3, 1]) - self.assertTrue(mim.allocate_log_ == [(0, 2), (2, 3), (1, 0), (2, 1), - (1, 3), (0, 3), (1, 1)]) + self.assertListEqual(mim.allocate_log_, [(0, 2), (2, 3), (1, 0), (2, 1), + (1, 3), (0, 3), (1, 1)]) def test_cornercase_1(self): """This corner case is brought up by Caroline. diff --git a/crosperf/machine_manager.py b/crosperf/machine_manager.py index 2cdaca3f..6ed7e513 100644 --- a/crosperf/machine_manager.py +++ b/crosperf/machine_manager.py @@ -1,15 +1,15 @@ +# -*- coding: utf-8 -*- # Copyright (c) 2013 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. """Machine Manager module.""" +from __future__ import division from __future__ import print_function import collections -import file_lock_machine import hashlib -import image_chromeos import math import os.path import re @@ -17,6 +17,8 @@ import sys import threading import time +import file_lock_machine +import image_chromeos import test_flag from cros_utils import command_executer from cros_utils import logger @@ -124,8 +126,8 @@ class CrosMachine(object): self.phys_kbytes = phys_kbytes def _GetMemoryInfo(self): - #TODO yunlian: when the machine in rebooting, it will not return - #meminfo, the assert does not catch it either + # TODO yunlian: when the machine in rebooting, it will not return + # meminfo, the assert does not catch it either command = 'cat /proc/meminfo' ret, self.meminfo, _ = self.ce.CrosRunCommandWOutput( command, machine=self.name, chromeos_root=self.chromeos_root) @@ -159,7 +161,7 @@ class CrosMachine(object): command, machine=self.name, chromeos_root=self.chromeos_root) b = if_out.splitlines() a = [l for l in b if 'Product' in l] - if len(a): + if a: self.machine_id = a[0] return command = 'ifconfig' @@ -167,11 +169,11 @@ class CrosMachine(object): command, machine=self.name, chromeos_root=self.chromeos_root) b = if_out.splitlines() a = [l for l in b if 'HWaddr' in l] - if len(a): + if a: self.machine_id = '_'.join(a) return a = [l for l in b if 'ether' in l] - if len(a): + if a: self.machine_id = '_'.join(a) return assert 0, 'Could not get machine_id from machine: %s' % self.name @@ -515,7 +517,7 @@ class MachineManager(object): dic[machine.cpuinfo].append(label.name) break output_segs = [] - for key, v in dic.iteritems(): + for key, v in dic.items(): output = ' '.join(v) output += '\n-------------------\n' output += key @@ -630,7 +632,7 @@ power management: self.test_run = None self.chromeos_root = chromeos_root self.checksum_string = re.sub(r'\d', '', name) - #In test, we assume "lumpy1", "lumpy2" are the same machine. + # In test, we assume "lumpy1", "lumpy2" are the same machine. self.machine_checksum = self._GetMD5Checksum(self.checksum_string) self.log_level = log_level self.label = None @@ -684,8 +686,8 @@ class MockMachineManager(MachineManager): return machine return None - def ImageMachine(self, machine_name, label): - if machine_name or label: + def ImageMachine(self, machine, label): + if machine or label: return 0 return 1 diff --git a/crosperf/results_report.py b/crosperf/results_report.py index 22719027..81591db7 100644 --- a/crosperf/results_report.py +++ b/crosperf/results_report.py @@ -375,8 +375,8 @@ class TextResultsReport(ResultsReport): def GetTotalWaitCooldownTime(self): """Get cooldown wait time in seconds from experiment benchmark runs. - Returns: - Dictionary {'dut': int(wait_time_in_seconds)} + Returns: + Dictionary {'dut': int(wait_time_in_seconds)} """ waittime_dict = {} for dut in self.experiment.machine_manager.GetMachines(): diff --git a/crosperf/results_report_templates.py b/crosperf/results_report_templates.py index 15ce5827..3c5258c9 100644 --- a/crosperf/results_report_templates.py +++ b/crosperf/results_report_templates.py @@ -1,6 +1,8 @@ +# -*- coding: utf-8 -*- # Copyright 2016 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. + """Text templates used by various parts of results_report.""" from __future__ import print_function diff --git a/crosperf/results_report_unittest.py b/crosperf/results_report_unittest.py index 48fa0c38..dfcce725 100755 --- a/crosperf/results_report_unittest.py +++ b/crosperf/results_report_unittest.py @@ -130,19 +130,19 @@ def _InjectSuccesses(experiment, how_many, keyvals, for_benchmark=0): machine_manager.AddMachine('testing_machine') machine = next( m for m in machine_manager.GetMachines() if m.name == 'testing_machine') - for label in experiment.labels: - def MakeSuccessfulRun(n): - run = MockBenchmarkRun('mock_success%d' % (n,), bench, label, - 1 + n + num_runs, cache_conditions, - machine_manager, log, log_level, share_cache, {}) - mock_result = MockResult(log, label, log_level, machine) - mock_result.keyvals = keyvals - run.result = mock_result - return run + def MakeSuccessfulRun(n, label): + run = MockBenchmarkRun('mock_success%d' % (n,), bench, label, + 1 + n + num_runs, cache_conditions, machine_manager, + log, log_level, share_cache, {}) + mock_result = MockResult(log, label, log_level, machine) + mock_result.keyvals = keyvals + run.result = mock_result + return run + for label in experiment.labels: experiment.benchmark_runs.extend( - MakeSuccessfulRun(n) for n in range(how_many)) + MakeSuccessfulRun(n, label) for n in range(how_many)) return experiment @@ -429,7 +429,7 @@ class PerfReportParserTest(unittest.TestCase): def testParserParsesRealWorldPerfReport(self): report = ParseStandardPerfReport(self._ReadRealPerfReport()) - self.assertItemsEqual(['cycles', 'instructions'], report.keys()) + self.assertItemsEqual(['cycles', 'instructions'], sorted(report.keys())) # Arbitrarily selected known percentages from the perf report. known_cycles_percentages = { diff --git a/crosperf/settings.py b/crosperf/settings.py index 708697b1..41530d97 100644 --- a/crosperf/settings.py +++ b/crosperf/settings.py @@ -1,4 +1,4 @@ -#-*- coding: utf-8 -*- +# -*- coding: utf-8 -*- # Copyright 2019 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. diff --git a/crosperf/settings_unittest.py b/crosperf/settings_unittest.py index 8140e9b9..e6126923 100755 --- a/crosperf/settings_unittest.py +++ b/crosperf/settings_unittest.py @@ -37,7 +37,7 @@ class TestSettings(unittest.TestCase): settings_parent = {'fake_parent_entry': 0} self.settings.SetParentSettings(settings_parent) self.assertIsNotNone(self.settings.parent) - self.assertEqual(type(self.settings.parent), dict) + self.assertTrue(isinstance(self.settings.parent, dict)) self.assertEqual(self.settings.parent, settings_parent) def test_add_field(self): @@ -88,7 +88,7 @@ class TestSettings(unittest.TestCase): description="A comma-separated list of ip's of " 'chromeos devices to run ' 'experiments on.')) - self.assertEqual(type(self.settings.fields), dict) + self.assertTrue(isinstance(self.settings.fields, dict)) self.assertEqual(len(self.settings.fields), 2) res = self.settings.fields['remote'] self.assertEqual(res.Get(), []) diff --git a/crosperf/test_flag.py b/crosperf/test_flag.py index 70918693..6fa3b589 100644 --- a/crosperf/test_flag.py +++ b/crosperf/test_flag.py @@ -1,4 +1,8 @@ -# Copyright 2011 Google Inc. All Rights Reserved. +# -*- coding: utf-8 -*- +# Copyright 2011 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. + """A global variable for testing.""" is_test = [False] diff --git a/crosperf/translate_xbuddy.py b/crosperf/translate_xbuddy.py index 20fcc704..ca7058ea 100644 --- a/crosperf/translate_xbuddy.py +++ b/crosperf/translate_xbuddy.py @@ -1,3 +1,8 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 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. + """Module to translate the xbuddy config.""" from __future__ import print_function @@ -14,7 +19,7 @@ else: ' and try again.') sys.exit(0) -#pylint: disable=import-error +# pylint: disable=import-error,wrong-import-position import xbuddy |