Skip to content

Commit

Permalink
Merge pull request #6 from natanfeitosa/add-label
Browse files Browse the repository at this point in the history
Added label functionality to resolve #4
  • Loading branch information
natanfeitosa authored Jan 25, 2023
2 parents f640a21 + e104c06 commit a1f199a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .replit
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ channel = "stable-21_11"
[env]
VIRTUAL_ENV = "/home/runner/${REPL_SLUG}/venv"
PATH = "${VIRTUAL_ENV}/bin"
PYTHONPATH = "${VIRTUAL_ENV}/lib/python3.8/site-packages"
PYTHONPATH = "${VIRTUAL_ENV}/lib/python3.10/site-packages"
REPLIT_POETRY_PYPI_REPOSITORY = "https://package-proxy.replit.com/pypi/"
MPLBACKEND = "TkAgg"
POETRY_CACHE_DIR = "${HOME}/${REPL_SLUG}/.cache/pypoetry"
Expand Down
5 changes: 5 additions & 0 deletions kohi/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def type_validator(data):
self._validators: t.List['Validator'] = [Validator('is-type', type_validator)]
self._throw: bool = False
self._errors: t.List[str] = []
self._label: str = ''

def __repr__(self):
return f'<{self.__class__.__name__} of kohi>'
Expand Down Expand Up @@ -76,4 +77,8 @@ def reset(self):
def throw(self):
self._throw = True
return self

def label(self, text: str):
self._label = text
return self

23 changes: 23 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from kohi.base import BaseSchema

def test_add_validator():
b = BaseSchema(list)
arg = [0, 1, 2, 3]

assert b.validate(arg)

def more_than_five(data):
if len(data) < 6:
return 'must have more than 5 items'
b.add_validator('more-than-five', more_than_five)

assert not b.validate(arg)

def test_label():
b = BaseSchema(object)

label = 'object_test'

assert (not b._label)
assert b.label(label) == b
assert b._label == label

0 comments on commit a1f199a

Please sign in to comment.