Skip to content

Commit

Permalink
added isort, black and flake8 to style checking
Browse files Browse the repository at this point in the history
  • Loading branch information
erayerdin committed Apr 16, 2020
1 parent 3d9bd67 commit 05ab5f4
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 156 deletions.
5 changes: 5 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[settings]
known_third_party = click,colorful,pytest,requests,requests_mock,setuptools,yaspin
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ jobs:
python: '3.7'
install:
- pip install -r requirements.txt
# ref: https://stackoverflow.com/a/54053100/2926992
- cat dev.requirements.txt | sed -e '/^\s*#.*$/d' -e '/^\s*$/d' | xargs -n 1 pip install || true
script:
- black setup.py tests/ tgcli/ -l 79
- black setup.py tests/ tgcli/
- flake8 setup.py tests/ tgcli/
- isort -c
- stage: Testing
python: '3.5'
install:
Expand Down
9 changes: 5 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"python.linting.enabled": true,
"python.linting.pep8Enabled": false,
"python.linting.pylintEnabled": true,
"python.linting.pycodestyleEnabled": false,
"python.linting.pylintEnabled": false,
"files.exclude": {
"**/.git": true,
"**/.svn": true,
Expand All @@ -15,5 +15,6 @@
".pytest_cache": true
},
"explorerExclude.backup": null,
"python.pythonPath": ".venv/bin/python3.7"
}
"python.pythonPath": ".venv/bin/python",
"python.linting.flake8Enabled": true
}
17 changes: 4 additions & 13 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import typing

import pytest
import requests
import requests_mock

import tgcli.request.bot
Expand Down Expand Up @@ -61,9 +60,7 @@ def factory(method_name: str) -> tgcli.request.bot.BotRequest:


@pytest.fixture
def bot_authentication_request(
bot_session
) -> tgcli.request.bot.AuthenticationRequest:
def bot_authentication_request(bot_session) -> tgcli.request.bot.AuthenticationRequest:
"""
Returns a bot authentication request.
Expand All @@ -79,9 +76,7 @@ def bot_authentication_request(


@pytest.fixture
def bot_send_message_request(
bot_session
) -> tgcli.request.bot.SendMessageRequest:
def bot_send_message_request(bot_session) -> tgcli.request.bot.SendMessageRequest:
"""
Returns a bot send message request.
Expand Down Expand Up @@ -114,9 +109,7 @@ def bot_send_poll_request(bot_session) -> tgcli.request.bot.SendPollRequest:
question = "Foo?"
options = ("Bar", "Baz")
"""
return tgcli.request.bot.SendPollRequest(
bot_session, 1, "Foo?", ("Bar", "Baz")
)
return tgcli.request.bot.SendPollRequest(bot_session, 1, "Foo?", ("Bar", "Baz"))


@pytest.fixture
Expand Down Expand Up @@ -345,8 +338,6 @@ def invoke_message_factory():
"""

def factory(klass: typing.ClassVar, method: typing.Callable):
return "A message invoked by `{}::{}`.".format(
klass.__name__, method.__name__
)
return "A message invoked by `{}::{}`.".format(klass.__name__, method.__name__)

return factory
60 changes: 19 additions & 41 deletions tests/test_cli/test_bot_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@
SKIPIF_BOT_TOKEN_NOT_EXISTS,
SKIPIF_HAS_NOT_CONNECTED,
)
from tgcli.cli.bot.send import MESSAGE_FORMATS


class TestMessage:
@SKIPIF_HAS_NOT_CONNECTED
@SKIPIF_BOT_TOKEN_NOT_EXISTS
@SKIPIF_BOT_RECEIVER_NOT_EXISTS
def test_html(
self,
cli_runner: CliRunner,
cli,
receiver_id: str,
invoke_message_factory,
self, cli_runner: CliRunner, cli, receiver_id: str, invoke_message_factory,
):
args = (
"bot",
Expand All @@ -36,11 +31,7 @@ def test_html(
@SKIPIF_BOT_TOKEN_NOT_EXISTS
@SKIPIF_BOT_RECEIVER_NOT_EXISTS
def test_markdown(
self,
cli_runner: CliRunner,
cli,
receiver_id: str,
invoke_message_factory,
self, cli_runner: CliRunner, cli, receiver_id: str, invoke_message_factory,
):
args = (
"bot",
Expand Down Expand Up @@ -94,11 +85,7 @@ def test_thumbnail(self, cli_runner: CliRunner, cli, receiver_id: str):
@SKIPIF_BOT_TOKEN_NOT_EXISTS
@SKIPIF_BOT_RECEIVER_NOT_EXISTS
def test_message(
self,
cli_runner: CliRunner,
cli,
receiver_id: str,
invoke_message_factory,
self, cli_runner: CliRunner, cli, receiver_id: str, invoke_message_factory,
):
args = (
"bot",
Expand Down Expand Up @@ -134,11 +121,7 @@ def test_vanilla(self, cli_runner: CliRunner, cli, receiver_id: str):
@SKIPIF_BOT_TOKEN_NOT_EXISTS
@SKIPIF_BOT_RECEIVER_NOT_EXISTS
def test_message(
self,
cli_runner: CliRunner,
cli,
receiver_id: str,
invoke_message_factory,
self, cli_runner: CliRunner, cli, receiver_id: str, invoke_message_factory,
):
args = (
"bot",
Expand Down Expand Up @@ -193,11 +176,7 @@ def test_aspect_ratio(self, cli_runner: CliRunner, cli, receiver_id: str):
@SKIPIF_BOT_TOKEN_NOT_EXISTS
@SKIPIF_BOT_RECEIVER_NOT_EXISTS
def test_message(
self,
cli_runner: CliRunner,
cli,
receiver_id: str,
invoke_message_factory,
self, cli_runner: CliRunner, cli, receiver_id: str, invoke_message_factory,
):
args = (
"bot",
Expand All @@ -216,11 +195,7 @@ def test_message(
@SKIPIF_BOT_TOKEN_NOT_EXISTS
@SKIPIF_BOT_RECEIVER_NOT_EXISTS
def test_message_aspect_ratio(
self,
cli_runner: CliRunner,
cli,
receiver_id: str,
invoke_message_factory,
self, cli_runner: CliRunner, cli, receiver_id: str, invoke_message_factory,
):
args = (
"bot",
Expand All @@ -230,9 +205,7 @@ def test_message_aspect_ratio(
"video",
"tests/resources/placeholder.mkv",
"-m",
invoke_message_factory(
self.__class__, self.test_message_aspect_ratio
),
invoke_message_factory(self.__class__, self.test_message_aspect_ratio),
"-h",
"16",
"-v",
Expand Down Expand Up @@ -274,7 +247,7 @@ def test_performer(self, cli_runner: CliRunner, cli, receiver_id: str):
)
result = cli_runner.invoke(cli, args)
assert result.exit_code == 0

@SKIPIF_HAS_NOT_CONNECTED
@SKIPIF_BOT_TOKEN_NOT_EXISTS
@SKIPIF_BOT_RECEIVER_NOT_EXISTS
Expand All @@ -287,15 +260,17 @@ def test_title(self, cli_runner: CliRunner, cli, receiver_id: str):
"audio",
"tests/resources/placeholder.wav",
"--title",
"White Noise"
"White Noise",
)
result = cli_runner.invoke(cli, args)
assert result.exit_code == 0

@SKIPIF_HAS_NOT_CONNECTED
@SKIPIF_BOT_TOKEN_NOT_EXISTS
@SKIPIF_BOT_RECEIVER_NOT_EXISTS
def test_message(self, cli_runner: CliRunner, cli, receiver_id: str, invoke_message_factory):
def test_message(
self, cli_runner: CliRunner, cli, receiver_id: str, invoke_message_factory
):
args = (
"bot",
"send",
Expand All @@ -304,11 +279,12 @@ def test_message(self, cli_runner: CliRunner, cli, receiver_id: str, invoke_mess
"audio",
"tests/resources/placeholder.wav",
"-m",
invoke_message_factory(self.__class__, self.test_message)
invoke_message_factory(self.__class__, self.test_message),
)
result = cli_runner.invoke(cli, args)
assert result.exit_code == 0


# todo polls cannot be tested because it cannot be sent to private messages


Expand All @@ -323,8 +299,10 @@ def test_vanilla(self, cli_runner: CliRunner, cli, receiver_id: str):
"-r",
receiver_id,
"location",
"-x", "38.41273",
"-y", "27.13838",
"-x",
"38.41273",
"-y",
"27.13838",
)
result = cli_runner.invoke(cli, args)
assert result.exit_code == 0
assert result.exit_code == 0

0 comments on commit 05ab5f4

Please sign in to comment.