Added first module unit tests; started changelog

master
Jef Roosens 2020-08-26 09:45:03 +02:00
parent cccdd667fb
commit 0801762f07
8 changed files with 54 additions and 47 deletions

8
CHANGELOG.md 100644
View File

@ -0,0 +1,8 @@
# Changelog
## Unreleased
### Added
- Prefix can now be passed as argument to init
### Fixed
- Buggy 'default' cached_property

View File

@ -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

View File

@ -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

View File

@ -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

View File

View File

@ -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

View File

@ -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)

View File

@ -1,2 +0,0 @@
def test_success():
pass