Skip to content

Commit

Permalink
Added test for example 9. Added coverage and function coverage for ex…
Browse files Browse the repository at this point in the history
…ample tests. (#509)

Co-authored-by: Paul Noalhyt <[email protected]>
  • Loading branch information
paulnoalhyt and Paul Noalhyt authored Oct 31, 2024
1 parent 6a0f0c1 commit f0188fa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ develop:

.PHONY: test
test:
$(PYTHON) -m pytest test_examples.py
$(PYTHON) -m pytest --cov=. --cov-report=term-missing test_examples.py
fun-coverage --cov-fail-under=100

.PHONY: dependencies
dependencies:
Expand Down
21 changes: 21 additions & 0 deletions examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from examples.ex5_binary_extension import SEVEN_KITTEH
from examples.ex8_recursive_unpacking import KITTEH as KITTEH_ASCII
from hashlib import md5

EXAMPLE_DIRECTORY = os.path.dirname(__file__)

Expand Down Expand Up @@ -160,3 +161,23 @@ def test_example_8(tmp_path):
with open("meow.txt") as f:
data = f.read().strip()
assert data == KITTEH_ASCII.strip(), f"Inner file meow.txt had incorrect contents {data}"
os.chdir(EXAMPLE_DIRECTORY)


def test_example_9(tmp_path):
"""
Test that the modified flash dump contains the inserted string and matches the right md5sum
"""
file = tmp_path / "repacked_flash_dump.bin"
command = ["python3", "ex9_flash_modification.py", "--output-file", str(file)]
subprocess.run(command, check=True)

with open(str(file), "rb") as f:
data = f.read()
expected_string = b"INSERT ME!"
assert expected_string in data, f"{str(file)} doesn't contain the {expected_string} string"
md5sum = md5(data).hexdigest()
expected_md5 = "6277eb7c64b12f247913eb4e875f5758"
assert (
md5sum == expected_md5
), f"md5sum for '{str(file)}' {md5sum} (expected {expected_md5})"

0 comments on commit f0188fa

Please sign in to comment.