Skip to content

Commit

Permalink
Codestyle was fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
quasiyoke committed Jan 6, 2018
1 parent 5ce9217 commit 9bd5c84
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 29 deletions.
4 changes: 2 additions & 2 deletions telepot_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from .aio import *
from .helpers import *
from .aio import create_open, DelegatorBot
from .helpers import assert_sent_message, finalize, receive_message
15 changes: 9 additions & 6 deletions telepot_testing/aio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import asyncio
from asyncio import Queue
import logging
from unittest.mock import Mock
from asyncio import Queue
from asynctest.mock import CoroutineMock
from telepot_testing.helpers import get_update, send_update, UPDATES_TIMEOUT
from telepot.helper import Microphone

LOGGER = logging.getLogger('telepot_testing.aio')

def create_open(cls, *args, **kwargs):
def make_coroutine_instance(seed_tuple):
def get_future(seed_tuple):
"""Args:
seed_tuple: bot, update, seed
seed_tuple (tuple): bot, update, seed
Returns:
Future: Future awaiting for received updates.
"""
async def wait_loop():
await handler.on_message(update)
Expand All @@ -36,7 +39,7 @@ async def wait_loop():
unused_bot, update, unused_seed = seed_tuple
return wait_loop()

return make_coroutine_instance
return get_future

class Listener:
def __init__(self, microphone, queue):
Expand Down Expand Up @@ -109,7 +112,7 @@ async def message_loop(self):
update = await get_update()
await self.handle(update)

# pylint: disable=invalid-name,too-many-arguments
# pylint: disable=invalid-name,too-many-arguments,unused-argument
async def sendMessage(
self,
chat_id,
Expand All @@ -118,7 +121,7 @@ async def sendMessage(
disable_web_page_preview=None,
parse_mode=None,
reply_markup=None,
):
):
update = {
'chat': {
'id': chat_id,
Expand Down
10 changes: 7 additions & 3 deletions telepot_testing/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging

LOGGER = logging.getLogger('telepot_testing')
# pylint: disable=invalid-name
message_id_counter = 0
SENT_FUTURES = []
UPDATES_FUTURES = []
Expand Down Expand Up @@ -83,21 +84,24 @@ async def get_update():
try:
await asyncio.wait_for(future, timeout=UPDATES_TIMEOUT)
except asyncio.TimeoutError:
UPDATES_FUTURES.remove(future)
return None
except asyncio.CancelledError:
LOGGER.debug('Cancelled')
raise
# pylint: disable=bare-except
except:
UPDATES_FUTURES.remove(future)
LOGGER.exception('Exception during waiting for updates')
raise
else:
UPDATES_FUTURES.remove(future)
return future.result()
finally:
UPDATES_FUTURES.remove(future)

def receive_update(update):
get_first_not_done_future(UPDATES_FUTURES).set_result(update)

def receive_message(chat_id, text):
# pylint: disable=global-statement
global message_id_counter
message_id_counter += 1
receive_update({
Expand Down
9 changes: 2 additions & 7 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import asyncio
import datetime
from unittest.mock import create_autospec
from functools import wraps
import asynctest
from asynctest.mock import call, patch, Mock, CoroutineMock
import logging
from asynctest.mock import patch, Mock
from peewee import SqliteDatabase
from telepot.exception import TelegramError
from randtalkbot import stats, stranger, talk
from randtalkbot.bot import Bot
from randtalkbot.stats import Stats
Expand All @@ -20,8 +17,6 @@
from randtalkbot.talk import Talk
from randtalkbot.stats_service import StatsService
import telepot_testing
from telepot import helper as telepot_helpers
import logging
from telepot_testing import finalize as finalize_telepot

def assert_db(db_dict):
Expand Down
5 changes: 0 additions & 5 deletions tests/test_chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import asyncio
import datetime
from unittest.mock import create_autospec
import asynctest
from asynctest.mock import call, patch, Mock, CoroutineMock
from peewee import SqliteDatabase
from telepot.exception import TelegramError
from telepot_testing import assert_sent_message, receive_message
from .helpers import assert_db, finalize, run, patch_telepot

Expand Down
7 changes: 1 addition & 6 deletions tests/test_invites.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import asyncio
import datetime
import logging
from unittest.mock import create_autospec
import asynctest
from asynctest.mock import call, patch, Mock, CoroutineMock
from peewee import SqliteDatabase
from telepot.exception import TelegramError
from telepot_testing import assert_sent_message, receive_message
from .helpers import assert_db, finalize, run, patch_telepot
from randtalkbot.stranger import Stranger
from .helpers import assert_db, finalize, run, patch_telepot

LOGGER = logging.getLogger('test_invites')
STRANGER1_2 = {
Expand Down

0 comments on commit 9bd5c84

Please sign in to comment.