Skip to content

Commit

Permalink
Add a test for python exception
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Jan 11, 2024
1 parent e879377 commit 5544b5b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ jobs:

- name: Update tests outputs
run: python3 tests/check_correct_sum.py

- name: Test exceptions
run: python3 tests/exception_test.py
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ipl3checksum/ipl3checksum.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ from .checksum import calculateChecksumAutodetect as calculateChecksumAutodetect
from .detect import detectCIC as detectCIC
from .detect import detectCICRaw as detectCICRaw

import exceptions as exceptions
from .exceptions import exceptions as exceptions
22 changes: 22 additions & 0 deletions tests/exception_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python3

# SPDX-FileCopyrightText: © 2024 Decompollaborate
# SPDX-License-Identifier: MIT

from __future__ import annotations

import ipl3checksum

# We want this buffer to be small so it triggers an exception
b = bytes([0,0,0,0])

try:
checksum = ipl3checksum.CICKind.CIC_6102_7101.calculateChecksum(b)

print(f"This code shouldn't run")
print(f"{checksum[0]:08X} {checksum[1]:08X}")
raise RuntimeError()

except ipl3checksum.exceptions.BufferNotBigEnough as e:
print("We triggered and succesfully catched an exception!")
print(f" e: {e}")

0 comments on commit 5544b5b

Please sign in to comment.