Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix tests. Add makefile. Re-organise dependencies
  • Loading branch information
ZetaTwo committed Jan 11, 2024
commit 7bd470aaf35eb3719d3fd0425e6b64dd5b395b2b
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

dependencies:
pip install -r requirements.txt

dependencies-dev:
pip install -r requirements-dev.txt

mypy:
python -m mypy --strict --exclude build .

test:
python -m pytest .

.PHONY: dependencies dependencies-dev mypy test
6 changes: 3 additions & 3 deletions challtools/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def set_defaults(validator, properties, instance, schema2):


class Message(object):
def __init__(self, code, field, name, level, message):
def __init__(self, code: str, field, name: str, level: int, message: str):
self.code = code
self.field = field
self.name = name
Expand All @@ -58,7 +58,7 @@ class ConfigValidator:
def __init__(self, config, ctf_config=None, challdir=None):
if not isinstance(config, dict):
raise ValueError("Config parameter needs to be a dict")
self.messages = []
self.messages: List[Message] = []
self.config = {}
self.normalized_config = {}
self.config = config
Expand Down Expand Up @@ -262,7 +262,7 @@ def validate(self) -> Tuple[bool, List[Message]]:

return True, self.messages

def _raise_code(self, code, field=None, **formatting) -> None:
def _raise_code(self, code: str, field: str = None, **formatting) -> None:
"""Adds a formatted message entry into the messages array.

Args:
Expand Down
10 changes: 10 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-r requirements.txt
pytest
pytest-cov

types-flask
types-jsonschema
types-pkg_resources
types-PyYAML
types-requests
types-setuptools
11 changes: 2 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
argcomplete
docker
pytest
jsonschema
pyyaml
requests

types-PyYAML
types-jsonschema
types-pkg_resources
types-flask
types-setuptools
types-requests
requests
20 changes: 11 additions & 9 deletions tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_invalid(self):

success, errors = validator.validate()
assert not success
assert any([error["code"] == "A002" for error in errors])
assert any([error.code == "A002" for error in errors])


class Test_A005:
Expand All @@ -30,7 +30,7 @@ def test_valid(self):

success, errors = validator.validate()
assert success
assert not any([error["code"] == "A005" for error in errors])
assert not any([error.code == "A005" for error in errors])

def test_warn(self):
config = get_min_valid_config()
Expand All @@ -39,7 +39,7 @@ def test_warn(self):

success, errors = validator.validate()
assert success
assert any([error["code"] == "A005" for error in errors])
assert any([error.code == "A005" for error in errors])


class Test_A006:
Expand All @@ -54,7 +54,7 @@ def test_valid(self):
success, errors = validator.validate()

assert success
assert not any([error["code"] == "A006" for error in errors])
assert not any([error.code == "A006" for error in errors])

def test_invalid(self):
config = get_min_valid_config()
Expand All @@ -67,7 +67,7 @@ def test_invalid(self):
success, errors = validator.validate()

assert success
assert any([error["code"] == "A006" for error in errors])
assert any([error.code == "A006" for error in errors])


class Test_A007:
Expand All @@ -84,7 +84,7 @@ def test_valid(self):
success, errors = validator.validate()

assert success
assert not any([error["code"] == "A007" for error in errors])
assert not any([error.code == "A007" for error in errors])

def test_invalid(self):
config = get_min_valid_config()
Expand All @@ -99,7 +99,7 @@ def test_invalid(self):
success, errors = validator.validate()

assert success
assert any([error["code"] == "A007" for error in errors])
assert any([error.code == "A007" for error in errors])


class Test_A008:
Expand All @@ -112,7 +112,7 @@ def test_valid(self):
success, errors = validator.validate()

assert success
assert not any([error["code"] == "A008" for error in errors])
assert not any([error.code == "A008" for error in errors])

def test_invalid(self):
config = get_min_valid_config()
Expand All @@ -121,5 +121,7 @@ def test_invalid(self):

success, errors = validator.validate()

print(errors)

assert success
assert any([error["code"] == "A008" for error in errors])
assert any([error.code == "A008" for error in errors])