Added first module unit tests; started changelog
parent
cccdd667fb
commit
0801762f07
|
@ -0,0 +1,8 @@
|
|||
# Changelog
|
||||
|
||||
## Unreleased
|
||||
### Added
|
||||
- Prefix can now be passed as argument to init
|
||||
|
||||
### Fixed
|
||||
- Buggy 'default' cached_property
|
16
Makefile
16
Makefile
|
@ -49,21 +49,13 @@ clean-setup:
|
|||
@ find . -maxdepth 1 -type d -name '*.egg-info' -exec rm -rf "{}" \;
|
||||
|
||||
# =====DOCS=====
|
||||
$(VENV)/bin/sphinx-build: build-venv
|
||||
@ echo "Installing sphinx..."
|
||||
@ "$(VENV)/bin/pip" install --quiet sphinx
|
||||
|
||||
docs: $(VENV)/bin/sphinx-build
|
||||
docs: build-venv
|
||||
@ "$(VENV)/bin/sphinx-apidoc" -o "$(DOCS)/source" "$(SRC)"
|
||||
@ "$(VENV)/bin/sphinx-build" "$(DOCS)/source" "$(DOCS)/build"
|
||||
|
||||
|
||||
# =====TESTS=====
|
||||
$(VENV)/bin/pytest: build-venv
|
||||
@ echo "Installing pytest..."
|
||||
@ "$(VENV)/bin/pip" install --quiet pytest
|
||||
|
||||
test: pytest.ini $(VENV)/bin/pytest
|
||||
test: pytest.ini build-venv
|
||||
@ "$(VENV)/bin/pytest" --color=yes
|
||||
|
||||
|
||||
|
@ -78,7 +70,7 @@ publish: package
|
|||
@ echo 'Installing twine...'
|
||||
@ $(VENV)/bin/pip install --quiet --upgrade twine
|
||||
@ [ git symbolic-ref HEAD --short = master ] && { \
|
||||
echo 'Publishing to PyPi Testing...'; \
|
||||
echo 'Publishing to PyPi...'; \
|
||||
$(VENV)/bin/python -m twine upload dist/* ; \
|
||||
} || { \
|
||||
echo 'Publishing to PyPi Testing...'; \
|
||||
|
@ -86,7 +78,5 @@ publish: package
|
|||
}
|
||||
|
||||
|
||||
# Publish will also come here someday
|
||||
|
||||
.PHONY: all clean clean-venv clean-cache clean-docs test package docs \
|
||||
build-venv run-venv clean-setup
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
from typing import List, Dict
|
||||
|
||||
|
||||
class Module:
|
||||
PREFIX = []
|
||||
NAME = ""
|
||||
|
||||
def __init__(self, client: "Frank", config: Dict = None):
|
||||
self._client = client
|
||||
self._config = config
|
||||
|
||||
async def start(self):
|
||||
pass
|
||||
|
||||
async def command(self, cmd: List[str]):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def match(cls, s: str) -> bool:
|
||||
"""
|
||||
Checks wether the given string is a prefix in the module.
|
||||
"""
|
||||
|
||||
if cls.PREFIX:
|
||||
if isinstance(cls.PREFIX, list):
|
||||
return s in cls.PREFIX
|
||||
|
||||
else:
|
||||
return s == cls.PREFIX
|
||||
|
||||
else:
|
||||
return False
|
|
@ -8,3 +8,5 @@ flake8-eradicate~=0.4.0
|
|||
flake8-quotes~=3.2.0
|
||||
flake8-variables-names~=0.0.3
|
||||
setuptools~=49.6.0
|
||||
pytest>=6.0.1,<7.0.0
|
||||
pytest-asyncio>=0.14.0,<1.0.0
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
from frank import Module, command, default
|
||||
|
||||
|
||||
class ModuleTester(Module):
|
||||
@command('test')
|
||||
async def test(cmd, author, channel, mid):
|
||||
pass
|
||||
|
||||
@default()
|
||||
async def test2(prefix, cmd, author, channel, mid):
|
||||
pass
|
|
@ -0,0 +1,30 @@
|
|||
from .module_tester import ModuleTester
|
||||
from frank import Default, Daemon, Command
|
||||
from frank.module.exceptions import InvalidCommand
|
||||
import pytest
|
||||
|
||||
|
||||
def test_property_types():
|
||||
test_mod = ModuleTester(None)
|
||||
|
||||
assert isinstance(test_mod.default, Default)
|
||||
assert hasattr(test_mod.default, 'help_str')
|
||||
|
||||
assert isinstance(test_mod.commands, list)
|
||||
assert all((
|
||||
isinstance(item, Command) for item in test_mod.commands
|
||||
))
|
||||
|
||||
assert isinstance(test_mod.commands, list)
|
||||
assert all((
|
||||
isinstance(item, Daemon) for item in test_mod.daemons
|
||||
))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_invalid_command():
|
||||
test_mod = ModuleTester(None)
|
||||
|
||||
with pytest.raises(InvalidCommand):
|
||||
# None is just a placeholder here
|
||||
await test_mod('aninvalidcommand', None, None, None)
|
|
@ -1,2 +0,0 @@
|
|||
def test_success():
|
||||
pass
|
Reference in New Issue