Skip to content

Commit

Permalink
feat: add pytest to repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Robso-creator committed Jan 25, 2024
1 parent 3bc8ad4 commit 75c3b79
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ jobs:
with:
python-version: '3.10'
- uses: pre-commit/action@v3.0.0

run-tests:
runs-on: ubuntu-latest
steps:
- name: run tests
run: python -m pytest
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ all:
@echo "#### functions implemented"
@echo "make up ...................... runs main.py"
@echo "make pc ...................... runs pre-commit on all files"
@echo "make test .................... runs all tests (pytest)"

pc:
@echo "[PRE-COMMIT] All files"
pre-commit run --all-files

up:
python3 -m src.main

test:
python3 -m pytest
1 change: 1 addition & 0 deletions docs/README-en.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
![makefile](https://img.shields.io/badge/makefile-enabled-brightgreen?logo=gmail&logoColor=blue)
[![pytest](https://img.shields.io/badge/pytest-enabled-brightgreen?logo=pytest&logoColor=red)](https://docs.pytest.org/en/7.4.x/)

# Discord Bot
<sub>Não fala inglês? [Clique aqui](https://github.com/Robso-creator/discord_bot/blob/main/README.md) para ver esta página em português</sub>
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
![makefile](https://img.shields.io/badge/makefile-enabled-brightgreen?logo=gmail&logoColor=blue)
[![pytest](https://img.shields.io/badge/pytest-enabled-brightgreen?logo=pytest&logoColor=red)](https://docs.pytest.org/en/7.4.x/)

# Bot do Discord
<sub>Don't speak portuguese? [Click here](https://github.com/Robso-creator/discord_bot/blob/main/README-en.md) to view this page in English</sub>
Expand Down
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-r requirements.txt

pytest==7.4.4
pytest-sugar==0.9.7
5 changes: 3 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ async def on_message(self, message):
)


client = MyClient(intents=intents)
client.run(settings.DISCORD_TOKEN)
if __name__ == '__main__':
client = MyClient(intents=intents)
client.run(settings.DISCORD_TOKEN)
30 changes: 30 additions & 0 deletions tests/test_bot_funcs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from unittest.mock import MagicMock

import pytest

from src.main import MyClient


@pytest.fixture
def mocked_discord_client(monkeypatch):
mocked_client = MagicMock(spec=MyClient)

monkeypatch.setattr(mocked_client, 'run', MagicMock())

return mocked_client


def test_on_ready_called(mocked_discord_client):
client = mocked_discord_client()

client.on_ready()

assert client.on_ready.called


def test_on_message_called(mocked_discord_client):
client = mocked_discord_client()

client.on_message('Mocked')

assert client.on_message.called

0 comments on commit 75c3b79

Please sign in to comment.