Skip to content

Commit

Permalink
Merge pull request #5 from Robso-creator/issue-2
Browse files Browse the repository at this point in the history
feat: add pytest to repo
  • Loading branch information
Robso-creator authored Jan 25, 2024
2 parents 3bc8ad4 + 0e6a739 commit e6dcea0
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 19 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/pre-commit.yml

This file was deleted.

35 changes: 35 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
on:
pull_request:
branches: [main]
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.10'
- uses: pre-commit/action@v3.0.0

run-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- 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=#0A9EDC)](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=#0A9EDC)](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
8 changes: 4 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import discord

import settings

intents = discord.Intents.default()
intents.typing = False
intents.presences = False
Expand All @@ -23,5 +21,7 @@ async def on_message(self, message):
)


client = MyClient(intents=intents)
client.run(settings.DISCORD_TOKEN)
if __name__ == '__main__':
import settings
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 e6dcea0

Please sign in to comment.