From e615c14e8ee6522261be8cb07ef6cdbbfa8d8575 Mon Sep 17 00:00:00 2001 From: Mattias Josefsson Date: Thu, 2 Nov 2023 18:21:37 +0100 Subject: [PATCH 1/3] Update signal.py unnecessary print statement removed --- src/asammdf/signal.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/asammdf/signal.py b/src/asammdf/signal.py index 32fb1167b..da8da53c2 100644 --- a/src/asammdf/signal.py +++ b/src/asammdf/signal.py @@ -224,7 +224,6 @@ def plot(self, validate: bool = True, index_only: bool = False) -> None: return except: - print(format_exc()) try: import matplotlib.pyplot as plt from matplotlib.widgets import Slider From 0d087cbc49aba145dc2b3b2e32ea4541ac0170b1 Mon Sep 17 00:00:00 2001 From: Mattias Josefsson Date: Fri, 15 Dec 2023 10:20:19 +0100 Subject: [PATCH 2/3] black and ruff style checks --- .../dialogs/test_FunctionsManagerDialog.py | 4 +- test/test_mdf.py | 68 +++++++------ test/utils.py | 97 +++++++++---------- 3 files changed, 83 insertions(+), 86 deletions(-) diff --git a/test/asammdf/gui/dialogs/test_FunctionsManagerDialog.py b/test/asammdf/gui/dialogs/test_FunctionsManagerDialog.py index e7b80f9ae..3e6bd7d1c 100644 --- a/test/asammdf/gui/dialogs/test_FunctionsManagerDialog.py +++ b/test/asammdf/gui/dialogs/test_FunctionsManagerDialog.py @@ -220,7 +220,7 @@ def test_PushButton_SaveDefinitions(self): # Evaluate self.assertTrue(saved_file.exists()) - with open(saved_file, "r") as fpr: + with open(saved_file) as fpr: content = json.load(fpr) self.assertDictEqual(content, {"Function1": "def Function1(t=0):\n return 0"}) @@ -328,7 +328,7 @@ def test_PushButton_StoreFunctionChanges_0(self): # Evaluate self.assertTrue(saved_file.exists()) - with open(saved_file, "r") as fpr: + with open(saved_file) as fpr: content = json.load(fpr) self.assertIn(maximum.__name__, content) self.assertIn(content["maximum"], source) diff --git a/test/test_mdf.py b/test/test_mdf.py index 0080b639e..7844552d2 100644 --- a/test/test_mdf.py +++ b/test/test_mdf.py @@ -105,9 +105,7 @@ def test_read(self): equal = False elif i == 4: for j in range(1, 20): - target = np.array( - ["Channel {} sample {}".format(j, k).encode("ascii") for k in range(cycles)] - ) + target = np.array([f"Channel {j} sample {k}".encode("ascii") for k in range(cycles)]) vals = mdf.get(group=i, index=j + 1, samples_only=True)[0] cond = np.array_equal(vals, target) if not cond: @@ -158,13 +156,13 @@ def test_read_arrays(self): for j in range(1, 20): types = [ - ("Channel_{}".format(j), "(2, 3)= "4.00" else v3c.CONVERSION_TYPE_FORMULA, - "formula": "{} * sin(X)".format(i), + "formula": f"{i} * sin(X)", } sig = Signal( np.arange(cycles, dtype=np.int32) / 100.0, t, - name="Channel_{}".format(i), - unit="unit_{}".format(i), + name=f"Channel_{i}", + unit=f"unit_{i}", conversion=cls(**conversion), - comment="Sinus channel {} with algebraic conversion".format(i), + comment=f"Sinus channel {i} with algebraic conversion", raw=True, ) sigs.append(sig) @@ -107,10 +106,10 @@ def generate_test_file(tmpdir, version="4.10"): sig = Signal( np.ones(cycles, dtype=np.int64), t, - name="Channel_{}".format(i), - unit="unit_{}".format(i), + name=f"Channel_{i}", + unit=f"unit_{i}", conversion=cls(**conversion), - comment="Channel {} with rational conversion".format(i), + comment=f"Channel {i} with rational conversion", raw=True, ) sigs.append(sig) @@ -120,13 +119,13 @@ def generate_test_file(tmpdir, version="4.10"): sigs = [] encoding = "latin-1" if version < "4.00" else "utf-8" for i in range(channels_count): - sig = ["Channel {} sample {}".format(i, j).encode(encoding) for j in range(cycles)] + sig = [f"Channel {i} sample {j}".encode(encoding) for j in range(cycles)] sig = Signal( np.array(sig), t, - name="Channel_{}".format(i), - unit="unit_{}".format(i), - comment="String channel {}".format(i), + name=f"Channel_{i}", + unit=f"unit_{i}", + comment=f"String channel {i}", raw=True, encoding=encoding, ) @@ -140,9 +139,9 @@ def generate_test_file(tmpdir, version="4.10"): sig = Signal( ones * i, t, - name="Channel_{}".format(i), - unit="unit_{}".format(i), - comment="Byte array channel {}".format(i), + name=f"Channel_{i}", + unit=f"unit_{i}", + comment=f"Byte array channel {i}", raw=True, ) sigs.append(sig) @@ -153,24 +152,24 @@ def generate_test_file(tmpdir, version="4.10"): ones = np.ones(cycles, dtype=np.uint64) conversion = { "raw": np.arange(255, dtype=np.float64), - "phys": np.array(["Value {}".format(i).encode("ascii") for i in range(255)]), + "phys": np.array([f"Value {i}".encode("ascii") for i in range(255)]), "conversion_type": v4c.CONVERSION_TYPE_TABX if version >= "4.00" else v3c.CONVERSION_TYPE_TABX, "links_nr": 260, "ref_param_nr": 255, } for i in range(255): - conversion["val_{}".format(i)] = conversion["param_val_{}".format(i)] = conversion["raw"][i] - conversion["text_{}".format(i)] = conversion["phys"][i] - conversion["text_{}".format(255)] = "Default" + conversion[f"val_{i}"] = conversion[f"param_val_{i}"] = conversion["raw"][i] + conversion[f"text_{i}"] = conversion["phys"][i] + conversion[f"text_{255}"] = "Default" for i in range(channels_count): sig = Signal( ones * i, t, - name="Channel_{}".format(i), - unit="unit_{}".format(i), - comment="Value to text channel {}".format(i), + name=f"Channel_{i}", + unit=f"unit_{i}", + comment=f"Value to text channel {i}", conversion=cls(**conversion), raw=True, ) @@ -201,18 +200,18 @@ def generate_arrays_test_file(tmpdir): ] types = [ - ("Channel_{}".format(i), "(2, 3) Date: Sat, 16 Dec 2023 09:20:01 +0100 Subject: [PATCH 3/3] style, removed unused import --- src/asammdf/signal.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/asammdf/signal.py b/src/asammdf/signal.py index da8da53c2..bb761c89e 100644 --- a/src/asammdf/signal.py +++ b/src/asammdf/signal.py @@ -5,7 +5,6 @@ from collections.abc import Iterator import logging from textwrap import fill -from traceback import format_exc from typing import Any import numpy as np