-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from artembakhanov/tests_and_documentation
Tests and documentation + update 1.0.4
- Loading branch information
Showing
8 changed files
with
202 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Tests | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.6, 3.7, 3.8] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 pytest | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
- name: Lint with flake8 | ||
run: | | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test with pytest | ||
run: | | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Upload Package | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install setuptools wheel twine | ||
- name: Build and publish | ||
env: | ||
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} | ||
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | ||
run: | | ||
python setup.py sdist bdist_wheel | ||
twine upload dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import pytest | ||
import sys, os | ||
from datetime import date | ||
from types import SimpleNamespace | ||
|
||
myPath = os.path.dirname(os.path.abspath(__file__)) | ||
sys.path.insert(0, myPath + '/../') | ||
from telegram_bot_calendar.base import YEAR, MONTH, DAY, max_date, min_date, TelegramCalendar, CB_CALENDAR | ||
|
||
|
||
@pytest.mark.parametrize(('given', 'step', 'max_d'), [(date(2019, 5, 2), YEAR, date(2019, 12, 31)), | ||
(date(1999, 12, 30), YEAR, date(1999, 12, 31)), | ||
(date(2001, 1, 2), YEAR, date(2001, 12, 31)), | ||
(date(2012, 5, 1), MONTH, date(2012, 5, 31)), | ||
(date(2019, 9, 15), MONTH, date(2019, 9, 30)), | ||
(date(2016, 2, 10), MONTH, date(2016, 2, 29)), | ||
(date(2016, 2, 10), DAY, date(2016, 2, 10)), | ||
]) | ||
def test_max_date(given, step, max_d): | ||
assert max_date(given, step) == max_d | ||
|
||
|
||
@pytest.mark.parametrize(('given', 'step', 'min_d'), [(date(2019, 5, 2), YEAR, date(2019, 1, 1)), | ||
(date(1999, 12, 30), YEAR, date(1999, 1, 1)), | ||
(date(2001, 1, 2), YEAR, date(2001, 1, 1)), | ||
(date(2012, 5, 1), MONTH, date(2012, 5, 1)), | ||
(date(2019, 9, 15), MONTH, date(2019, 9, 1)), | ||
(date(2016, 2, 10), MONTH, date(2016, 2, 1)), | ||
(date(2016, 2, 10), DAY, date(2016, 2, 10)), | ||
]) | ||
def test_min_date(given, step, min_d): | ||
assert min_date(given, step) == min_d | ||
|
||
|
||
@pytest.mark.parametrize(('min_date', 'max_date', 'step', 'start', 'diff', 'period'), | ||
[(date(2019, 11, 9), None, YEAR, date(2020, 1, 12), 2, | ||
[date(2020, 1, 12), date(2021, 1, 12)])]) | ||
def test__get_period(min_date, max_date, step, start, diff, period): | ||
telegram_calendar = TelegramCalendar(min_date=min_date, max_date=max_date) | ||
|
||
assert telegram_calendar._get_period(step, start, diff) == period | ||
|
||
|
||
@pytest.mark.parametrize(('calendar_id', 'callback_data', 'passed'), | ||
[(0, 'cbcal_0_g_y_2017_1_13_238946419208856913', True), | ||
(1, 'cbcal_0_g_y_2017_1_13_238946419208856913', False), | ||
(1, 'cbcal_1_s_d_2016_8_25_971574741092873836', True), | ||
(0, 'something_irrelevant', False), | ||
(22, 'cbcal_22_n', True), ]) | ||
def test_func(calendar_id, callback_data, passed): | ||
assert TelegramCalendar.func(calendar_id)(SimpleNamespace(data=callback_data)) == passed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import json | ||
import os | ||
import sys | ||
from datetime import date | ||
|
||
import pytest | ||
from dateutil.relativedelta import relativedelta | ||
|
||
from telegram_bot_calendar import DAY, MONTH, YEAR | ||
from telegram_bot_calendar.detailed import DetailedTelegramCalendar, NOTHING | ||
|
||
myPath = os.path.dirname(os.path.abspath(__file__)) | ||
sys.path.insert(0, myPath + '/../') | ||
|
||
|
||
# todo: fix this test to properly check generated keyboard | ||
@pytest.mark.parametrize(('callback_data', 'result', 'key', 'step'), | ||
[('cbcal_0_s_m_2021_11_13_726706365801178150', None, None, DAY), | ||
('cbcal_0_s_d_2021_11_13_726706365801178150', date(2021, 11, 13), None, DAY), | ||
('cbcal_0_s_y_2020_1_1_726702345801178150', None, None, MONTH), | ||
('cbcal_0_n_726702345801178150', None, None, None), | ||
('cbcal_0_g_m_2022_5_7_726702345801178150', None, None, MONTH)]) | ||
def test_process(callback_data, result, key, step): | ||
calendar = DetailedTelegramCalendar(current_date=date(2021, 1, 12)) | ||
result_, _, step_ = calendar.process(callback_data) | ||
assert result_ == result and step_ == step | ||
|
||
|
||
@pytest.mark.parametrize( | ||
('step', 'start', 'diff', 'mind', 'maxd', 'min_button_date', 'max_button_date', 'result_buttons'), | ||
[ | ||
( | ||
MONTH, date(2021, 1, 12), relativedelta(months=12), date(2021, 1, 1), date(2021, 3, 2), date(2021, 1, 1), | ||
date(2021, 3, 2), | ||
[{'text': "×", "callback_data": "cbcal_0_n"}, | ||
{'text': "2021", "callback_data": "cbcal_0_g_y_2021_1_12"}, | ||
{'text': "×", "callback_data": "cbcal_0_n"}] | ||
), | ||
( | ||
MONTH, date(2021, 1, 12), relativedelta(months=12), date(2021, 1, 1), date(2022, 1, 1), date(2021, 1, 1), | ||
date(2021, 12, 1), | ||
[{'text': "×", "callback_data": "cbcal_0_n"}, | ||
{'text': "2021", "callback_data": "cbcal_0_g_y_2021_1_12"}, | ||
{'text': ">>", "callback_data": "cbcal_0_g_m_2022_1_1"}] | ||
), | ||
( | ||
YEAR, date(2021, 5, 12), relativedelta(years=4), date(2018, 5, 12), date(2023, 5, 12), date(2019, 5, 12), | ||
date(2019, 5, 12), | ||
[{'text': "<<", "callback_data": "cbcal_0_g_y_2017_5_12"}, | ||
{'text': " ", "callback_data": "cbcal_0_n"}, | ||
{'text': ">>", "callback_data": "cbcal_0_g_y_2025_5_12"}] | ||
) | ||
]) | ||
def test__build_nav_buttons(step, start, diff, mind, maxd, min_button_date, max_button_date, result_buttons): | ||
calendar = DetailedTelegramCalendar(current_date=start, min_date=mind, max_date=maxd) | ||
buttons = calendar._build_nav_buttons(step, diff, min_button_date, max_button_date) | ||
|
||
result = True | ||
print(buttons[0]) | ||
for i, button in enumerate(buttons[0]): | ||
if button['text'] != result_buttons[i]['text'] or button['callback_data'].startswith(result_buttons[i]['text']): | ||
result = False | ||
|
||
assert result |