From d61459c011c38a55ab4743dc9794f9f485aef0a4 Mon Sep 17 00:00:00 2001 From: Patrick762 Date: Fri, 25 Oct 2024 16:23:21 +0200 Subject: [PATCH 1/6] Create test.yaml --- .github/workflows/test.yaml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..87f7f4a --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,20 @@ +name: Unittests +on: + push: + pull_request: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - name: Setup Python + uses: actions/setup-python@v5.3.0 + with: + python-version: 3 + - name: Run unittests + run: python3 -m unittest discover -s tests -p "*_test.py" From 49c1409656e28e9b37fee030d5ab36dfc7c283b5 Mon Sep 17 00:00:00 2001 From: Patrick762 Date: Fri, 25 Oct 2024 16:29:00 +0200 Subject: [PATCH 2/6] Update test.yaml --- .github/workflows/test.yaml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 87f7f4a..63b4505 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -8,13 +8,15 @@ on: jobs: test: runs-on: ubuntu-latest - permissions: - issues: write - pull-requests: write steps: - - name: Setup Python - uses: actions/setup-python@v5.3.0 - with: - python-version: 3 - - name: Run unittests - run: python3 -m unittest discover -s tests -p "*_test.py" + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install unittest + - name: Run unittests + run: python3 -m unittest discover -s tests -p "*_test.py" From 28cd715327209dd2bd0481c672a5d2dbf5e2863e Mon Sep 17 00:00:00 2001 From: Patrick762 Date: Fri, 25 Oct 2024 16:30:50 +0200 Subject: [PATCH 3/6] removed pip install --- .github/workflows/test.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 63b4505..997bed7 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,6 +17,5 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install unittest - name: Run unittests run: python3 -m unittest discover -s tests -p "*_test.py" From 6ce8f24477c25a4b803c8fb85009a1f8f86bc863 Mon Sep 17 00:00:00 2001 From: Patrick762 Date: Fri, 25 Oct 2024 16:32:19 +0200 Subject: [PATCH 4/6] added pip install requirements.txt --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 997bed7..8122dce 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,5 +17,6 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + pip install -r requirements.txt - name: Run unittests run: python3 -m unittest discover -s tests -p "*_test.py" From a72f42eb4afe45eb381c596ab9dcec783d016a39 Mon Sep 17 00:00:00 2001 From: Patrick762 Date: Fri, 25 Oct 2024 16:47:26 +0200 Subject: [PATCH 5/6] added simple test for struct --- tests/device_struct_test.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/device_struct_test.py diff --git a/tests/device_struct_test.py b/tests/device_struct_test.py new file mode 100644 index 0000000..09fbe3c --- /dev/null +++ b/tests/device_struct_test.py @@ -0,0 +1,24 @@ +"""Unittest for device builder.""" + +import unittest + +from custom_components.bluetti_bt.bluetti_bt_lib.utils.commands import ReadHoldingRegisters +from custom_components.bluetti_bt.bluetti_bt_lib.utils.struct import DeviceStruct + +class TestDeviceStruct(unittest.TestCase): + def test_get_read_holding_registers(self): + struct = DeviceStruct() + + struct.add_swap_string_field("device_type", 110, 6) + struct.add_sn_field("serial_number", 116) + struct.add_decimal_field( + "power_generation", 154, 1 + ) + struct.add_uint_field("total_battery_percent", 102) + + registers = struct.get_read_holding_registers() + + self.assertGreater(len(registers), 0) + + for reg in registers: + self.assertIsInstance(reg, ReadHoldingRegisters) From de1ca78c90b186512d1fc3d6e06370c3b7013758 Mon Sep 17 00:00:00 2001 From: Patrick762 Date: Fri, 25 Oct 2024 16:48:18 +0200 Subject: [PATCH 6/6] fixed comment --- tests/device_struct_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/device_struct_test.py b/tests/device_struct_test.py index 09fbe3c..850ef6f 100644 --- a/tests/device_struct_test.py +++ b/tests/device_struct_test.py @@ -1,4 +1,4 @@ -"""Unittest for device builder.""" +"""Unittest for device struct.""" import unittest