Skip to content

Working on pytest #757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 191 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
191 commits
Select commit Hold shift + click to select a range
15edf67
need travis test
Eldinnie Jul 29, 2017
29f6c2c
sdf
Eldinnie Jul 29, 2017
d8a5943
some tests
Eldinnie Jul 29, 2017
2b2c734
travis
Eldinnie Jul 29, 2017
efe0c90
Add coverage and travis folding
jsmnbom Jul 30, 2017
1c67e36
Add pytest version of test_official
jsmnbom Jul 30, 2017
a56ef94
Small changes
jsmnbom Jul 30, 2017
97b3fd6
Add pytest ini file configuration and close file handle properly
jsmnbom Jul 30, 2017
1983691
making stuff look good :D
Eldinnie Jul 30, 2017
9bd47bc
bash at top
Eldinnie Jul 30, 2017
f73025f
Only ignore resource warning on py3
jsmnbom Jul 30, 2017
35573ee
Split travis folding into plugin
jsmnbom Jul 30, 2017
2438450
test_chat
Eldinnie Jul 30, 2017
4e89dac
Merge remote-tracking branch 'origin/pytest' into pytest
Eldinnie Jul 30, 2017
2bc4143
id instead of _id
Eldinnie Jul 30, 2017
b819072
starting test_chat_member
Eldinnie Jul 30, 2017
0169f57
test_chatmember
Eldinnie Jul 30, 2017
6f11699
tart test_constant
Eldinnie Jul 30, 2017
58de4a4
test_constants
Eldinnie Jul 30, 2017
94b8e61
start test_choseninlineresult
Eldinnie Jul 30, 2017
f161a08
test_choseninlineresult
Eldinnie Jul 30, 2017
34df4f3
start test_contact
Eldinnie Jul 30, 2017
7b05fe2
test_contact
Eldinnie Jul 30, 2017
96e3248
start test_document
Eldinnie Jul 30, 2017
e5b14fc
test_document
Eldinnie Jul 30, 2017
860d372
tweak test_audio
Eldinnie Jul 31, 2017
9c223d9
start test_file
Eldinnie Jul 31, 2017
bb5a1ca
test_file
Eldinnie Jul 31, 2017
0b0f64e
start test_filters
Eldinnie Jul 31, 2017
a246f73
Minor changes
jsmnbom Jul 31, 2017
880bd7b
start forcereply
jsmnbom Jul 31, 2017
851b2d9
ForceReply
jsmnbom Jul 31, 2017
56e7e51
Add a migration helper
jsmnbom Jul 31, 2017
fedb99f
start game
jsmnbom Jul 31, 2017
db89c06
Game
jsmnbom Jul 31, 2017
bb271e3
Make migration tool smarter and move it to root
jsmnbom Jul 31, 2017
4a76fc5
test_helpers
jsmnbom Jul 31, 2017
c61d3bc
start inlinekeyboardbutton
jsmnbom Jul 31, 2017
9ec0c14
inlinekeyboardbutton
jsmnbom Jul 31, 2017
02c7dc3
inlinekeyboardmarkup
jsmnbom Jul 31, 2017
31bae4a
start inlinequery
jsmnbom Jul 31, 2017
e0b058e
inlinequery
jsmnbom Jul 31, 2017
f9a7457
Use proper snake_case and teach migrate tool to automatically convert
jsmnbom Jul 31, 2017
309859c
Improve travis folding so we can turn verbosity back on
jsmnbom Jul 31, 2017
7b61599
Lazy fix for unicode error
jsmnbom Jul 31, 2017
7a29ee6
More travis prettification
jsmnbom Jul 31, 2017
c029e85
Mark contact sending as expected to fail
jsmnbom Jul 31, 2017
7828f4c
Use to_timstamp helper so tests work on py <3.3
jsmnbom Jul 31, 2017
2b7d044
Add pre-commit-hooks to test
jsmnbom Jul 31, 2017
424a2db
Add build test
jsmnbom Jul 31, 2017
0621b37
test_filters
Eldinnie Jul 31, 2017
319f679
fix test_file
Eldinnie Jul 31, 2017
87789a8
Adjustments
Eldinnie Jul 31, 2017
6264c75
formatting
Eldinnie Jul 31, 2017
2b7d168
less requests is more better
Eldinnie Jul 31, 2017
e78a03f
update migration tool
jsmnbom Aug 1, 2017
cc178eb
start inlinequeryresultarticle
jsmnbom Aug 1, 2017
43fe796
inlinequeryresultarticle
jsmnbom Aug 1, 2017
e04551f
start inlinequeryresult* (non cached)
jsmnbom Aug 1, 2017
2131d73
inlinequeryresult* (non cached)
jsmnbom Aug 1, 2017
8dc7fdc
Unify test names
jsmnbom Aug 1, 2017
b818b34
Start inlinequeryresultcached*
jsmnbom Aug 1, 2017
71876c1
inlinequeryresultcached*
jsmnbom Aug 1, 2017
4461e43
inlinequeryresultgame
jsmnbom Aug 1, 2017
6efc545
start jobqueue
jsmnbom Aug 1, 2017
8d2dcdb
JobQueue
jsmnbom Aug 1, 2017
4b27da2
Start input*messagecontent
jsmnbom Aug 1, 2017
a338178
input*messagecontent
jsmnbom Aug 1, 2017
0a2b4e2
start invoice
jsmnbom Aug 1, 2017
b5f0e34
invoice
jsmnbom Aug 1, 2017
e461dbc
start conversationhandler
jsmnbom Aug 1, 2017
160a515
unifying
Eldinnie Aug 1, 2017
4c90140
moved provider_token to session scope in conftest
Eldinnie Aug 1, 2017
33456a0
conversationhandler
jsmnbom Aug 1, 2017
53570e3
small fixes
jsmnbom Aug 1, 2017
090a998
keyboardbutton + labeledprice
jsmnbom Aug 2, 2017
85c54fd
start callbackquery
Eldinnie Aug 2, 2017
fd1f5c4
Remove most sleep from conversationhandler tests
jsmnbom Aug 2, 2017
88a5a42
test_callbackquery
Eldinnie Aug 2, 2017
864f1be
oops
Eldinnie Aug 2, 2017
72d27d0
Fixed conversationhandler test
jsmnbom Aug 2, 2017
387ba9d
Speed up jobqueue tests
jsmnbom Aug 2, 2017
0379fbe
Fix audio tests
jsmnbom Aug 2, 2017
be4c3c7
Fix jobqueue speed up
jsmnbom Aug 2, 2017
be1ec0d
Update requirements and travis config
jsmnbom Aug 2, 2017
814dd2d
test_location
Eldinnie Aug 2, 2017
c4f3911
start test_message
Eldinnie Aug 2, 2017
9554d9b
test_message
Eldinnie Aug 3, 2017
bfbe563
test_messageenetity
Eldinnie Aug 3, 2017
bf63abb
conversationhandler
Eldinnie Aug 3, 2017
da99ad0
Small fixes
jsmnbom Aug 3, 2017
bf132b9
Start messagequeue
jsmnbom Aug 3, 2017
08629c9
messagequeue
jsmnbom Aug 3, 2017
5d489b3
start orderinfo
jsmnbom Aug 3, 2017
9225204
orderinfo
jsmnbom Aug 3, 2017
dd3af85
parsemode
jsmnbom Aug 3, 2017
d70cf46
start photo
jsmnbom Aug 3, 2017
e4c98bb
fix test_message
Eldinnie Aug 3, 2017
747c114
start commandhandler
Eldinnie Aug 3, 2017
19ffc49
photo
jsmnbom Aug 3, 2017
6187538
commandhandler
Eldinnie Aug 3, 2017
c3b25bc
start callbackqueryhandler
Eldinnie Aug 3, 2017
f8e72a4
callbackqueryhandler
Eldinnie Aug 3, 2017
4a85835
tiny change to commandhandlertest
jsmnbom Aug 3, 2017
7fea9a7
start shipping and precheckout queries
jsmnbom Aug 3, 2017
7198b03
shipping and precheckout queries
jsmnbom Aug 3, 2017
e96ce4b
Move test ini from pytest.ini to setup.cfg
jsmnbom Aug 3, 2017
2c4b882
start replykeyboardmarkup
jsmnbom Aug 3, 2017
f24d8ce
replykeyboardmarkup
jsmnbom Aug 3, 2017
e022e19
replykeyboardremove
jsmnbom Aug 3, 2017
47f8775
shippingaddress
jsmnbom Aug 3, 2017
6ff1aab
start shippingoption
jsmnbom Aug 3, 2017
5d249e8
shippingoption
jsmnbom Aug 3, 2017
0bff57d
sticker
jsmnbom Aug 3, 2017
d6e32de
successfulpayment
jsmnbom Aug 3, 2017
87389fa
start update
jsmnbom Aug 3, 2017
e2daea5
Update
jsmnbom Aug 3, 2017
d5be8d8
Bot
jsmnbom Aug 3, 2017
6d47d9d
TestJobQueue.test_run_repeating_first should now never fail :D
jsmnbom Aug 3, 2017
ae0cbad
Fix replykeyboardremove test
jsmnbom Aug 3, 2017
43f49cb
Fix bot tests
jsmnbom Aug 3, 2017
9e8c002
Fix bot tests more?
jsmnbom Aug 3, 2017
d3d44b6
start venue, video and videonote
jsmnbom Aug 3, 2017
66cd550
venue, video and videonote
jsmnbom Aug 3, 2017
30aad6b
voice
jsmnbom Aug 3, 2017
104315d
fixes
jsmnbom Aug 3, 2017
e8f7ae7
Make the bot provider more robust for future
jsmnbom Aug 3, 2017
0cea75b
Dispatcher
jsmnbom Aug 4, 2017
ea06f07
Updater
jsmnbom Aug 4, 2017
19a801a
Fixes
jsmnbom Aug 4, 2017
1727d74
more fixes?
jsmnbom Aug 4, 2017
d04493a
Debugging
jsmnbom Aug 4, 2017
e01633d
More debugging!
jsmnbom Aug 4, 2017
ef7580e
It works now?
jsmnbom Aug 4, 2017
2ca6461
Fix TestUpdater.test_user_signal
jsmnbom Aug 4, 2017
a27313c
More Bot tests
jsmnbom Aug 4, 2017
b19b2ef
StickerSet and Maskposistion tests
jsmnbom Aug 4, 2017
8264849
Add sticker test data file
jsmnbom Aug 5, 2017
69fa530
Give up on sticker tests
jsmnbom Aug 5, 2017
47aada3
test X.answer shortcuts
jsmnbom Aug 5, 2017
d7e7a9b
Fix export link test on py2
jsmnbom Aug 5, 2017
8753df9
small adjustments and fixes
Eldinnie Aug 5, 2017
675fb9c
reformat code
Eldinnie Aug 5, 2017
1e702ae
small changes improving coverage
Eldinnie Aug 5, 2017
6227a6a
correct the markup_as_dat
Eldinnie Aug 6, 2017
eef1ee9
xfail send_contact
Eldinnie Aug 6, 2017
7f91ac9
remove skip_tests from test_bot
Eldinnie Aug 6, 2017
fc13e98
rename handler methods
Eldinnie Aug 6, 2017
87fc980
Improve handlers and ChosenInlineResultHandler
Eldinnie Aug 6, 2017
1e7f3ac
InlineQueryHandler
Eldinnie Aug 6, 2017
37edfdd
start messagehandler
Eldinnie Aug 6, 2017
cbf936c
MessageHandler
Eldinnie Aug 6, 2017
3ea97fd
PreCheckoutQueryHandler
Eldinnie Aug 6, 2017
451d0dc
shippingqueryhandler
Eldinnie Aug 6, 2017
72d0fdb
scope='class'
Eldinnie Aug 6, 2017
ee535de
RegexHandler
Eldinnie Aug 6, 2017
b8fd9bd
fix up
Eldinnie Aug 6, 2017
e09a60c
string*handler
Eldinnie Aug 6, 2017
161a128
final push
Eldinnie Aug 6, 2017
83d68af
xfail on tests relying on #744
Eldinnie Aug 6, 2017
da46b80
xfail webhook tests
Eldinnie Aug 7, 2017
ae073dc
TypeHandler
Eldinnie Aug 7, 2017
7ed23c8
start monkeypatching bot methods
Eldinnie Aug 7, 2017
56b8e4e
Update contributing guide to new asserts
jsmnbom Aug 7, 2017
25af9fb
Merge branch 'master' into pytest-e
jsmnbom Aug 7, 2017
8b08f1e
add text_*_urled tests
Eldinnie Aug 7, 2017
7e5085b
Merge remote-tracking branch 'origin/pytest' into pytest
Eldinnie Aug 7, 2017
5f3fbd7
styling
Eldinnie Aug 7, 2017
5239e5b
DispatcherHandlerContinue/Stop
jsmnbom Aug 7, 2017
afcba19
Move from temp pytests directory to tests
jsmnbom Aug 7, 2017
bf184d4
User
jsmnbom Aug 7, 2017
60f2b87
Forgot import in renaming
jsmnbom Aug 7, 2017
cde963b
Fix callback query _id_attrs so it can be compard
jsmnbom Aug 7, 2017
0e78ca4
Fix for contributing guide
jsmnbom Aug 7, 2017
7bb236e
Whoops
jsmnbom Aug 7, 2017
5e352c9
Fix license notice
jsmnbom Aug 7, 2017
9e2e4b3
Forgot tool:pytests testpaths in move
jsmnbom Aug 7, 2017
d76b1cd
Complete move
jsmnbom Aug 7, 2017
cccffe8
fix kick_chat_member ?
Eldinnie Aug 7, 2017
8812b0f
Move coverage config from coveragerc to setup.cfg
jsmnbom Aug 8, 2017
752e1e7
get_game_high_score test
jsmnbom Aug 8, 2017
fb13e2f
Fix/improve monkeypatched bot tests
jsmnbom Aug 8, 2017
5a59d07
small fix
Eldinnie Aug 8, 2017
2e7c086
Skip send_contact on pypy
jsmnbom Aug 8, 2017
c7d8f06
Cleanup
jsmnbom Aug 8, 2017
1a6a4b9
Update all instances of nose/nosetests to pytest
jsmnbom Aug 8, 2017
e038ac7
Remove individual to_json tests in favour of a single one
jsmnbom Aug 9, 2017
8011722
finishing touches
Eldinnie Aug 11, 2017
e48ed60
correction errors
Eldinnie Aug 11, 2017
52fdddd
effective_attachment test and adjustment
Eldinnie Aug 11, 2017
ac47cf8
Don't test ABC, and test that ujson is at least consistent if anything
jsmnbom Aug 11, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .coveragerc

This file was deleted.

47 changes: 28 additions & 19 deletions .github/CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
How To Contribute
===================
=================

Every open source project lives from the generous help by contributors that sacrifice their time and ``python-telegram-bot`` is no different. To make participation as pleasant as possible, this project adheres to the `Code of Conduct`_ by the Python Software Foundation.

Setting things up
-------------------
-----------------

1. Fork the ``python-telegram-bot`` repository to your GitHub account.

Expand Down Expand Up @@ -35,7 +35,7 @@ Setting things up
$ pre-commit install

Finding something to do
###################
#######################

If you already know what you'd like to work on, you can skip this section.

Expand All @@ -44,7 +44,7 @@ If you have an idea for something to do, first check if it's already been filed
Another great way to start contributing is by writing tests. Tests are really important because they help prevent developers from accidentally breaking existing code, allowing them to build cool things faster. If you're interested in helping out, let the development team know by posting to the `developers' mailing list`_, and we'll help you get started.

Instructions for making a code change
####################
#####################################

The central development branch is ``master``, which should be clean and ready for release at any time. In general, all changes should be done as feature branches based off of ``master``.

Expand Down Expand Up @@ -89,7 +89,7 @@ Here's how to make a one-off code change.

.. code-block::

$ nosetests -v
$ pytest -v

- To actually make the commit (this will trigger tests for yapf, lint and pep8 automatically):

Expand Down Expand Up @@ -129,19 +129,19 @@ Here's how to make a one-off code change.

.. code-block:: bash

$ git checkout your-branch-name
$ git fetch upstream
$ git merge upstream/master
$ ...[fix the conflicts]...
$ ...[make sure the tests pass before committing]...
$ git commit -a
$ git push origin your-branch-name
$ git checkout your-branch-name
$ git fetch upstream
$ git merge upstream/master
$ ...[fix the conflicts]...
$ ...[make sure the tests pass before committing]...
$ git commit -a
$ git push origin your-branch-name

- If after merging you see local modified files in ``telegram/vendor/`` directory, that you didn't actually touch, that means you need to update submodules with this command:

.. code-block:: bash

$ git submodule update --init --recursive
$ git submodule update --init --recursive

- At the end, the reviewer will merge the pull request.

Expand All @@ -155,20 +155,29 @@ Here's how to make a one-off code change.
7. **Celebrate.** Congratulations, you have contributed to ``python-telegram-bot``!

Style commandments
---------------------
------------------

Specific commandments
#####################

- Avoid using "double quotes" where you can reasonably use 'single quotes'.

AssertEqual argument order
######################
Assert comparison order
#######################

- assertEqual method's arguments should be in ('actual', 'expected') order.
- assert statements should compare in **actual** == **expected** order.
For example (assuming ``test_call`` is the thing being tested):

.. code-block:: python

# GOOD
assert test_call() == 5

# BAD
assert 5 == test_call()

Properly calling callables
#######################
##########################

Methods, functions and classes can specify optional parameters (with default
values) using Python's keyword arg syntax. When providing a value to such a
Expand All @@ -186,7 +195,7 @@ This gives us the flexibility to re-order arguments and more importantly
to add new required arguments. It's also more explicit and easier to read.

Properly defining optional arguments
########################
####################################

It's always good to not initialize optional arguments at class creation,
instead use ``**kwargs`` to get them. It's well known Telegram API can
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
files: ^telegram/.*\.py$
args:
- --errors-only
- --disable=no-name-in-module,import-error
- --disable=import-error
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ branches:
cache:
directories:
- $HOME/.cache/pip
- $HOME/.pre-commit
before_cache:
- rm -f $HOME/.cache/pip/log/debug.log
- rm -f $HOME/.pre-commit/pre-commit.log

install:
- pip install coveralls
- pip install coveralls pytest-cov
- pip install -U wheel
- pip install -r requirements.txt
- pip install -r requirements-dev.txt
- pip install -U -r requirements.txt
- pip install -U -r requirements-dev.txt
- if [[ $TRAVIS_PYTHON_VERSION != 'pypy'* ]]; then pip install ujson; fi

script:
- python travis.py
- pytest -v --cov=telegram

after_success:
coveralls
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.PHONY: clean pep257 pep8 yapf lint test install

PYLINT := pylint
NOSETESTS := nosetests
PYTEST := pytest
PEP257 := pep257
PEP8 := flake8
YAPF := yapf
Expand All @@ -29,7 +29,7 @@ lint:
$(PYLINT) -E telegram --disable=no-name-in-module,import-error

test:
$(NOSETESTS) -v
$(PYTEST) -v

install:
$(PIP) install -r requirements.txt -r requirements-dev.txt
Expand All @@ -41,11 +41,11 @@ help:
@echo "- pep8 Check style with flake8"
@echo "- lint Check style with pylint"
@echo "- yapf Check style with yapf"
@echo "- test Run tests"
@echo "- test Run tests using pytest"
@echo
@echo "Available variables:"
@echo "- PYLINT default: $(PYLINT)"
@echo "- NOSETESTS default: $(NOSETESTS)"
@echo "- PYTEST default: $(PYTEST)"
@echo "- PEP257 default: $(PEP257)"
@echo "- PEP8 default: $(PEP8)"
@echo "- YAPF default: $(YAPF)"
Expand Down
6 changes: 1 addition & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,4 @@ build: off
cache: C:\Users\appveyor\pip\wheels

test_script:
- "%python%\\Scripts\\nosetests -v --with-flaky --no-flaky-report tests"

after_test:
# This step builds your wheels.
- "%PYTHON%\\python.exe setup.py bdist_wheel"
- "%python%\\Scripts\\pytest -v --cov=telegram"
109 changes: 109 additions & 0 deletions pytest_migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
"""Helper for migrating to pytests

Run it like::

python pytest_migration.py test_forcereply.py
"""

import re
import sys
from pathlib import Path

header = """#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2017
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/]."""

CLASS = r'class (.*)Test\(BaseTest, unittest.TestCase\):(?:\r?\n)([\s\S]*)if __name__'
JSON_DICT = r'self.json_dict = (\{[\s\S]*\})([\s\S]*?def)'
CLASS_VARS = r' def setUp\(self\):\n([\s\S]*?def)'

if __name__ == '__main__':
original = Path('tests/' + sys.argv[1]).open('r', encoding='UTF-8').read()
new_text = header
new_text += '\nimport json\n\nimport pytest\n\n'

match = re.search(CLASS, original)
if not match:
match = re.search(CLASS[:-11], original)

name = match.group(1)
test_name = 'Test' + name

new_class = 'class {}:\n{}'.format(test_name, match.group(2))

imports = {name}
for find in re.finditer('telegram\.([^().]*)', new_class):
imports.add(find.group(1))
tg_imports = ', '.join(imports)
new_text += 'from telegram import {}{}{}\n\n'.format('(' if len(tg_imports) > 77 else '',
tg_imports,
')' if len(tg_imports) > 77 else '')

new_class = re.sub(r'telegram\.', '', new_class)
new_class = re.sub(r'self\.assertTrue\(isinstance\((.*), (.*)\)\)',
r'assert isinstance(\1, \2)', new_class)
new_class = re.sub(r'self\.assertTrue\(self\.is_json\((.*)\)\)', r'json.loads(\1)', new_class)
new_class = re.sub(r'self\.assertTrue\(self\.is_dict\((.*)\)\)',
r'assert isinstance(\1, dict)', new_class)
new_class = re.sub(r'self\.assert(True|False)\((.*)\)', r'assert \2 is \1', new_class)
new_class = re.sub(r'self\.assertIsNone\((.*)\)', r'assert \1 is None', new_class)
new_class = re.sub(r'self\.assertIsInstance\((.*), (.*)\)',
r'assert isinstance(\1, \2)', new_class)
new_class = re.sub(r'self\.assert(?:Dict)?Equals?\((.*), (.*)\)',
r'assert \1 == \2', new_class)
new_class = re.sub(r'self\.assertNotEquals?\((.*), (.*)\)', r'assert \1 != \2', new_class)
new_class = re.sub(r'self\.assertIs\((.*), (.*)\)', r'assert \1 is \2', new_class)
new_class = re.sub(r'self\.assertIsNot\((.*), (.*)\)', r'assert \1 is not \2', new_class)
new_class = re.sub(r'self\._bot', r'bot', new_class)
new_class = re.sub(r'self\._chat_id,', r'chat_id,', new_class)
new_class = re.sub(r'self\._id', 'self.id', new_class)

new_class = re.sub(r'def test_.*_(de|to)_(json|dict)\(self\):',
r'def test_\1_\2(self):', new_class)

name_lower = name.lower()
proper_name_lower = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
proper_name_lower = re.sub('([a-z0-9])([A-Z])', r'\1_\2', proper_name_lower).lower()
new_class.replace(name_lower, proper_name_lower)

json_dict = re.search(JSON_DICT, new_class)
if json_dict:
new_class = re.sub(JSON_DICT, r'\2', new_class)
new_text += '@pytest.fixture(scope=\'class\')\ndef json_dict():\n return '
new_text += json_dict.group(1).replace('self.', test_name + '.')
new_text += '\n\n'
new_text += '@pytest.fixture(scope=\'class\')\ndef {}():\n'.format(proper_name_lower)
args = []
for line in json_dict.group(1).replace('self.', test_name + '.').split(','):
match = re.search(r'\'(.*)\': (.*?\.[^,\s.]*)', line)
if match:
args.append('{}={}'.format(match.group(1), match.group(2)))
new_text += ' return {}({})\n\n'.format(name, ', '.join(args))

class_vars = re.search(CLASS_VARS, new_class)
if class_vars:
class_vars = class_vars.group(1)
class_vars = class_vars.replace(' ', '')
class_vars = class_vars.replace('self.', '')
class_vars = '\n'.join([' ' + x for x in class_vars.split('\n')])
new_class = re.sub(CLASS_VARS, class_vars, new_class)

new_class = re.sub(r'self.json_dict', r'json_dict', new_class)

new_text += new_class
new_file = Path('pytests/' + sys.argv[1]).open('w', encoding='UTF-8').write(new_text)
5 changes: 2 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
flake8
nose
pep257
pylint
flaky
yapf
pre-commit
pre-commit-hooks
beautifulsoup4
rednose
pytest
pytest-timeout
16 changes: 16 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,19 @@ ignore = W503
based_on_style = google
split_before_logical_operator = True
column_limit = 99

[tool:pytest]
testpaths = tests
addopts = --no-success-flaky-report -rsxX
filterwarnings =
error
ignore::DeprecationWarning

[coverage:run]
branch = True
source = telegram
omit =
tests/
telegram/__main__.py
telegram/vendor/*

2 changes: 1 addition & 1 deletion telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ def set_webhook(self,
url_ = '{0}/setWebhook'.format(self.base_url)

# Backwards-compatibility: 'url' used to be named 'webhook_url'
if 'webhook_url' in kwargs:
if 'webhook_url' in kwargs: # pragma: no cover
warnings.warn("The 'webhook_url' parameter has been renamed to 'url' in accordance "
"with the API")

Expand Down
2 changes: 1 addition & 1 deletion telegram/callbackquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self,

self.bot = bot

self._id_attrs = ('id',)
self._id_attrs = (self.id,)

@classmethod
def de_json(cls, data, bot):
Expand Down
6 changes: 0 additions & 6 deletions telegram/ext/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,6 @@ def __init__(self, bot, update_queue, workers=4, exception_event=None, job_queue
else:
self._set_singleton(None)

@classmethod
def _reset_singleton(cls):
# NOTE: This method was added mainly for test_updater benefit and specifically pypy. Never
# call it in production code.
cls.__singleton_semaphore.release()

def _init_async_threads(self, base_name, workers):
base_name = '{}_'.format(base_name) if base_name else ''

Expand Down
2 changes: 1 addition & 1 deletion telegram/games/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self,
self.description = description
self.photo = photo
self.text = text
self.text_entities = text_entities
self.text_entities = text_entities or list()
self.animation = animation

@classmethod
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy