Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Tests

on:
push:
branches: [ main ]
pull_request:

# Allow job to be triggered manually.
workflow_dispatch:

# Cancel in-progress jobs when pushing to the same branch.
concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}

jobs:

tests:

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"

env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}

name: Python ${{ matrix.python-version }} on OS ${{ matrix.os }}
steps:

- name: Acquire sources
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64
cache: 'pip'
cache-dependency-path: |
requirements-*.txt

- name: Setup project
run: |
pip install --use-pep517 --prefer-binary --requirement requirements-tests.txt

- name: Run linter and software tests
run: |
pytest
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.idea
__pycache__
5 changes: 5 additions & 0 deletions mqttdecode
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,11 @@ def get_args():
epilog="https://github.com/mqtt-tools/mqttdecode"
)

parser.add_argument(
"-v", "--version", action="version",
version = f"{parser.prog} version 0.0.1"
)

parser.add_argument(
'-s', "--force-spec", action="store", type=int, default=None,
choices=[4, 5],
Expand Down
2 changes: 2 additions & 0 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest
runs
44 changes: 44 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import subprocess

import runs


def run_mqttdecode(arguments):
"""
Utility function to invoke `mqttdecode`.

:param arguments:
:return:
"""
command = f"python mqttdecode {arguments}"
response = runs.run(command)
return response


def test_cli_version(capfd):
"""
Verify `mqttdecode --version` succeeds.
"""
run_mqttdecode("--version")
out, err = capfd.readouterr()
assert out.strip() == "mqttdecode version 0.0.1"


def test_cli_mqttdecode(capfd):
"""
Verify basic `mqttdecode` incantation.
"""
output = subprocess.check_output(["python", "mqttdecode", "50020001"])
assert output == b"""
Hex: 50 02 0001
Command: PUBREC v3.1.1
Length: 2
Packet ID: 1

Hex: 50 02 0001
Command: PUBREC v5.0
Length: 2
Packet ID: 1
Reason code: 0 (success)

""".lstrip()
Loading