Skip to content

Commit eacc82f

Browse files
authored
Merge pull request #2 from int-brain-lab/develop
v0.1.2
2 parents afc4ce1 + d15138d commit eacc82f

File tree

6 files changed

+63
-31
lines changed

6 files changed

+63
-31
lines changed

.github/workflows/testing.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
name: CI
22
on:
33
workflow_dispatch:
4+
push:
5+
branches:
6+
- master
47
pull_request:
58
paths-ignore:
69
- 'docs/**'
10+
- '**/*.md'
711

812
jobs:
913
Ruff:

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.1.2] - 2024-07-11
9+
10+
### Changed
11+
12+
- dropped 'verbose' argument from list_boards()
13+
- dropped 'full' argument from version()
14+
815
## [0.1.1] - 2024-07-11
916

1017
### Added
@@ -16,5 +23,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1623
_First release._
1724

1825

26+
[0.1.2]: https://github.com/int-brain-lab/tycmd-wrapper/releases/tag/v0.1.2
1927
[0.1.1]: https://github.com/int-brain-lab/tycmd-wrapper/releases/tag/v0.1.1
2028
[0.1.0]: https://github.com/int-brain-lab/tycmd-wrapper/releases/tag/v0.1.0

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Martignène](https://github.com/Koromix/).
1010
Documentation: https://int-brain-lab.github.io/tycmd-wrapper
1111

1212
![License](https://img.shields.io/github/license/int-brain-lab/tycmd-wrapper)
13-
![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)
1413
[![Coverage](https://img.shields.io/coverallsCoverage/github/int-brain-lab/tycmd-wrapper)](https://coveralls.io/github/int-brain-lab/tycmd-wrapper)
1514
[![CI](https://github.com/int-brain-lab/tycmd-wrapper/actions/workflows/testing.yaml/badge.svg)](https://github.com/int-brain-lab/tycmd-wrapper/actions)
16-
[![Documentation](https://img.shields.io/badge/Sphinx-doc-green)](https://int-brain-lab.github.io/tycmd-wrapper)
15+
[![PyPI](https://img.shields.io/pypi/v/tycmd-wrapper)](https://pypi.org/project/tycmd-wrapper/)

docs/source/dev_guide.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ Building the package
5555

5656
.. code-block:: bash
5757
58-
pdm build --config-setting="--python-tag=py3" --config-setting="--py-limited-api=none"
58+
pdm build

tests/test_tycmd.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
from pathlib import Path
22
from tempfile import TemporaryDirectory
3+
from unittest.mock import patch
34

45
import pytest
56

67
import tycmd
7-
import re
88

99

1010
BLINK_HEX = Path(__file__).parent.joinpath("blink.hex").resolve()
1111

1212

13+
@pytest.fixture
14+
def mock_check_output():
15+
with patch("tycmd.check_output") as mock_check_output:
16+
yield mock_check_output
17+
18+
1319
def test_identify():
1420
with TemporaryDirectory() as temp_directory:
1521
firmware_file = Path(temp_directory).joinpath("firmware.hex")
@@ -19,13 +25,34 @@ def test_identify():
1925
assert "Teensy 4.0" in tycmd.identify(BLINK_HEX)
2026

2127

28+
def test_list_boards(mock_check_output):
29+
mock_check_output.return_value = (
30+
'[\n {"action": "add", "tag": "12345678-Teensy", "serial": "12345678", '
31+
'"description": "USB Serial", "model": "Teensy 4.1", "location": "usb-3-3", '
32+
'"capabilities": ["unique", "run", "rtc", "reboot", "serial"], '
33+
'"interfaces": [["Serial", "/dev/ttyACM0"]]}\n]\n'
34+
)
35+
output = tycmd.list_boards()
36+
mock_check_output.assert_called_once_with(
37+
["tycmd", "list", "-O", "json", "-v"], text=True
38+
)
39+
assert isinstance(output, list)
40+
assert isinstance(output[0], dict)
41+
assert output[0]["serial"] == "12345678"
42+
43+
mock_check_output.return_value = "[\n]\n"
44+
output = tycmd.list_boards()
45+
assert isinstance(output, list)
46+
assert len(output) == 0
47+
48+
2249
def test_version():
23-
output = tycmd.version(full=True)
24-
assert isinstance(output, str)
25-
match = re.search(r"^.+(\d+\.\d+\.\d+)", output)
26-
assert match is not None
27-
assert match.groups()[0] == tycmd._TYCMD_VERSION
28-
assert tycmd.version(full=False) == tycmd._TYCMD_VERSION
50+
assert tycmd.version() == tycmd._TYCMD_VERSION
51+
with (
52+
patch("tycmd.check_output", return_value="invalid") as _,
53+
pytest.raises(RuntimeError),
54+
):
55+
tycmd.version()
2956

3057

3158
def test__parse_firmware_file():

tycmd.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import re
77
from logging import getLogger
88

9-
__version__ = "0.1.1"
9+
__version__ = "0.1.2"
1010
_TYCMD_VERSION = "0.9.9"
1111

1212
log = getLogger(__name__)
@@ -35,45 +35,39 @@ def identify(filename: Path | str) -> list[str]:
3535
return output.get("models", [])
3636

3737

38-
def list_boards(verbose: bool = True) -> list[dict]:
38+
def list_boards() -> list[dict]:
3939
"""
4040
List available boards.
4141
42-
Parameters
43-
----------
44-
verbose : bool, optional
45-
If True, include detailed information about devices. Default is True.
46-
4742
Returns
4843
-------
4944
list[dict]
5045
List of available devices.
5146
"""
52-
args = ["tycmd", "list", "-O", "json"] + (["-v"] if verbose else [])
53-
return json.loads(check_output(args, text=True))
47+
args = ["tycmd", "list", "-O", "json", "-v"]
48+
return_string = check_output(args, text=True)
49+
return json.loads(return_string)
5450

5551

56-
def version(full: bool = False) -> str:
52+
def version() -> str:
5753
"""
58-
Return version information from tycmd.
59-
60-
Parameters
61-
----------
62-
full : bool, optional
63-
If True, return the full version string as returned by the tycmd binary. If
64-
False, return only the version number. Default is False.
54+
Return version information from tycmd binary.
6555
6656
Returns
6757
-------
6858
str
6959
The version of tycmd.
60+
61+
Raises
62+
------
63+
RuntimeError
64+
If the version string could not be determined.
7065
"""
7166
output = _call_tycmd(["--version"])
72-
if full:
73-
return output.strip()
67+
match = re.search(r"\d+\.\d+\.\d+", output)
68+
if match is None:
69+
raise RuntimeError("Could not determine tycmd version")
7470
else:
75-
if (match := re.search(r"\d+\.\d+\.\d+", output)) is None:
76-
return ""
7771
return match.group()
7872

7973

0 commit comments

Comments
 (0)