Skip to content

Commit

Permalink
Merge branch 'master' into fix/bytes-error-msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
vil02 authored Aug 18, 2024
2 parents cb8fc0b + be0459c commit 184a5f1
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 7 deletions.
20 changes: 20 additions & 0 deletions bump_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

set -euo pipefail

if [[ "$#" -ne 1 ]]; then
echo "Provide one argument."
exit 1
fi

VERSION_ARG=$1
readonly VERSION_ARG

poetry version "${VERSION_ARG}"


NEW_VERSION=$(poetry version --short)
readonly NEW_VERSION

git add pyproject.toml
git commit -m "chore: bump version to \`${NEW_VERSION}\`"
7 changes: 7 additions & 0 deletions puzzle_generator/configurators/check_kwargs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def check_kwargs(allowed_params, **kwargs):
for cur_param in kwargs:
if cur_param not in allowed_params:
raise TypeError(
f"{cur_param} is an invalid keyword argument. "
f"Valid arguments are {allowed_params}."
)
3 changes: 2 additions & 1 deletion puzzle_generator/configurators/configurators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ def get_configurator(**kwargs):
"simple": simple.Simple,
"spiced": spiced.Spiced,
}
return configurators[encryption](**kwargs)
new_kwargs = {_k: _v for _k, _v in kwargs.items() if _k != "encryption"}
return configurators[encryption](**new_kwargs)
2 changes: 2 additions & 0 deletions puzzle_generator/configurators/simple/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

from ...encryption_algorithms.simple import simple as se
from . import common as csc
from ..check_kwargs import check_kwargs


class Simple:
def __init__(self, **kwargs):
check_kwargs({"scrypt_params", "signature_params"}, **kwargs)
self._scrypt_params = csc.scrypt_params(**kwargs)
self._signature_params = csc.signature_params(**kwargs)

Expand Down
5 changes: 5 additions & 0 deletions puzzle_generator/configurators/simple/spiced.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ... import bytestr_utils as bu
from ...encryption_algorithms.simple import spiced as sse
from . import common as csc
from ..check_kwargs import check_kwargs


def _get_some_spices():
Expand All @@ -21,6 +22,10 @@ def _list_of_bytes_to_codestr(in_list: typing.List[bytes]) -> str:

class Spiced:
def __init__(self, **kwargs):
check_kwargs(
{"scrypt_params", "signature_params", "proc_spices", "signature_spices"},
**kwargs,
)
self._scrypt_params = csc.scrypt_params(**kwargs)
self._signature_params = csc.signature_params(**kwargs)
self._proc_spices = kwargs.get("proc_spices", _get_some_spices())
Expand Down
4 changes: 2 additions & 2 deletions puzzle_generator/run_puzzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
def run_puzzle(
in_puzzle: typing.Tuple[str, bytes],
in_decrypt: typing.Callable[[bytes, bytes], bytes | None],
get_answer,
):
get_answer: typing.Callable[[], str],
) -> None:
question, rest = in_puzzle
print(question)
if rest:
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "puzzle-generator"
version = "0.10.0"
version = "0.10.2"
description = "Generates python code representing a puzzle"
authors = ["piotr.idzik <[email protected]>"]
readme = "./puzzle_generator/README.md"
Expand All @@ -19,10 +19,10 @@ optional = true
[tool.poetry.group.dev.dependencies]
pytest = "8.3.2"
pylint = "3.2.6"
flake8 = "7.1.0"
flake8 = "7.1.1"
flake8-pytest-style = "2.0.0"
ruff = "0.5.6"
coverage = "7.6.0"
ruff = "0.6.1"
coverage = "7.6.1"
mypy = "1.11.1"
bandit = "1.7.9"

Expand Down
10 changes: 10 additions & 0 deletions tests/test_configurators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest

from puzzle_generator.configurators.simple import simple
from puzzle_generator.configurators.simple import spiced


@pytest.mark.parametrize("configurator", [simple.Simple, spiced.Spiced])
def test_configurators_raise_when_invalid_args(configurator):
with pytest.raises(TypeError):
configurator(wrong_param=10)

0 comments on commit 184a5f1

Please sign in to comment.