Skip to content

Commit

Permalink
Update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovizro committed Dec 22, 2023
1 parent eac9540 commit 02dee8e
Show file tree
Hide file tree
Showing 10 changed files with 468 additions and 120 deletions.
33 changes: 33 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# .coveragerc to control coverage.py
[run]
branch = True
omit =
kola/lib/debugger/*
*/__main__.py

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain about missing debug-only code:
def __repr__

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:

# Don't complain about abstract methods, they aren't run:
@(abc\.)?abstractmethod

# Don't complain aboud typing hint
class (\w+)\(Protocol\):
@(typing\.)?overload


ignore_errors = True
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test:
python -m unittest

coverage:
coverage run --source ${MODULE} --parallel-mode -m unittest
coverage run --source ${MODULE} --parallel-mode -m pytest
coverage combine
coverage html -i

Expand Down
21 changes: 12 additions & 9 deletions karuha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import asyncio
import os
from pathlib import Path
from typing import List
from typing import Dict, List
from typing_extensions import deprecated


Expand All @@ -23,7 +23,7 @@
from .exception import KaruhaException


_bot_cache = {}
_bot_cache: Dict[str, Bot] = {}


def get_bot(name: str = "chatbot") -> Bot:
Expand All @@ -50,7 +50,8 @@ async def async_run() -> None:
bot = _bot_cache[i.name]
else:
bot = Bot.from_config(i, config)
tasks.append(asyncio.create_task(bot.async_run()))
_bot_cache[i.name] = bot
tasks.append(asyncio.create_task(bot.async_run(config.server)))
if not tasks:
raise ValueError("no bot loaded")
await asyncio.gather(*tasks)
Expand All @@ -60,14 +61,16 @@ def run() -> None:
config = get_config()
loop = asyncio.new_event_loop()

bots: List[Bot] = []
for i in config.bots:
if i.name in _bot_cache:
bot = _bot_cache[i.name]
else:
bot = Bot.from_config(i, config)
bots.append(bot)
loop.create_task(bot.async_run())
continue
bot = Bot.from_config(i, config)
_bot_cache[i.name] = bot

bots: List[Bot] = []
for bot in _bot_cache.values():
bots.append(bot)
loop.create_task(bot.async_run(config.server))

if config.server.enable_plugin:
server = init_server(config.server.listen)
Expand Down
Loading

0 comments on commit 02dee8e

Please sign in to comment.