Skip to content

Commit 0dfb2e7

Browse files
committed
fixing tests
1 parent a19602f commit 0dfb2e7

File tree

8 files changed

+142
-86
lines changed

8 files changed

+142
-86
lines changed

.github/workflows/cd.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
2+
3+
on: push
4+
5+
jobs:
6+
build:
7+
name: Build distribution 📦
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
persist-credentials: false
14+
- name: Set up Python
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: "3.x"
18+
- name: Install pypa/build
19+
run: >-
20+
python3 -m
21+
pip install
22+
build
23+
--user
24+
- name: Build a binary wheel and a source tarball
25+
run: python3 -m build
26+
- name: Store the distribution packages
27+
uses: actions/upload-artifact@v4
28+
with:
29+
name: python-package-distributions
30+
path: dist/
31+
32+
publish-to-pypi:
33+
name: >-
34+
Publish Python 🐍 distribution 📦 to PyPI
35+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
36+
needs:
37+
- build
38+
runs-on: ubuntu-latest
39+
environment:
40+
name: pypi
41+
url: https://pypi.org/p/isp-programmer # Replace <package-name> with your PyPI project name
42+
permissions:
43+
id-token: write # IMPORTANT: mandatory for trusted publishing
44+
45+
steps:
46+
- name: Download all the dists
47+
uses: actions/download-artifact@v4
48+
with:
49+
name: python-package-distributions
50+
path: dist/
51+
- name: Publish distribution 📦 to PyPI
52+
uses: pypa/gh-action-pypi-publish@release/v1
53+
54+
publish-to-testpypi:
55+
name: Publish Python 🐍 distribution 📦 to TestPyPI
56+
needs:
57+
- build
58+
runs-on: ubuntu-latest
59+
60+
environment:
61+
name: testpypi
62+
url: https://test.pypi.org/p/isp-programmer
63+
64+
permissions:
65+
id-token: write # IMPORTANT: mandatory for trusted publishing
66+
67+
steps:
68+
- name: Download all the dists
69+
uses: actions/download-artifact@v4
70+
with:
71+
name: python-package-distributions
72+
path: dist/
73+
- name: Publish distribution 📦 to TestPyPI
74+
uses: pypa/gh-action-pypi-publish@release/v1
75+
with:
76+
repository-url: https://test.pypi.org/legacy/

.github/workflows/python-app.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Python application
5+
6+
on:
7+
push:
8+
branches: [ "master" ]
9+
pull_request:
10+
branches: [ "master" ]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Set up Python 3.9
23+
uses: actions/setup-python@v3
24+
with:
25+
python-version: "3.9"
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
python -m pip install .
30+
pip install ruff pytest
31+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
32+
- name: Lint with ruff
33+
run: |
34+
# stop the build if there are Python syntax errors or undefined names
35+
ruff check --exit-non-zero-on-fix
36+
- name: Test with pytest
37+
run: |
38+
pytest

.github/workflows/python-package.yml

Lines changed: 0 additions & 39 deletions
This file was deleted.

.github/workflows/pythonpublish.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/isp_programmer/ISPConnection.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import struct
66
from dataclasses import dataclass
77
import typing
8-
from typing import Deque, Union
8+
from typing import Deque, Union, Dict
99
from collections import deque
1010

1111
from intelhex import IntelHex
@@ -578,11 +578,11 @@ class ChipDescription:
578578
Wraps a chip description line and exposes it as a class
579579
"""
580580

581-
kWordSize = 4
582-
kPageSizeBytes = 64
583-
SectorSizePages = 16
584-
CRCLocation = 0x000002FC
585-
CRCValues = {
581+
kWordSize: int = 4
582+
kPageSizeBytes: int = 64
583+
SectorSizePages: int = 16
584+
CRCLocation: int = 0x000002FC
585+
CRCValues: Dict[str, int] = {
586586
"NO_ISP": 0x4E697370,
587587
"CRP1": 0x12345678,
588588
"CRP2": 0x87654321,
@@ -957,7 +957,7 @@ def SetupChip(
957957
chip = ChipDescription(descriptor)
958958
chip.CrystalFrequency = crystal_frequency
959959

960-
_log.debug("Setting new baudrate %d" % baudrate)
960+
_log.debug("Setting new baudrate %d", baudrate)
961961
isp.SetBaudRate(baudrate) # set the chips baudrate
962962
isp.baud_rate = baudrate # change the driver baudrate
963963
time.sleep(isp.settings.set_baudrate_sleep)

src/isp_programmer/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
from .ISPConnection import *
1+
from .ISPConnection import (BAUDRATES,
2+
Settings,
3+
ISPConnection)
4+
5+
__all__ = ("BAUDRATES", "Settings", "ISPConnection")

tests/__init__.py

Whitespace-only changes.

tests/test_read_lpcparts_file.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1+
import unittest
2+
from pathlib import Path
13
from isp_programmer import parts_definitions
24

3-
def_file = "lpctools_parts.def"
45

5-
if __name__ == "__main__":
6-
df = parts_definitions.ReadChipFile(def_file)
7-
print(df)
6+
def_file = Path(__file__).absolute().parent / "lpctools_parts.def"
7+
8+
9+
class SmokeTest(unittest.TestCase):
10+
def test_smoketest(self):
11+
df = parts_definitions.ReadChipFile(def_file)
12+
print(df)
813

9-
line = parts_definitions.GetPartDescriptorLine(fname=def_file, partid=0x00008041)
10-
print(line)
14+
line = parts_definitions.GetPartDescriptorLine(fname=def_file, partid=0x00008041)
15+
self.assertTrue(line is not None)
1116

12-
line = parts_definitions.GetPartDescriptorLine(fname=def_file, partid=0x0000804)
13-
print(line)
17+
with self.assertRaises(ValueError):
18+
parts_definitions.GetPartDescriptorLine(fname=def_file, partid=0x0000804)
19+
20+
if __name__ == "__main__":
21+
unittest.main()

0 commit comments

Comments
 (0)