From fe86d0f712feeb6ece0ecbbcf5cdd7b18d449d86 Mon Sep 17 00:00:00 2001 From: Richardvdketterij Date: Tue, 16 Jan 2024 13:19:10 +0100 Subject: [PATCH] flake8 --- .../diagnostic_common_diagnostics/cpu_monitor.py | 11 +++++++---- .../test/systemtest/test_cpu_monitor.py | 14 ++++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/diagnostic_common_diagnostics/diagnostic_common_diagnostics/cpu_monitor.py b/diagnostic_common_diagnostics/diagnostic_common_diagnostics/cpu_monitor.py index b22261e9..2318e831 100755 --- a/diagnostic_common_diagnostics/diagnostic_common_diagnostics/cpu_monitor.py +++ b/diagnostic_common_diagnostics/diagnostic_common_diagnostics/cpu_monitor.py @@ -40,9 +40,9 @@ import socket import psutil -from rclpy.node import Node from diagnostic_msgs.msg import DiagnosticStatus from diagnostic_updater import DiagnosticTask, Updater +from rclpy.node import Node class CpuTask(DiagnosticTask): @@ -56,7 +56,8 @@ def _get_average_reading(self): def avg(lst): return float(sum(lst)) / len(lst) if lst else float('nan') - return [avg(cpu_percentages) for cpu_percentages in zip(*self._readings)] + return [avg(cpu_percentages) + for cpu_percentages in zip(*self._readings)] def run(self, stat): self._readings.append(psutil.cpu_percent(percpu=True)) @@ -75,7 +76,8 @@ def run(self, stat): stat.summary(DiagnosticStatus.WARN, "At least one CPU exceeds {:d} percent".format(self._warning_percentage)) else: - stat.summary(DiagnosticStatus.OK, "CPU Average {:.2f} percent".format(cpu_average)) + stat.summary(DiagnosticStatus.OK, + "CPU Average {:.2f} percent".format(cpu_average)) return stat @@ -91,7 +93,8 @@ def main(args=None): node.declare_parameter('warning_percentage', 90) node.declare_parameter('window', 1) - warning_percentage = node.get_parameter('warning_percentage').get_parameter_value().integer_value + warning_percentage = node.get_parameter( + 'warning_percentage').get_parameter_value().integer_value window = node.get_parameter('window').get_parameter_value().integer_value # Create diagnostic updater with default updater rate of 1 hz diff --git a/diagnostic_common_diagnostics/test/systemtest/test_cpu_monitor.py b/diagnostic_common_diagnostics/test/systemtest/test_cpu_monitor.py index bc21c325..445f270b 100644 --- a/diagnostic_common_diagnostics/test/systemtest/test_cpu_monitor.py +++ b/diagnostic_common_diagnostics/test/systemtest/test_cpu_monitor.py @@ -32,16 +32,17 @@ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -import unittest import time -import rclpy +import unittest -from rclpy.node import Node from diagnostic_msgs.msg import DiagnosticStatus -from diagnostic_updater import DiagnosticStatusWrapper from diagnostic_updater import DiagnosticArray, Updater +from diagnostic_updater import DiagnosticStatusWrapper + +import rclpy +from rclpy.node import Node from diagnostic_common_diagnostics.cpu_monitor import CpuTask -import time + class TestCPUMonitor(unittest.TestCase): @classmethod @@ -101,7 +102,8 @@ def test_updater(self): updater.setHardwareID("test_id") updater.add(CpuTask()) - node.create_subscription(DiagnosticArray, '/diagnostics', self.diagnostics_callback, 10) + node.create_subscription( + DiagnosticArray, '/diagnostics', self.diagnostics_callback, 10) start_time = time.time() timeout = 5.0 # Timeout in seconds