Skip to content

Commit 5d7c6ad

Browse files
jsmnbomtsnoam
authored andcommitted
Switch to pytest + required fixes to code (python-telegram-bot#788)
Required fixes: - CallbackQuery is now comparable. - Message.effective_attachment, Message.photo, Message.new_chat_members, Message.new_chat_photo & Game.text_entitties semantic fixes - when they are not defined, return an empty list. - Docstring fix to Update class.
1 parent 915cd64 commit 5d7c6ad

File tree

111 files changed

+8663
-7670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+8663
-7670
lines changed

.coveragerc

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/CONTRIBUTING.rst

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
How To Contribute
2-
===================
2+
=================
33

44
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.
55

66
Setting things up
7-
-------------------
7+
-----------------
88

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

@@ -35,7 +35,7 @@ Setting things up
3535
$ pre-commit install
3636
3737
Finding something to do
38-
###################
38+
#######################
3939

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

@@ -44,7 +44,7 @@ If you have an idea for something to do, first check if it's already been filed
4444
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.
4545

4646
Instructions for making a code change
47-
####################
47+
#####################################
4848

4949
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``.
5050

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

9090
.. code-block::
9191
92-
$ nosetests -v
92+
$ pytest -v
9393
9494
- To actually make the commit (this will trigger tests for yapf, lint and pep8 automatically):
9595

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

130130
.. code-block:: bash
131131
132-
$ git checkout your-branch-name
133-
$ git fetch upstream
134-
$ git merge upstream/master
135-
$ ...[fix the conflicts]...
136-
$ ...[make sure the tests pass before committing]...
137-
$ git commit -a
138-
$ git push origin your-branch-name
132+
$ git checkout your-branch-name
133+
$ git fetch upstream
134+
$ git merge upstream/master
135+
$ ...[fix the conflicts]...
136+
$ ...[make sure the tests pass before committing]...
137+
$ git commit -a
138+
$ git push origin your-branch-name
139139
140140
- 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:
141141

142142
.. code-block:: bash
143143
144-
$ git submodule update --init --recursive
144+
$ git submodule update --init --recursive
145145
146146
- At the end, the reviewer will merge the pull request.
147147

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

157157
Style commandments
158-
---------------------
158+
------------------
159159

160160
Specific commandments
161161
#####################
162162

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

165-
AssertEqual argument order
166-
######################
165+
Assert comparison order
166+
#######################
167167

168-
- assertEqual method's arguments should be in ('actual', 'expected') order.
168+
- assert statements should compare in **actual** == **expected** order.
169+
For example (assuming ``test_call`` is the thing being tested):
170+
171+
.. code-block:: python
172+
173+
# GOOD
174+
assert test_call() == 5
175+
176+
# BAD
177+
assert 5 == test_call()
169178
170179
Properly calling callables
171-
#######################
180+
##########################
172181

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

188197
Properly defining optional arguments
189-
########################
198+
####################################
190199

191200
It's always good to not initialize optional arguments at class creation,
192201
instead use ``**kwargs`` to get them. It's well known Telegram API can

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
files: ^telegram/.*\.py$
1818
args:
1919
- --errors-only
20-
- --disable=no-name-in-module,import-error
20+
- --disable=import-error

.travis.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@ branches:
1818
cache:
1919
directories:
2020
- $HOME/.cache/pip
21+
- $HOME/.pre-commit
2122
before_cache:
2223
- rm -f $HOME/.cache/pip/log/debug.log
24+
- rm -f $HOME/.pre-commit/pre-commit.log
2325

2426
install:
25-
- pip install coveralls
27+
- pip install coveralls pytest-cov
2628
- pip install -U wheel
27-
- pip install -r requirements.txt
28-
- pip install -r requirements-dev.txt
29+
- pip install -U -r requirements.txt
30+
- pip install -U -r requirements-dev.txt
2931
- if [[ $TRAVIS_PYTHON_VERSION != 'pypy'* ]]; then pip install ujson; fi
3032

3133
script:
32-
- python travis.py
34+
- pytest -v --cov=telegram
3335

3436
after_success:
3537
coveralls

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.PHONY: clean pep257 pep8 yapf lint test install
33

44
PYLINT := pylint
5-
NOSETESTS := nosetests
5+
PYTEST := pytest
66
PEP257 := pep257
77
PEP8 := flake8
88
YAPF := yapf
@@ -29,7 +29,7 @@ lint:
2929
$(PYLINT) -E telegram --disable=no-name-in-module,import-error
3030

3131
test:
32-
$(NOSETESTS) -v
32+
$(PYTEST) -v
3333

3434
install:
3535
$(PIP) install -r requirements.txt -r requirements-dev.txt
@@ -41,11 +41,11 @@ help:
4141
@echo "- pep8 Check style with flake8"
4242
@echo "- lint Check style with pylint"
4343
@echo "- yapf Check style with yapf"
44-
@echo "- test Run tests"
44+
@echo "- test Run tests using pytest"
4545
@echo
4646
@echo "Available variables:"
4747
@echo "- PYLINT default: $(PYLINT)"
48-
@echo "- NOSETESTS default: $(NOSETESTS)"
48+
@echo "- PYTEST default: $(PYTEST)"
4949
@echo "- PEP257 default: $(PEP257)"
5050
@echo "- PEP8 default: $(PEP8)"
5151
@echo "- YAPF default: $(YAPF)"

appveyor.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,4 @@ build: off
2424
cache: C:\Users\appveyor\pip\wheels
2525

2626
test_script:
27-
- "%python%\\Scripts\\nosetests -v --with-flaky --no-flaky-report tests"
28-
29-
after_test:
30-
# This step builds your wheels.
31-
- "%PYTHON%\\python.exe setup.py bdist_wheel"
27+
- "%python%\\Scripts\\pytest -v --cov=telegram"

requirements-dev.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
flake8
2-
nose
32
pep257
43
pylint
54
flaky
65
yapf
76
pre-commit
8-
pre-commit-hooks
97
beautifulsoup4
10-
rednose
8+
pytest
9+
pytest-timeout

setup.cfg

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,19 @@ ignore = W503
1717
based_on_style = google
1818
split_before_logical_operator = True
1919
column_limit = 99
20+
21+
[tool:pytest]
22+
testpaths = tests
23+
addopts = --no-success-flaky-report -rsxX
24+
filterwarnings =
25+
error
26+
ignore::DeprecationWarning
27+
28+
[coverage:run]
29+
branch = False
30+
source = telegram
31+
omit =
32+
tests/
33+
telegram/__main__.py
34+
telegram/vendor/*
35+

telegram/bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ def set_webhook(self,
16511651
url_ = '{0}/setWebhook'.format(self.base_url)
16521652

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

telegram/callbackquery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __init__(self,
9090

9191
self.bot = bot
9292

93-
self._id_attrs = ('id',)
93+
self._id_attrs = (self.id,)
9494

9595
@classmethod
9696
def de_json(cls, data, bot):

0 commit comments

Comments
 (0)