Browse Source

tests: replace use of call_args.args/kwargs to restore compatibility with python<3.8

Fabian Peter Hammerle 3 years ago
parent
commit
b9cfdb6687
3 changed files with 12 additions and 9 deletions
  1. 1 0
      CHANGELOG.md
  2. 3 3
      setup.py
  3. 8 6
      tests/test_run.py

+ 1 - 0
CHANGELOG.md

@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Fixed
 - fixed return type hints in class `_Persistence`
 - added assertions fixing `mypy` errors
+- tests: fixed compatibility with python3.5-3.7
 
 ## [0.1.0] - 2021-02-14
 ### Added

+ 3 - 3
setup.py

@@ -52,8 +52,8 @@ setuptools.setup(
         # "Programming Language :: Python :: 3.5",
         # "Programming Language :: Python :: 3.6",
         # "Programming Language :: Python :: 3.7",
-        # "Programming Language :: Python :: 3.8",
-        # "Programming Language :: Python :: 3.9",
+        "Programming Language :: Python :: 3.8",
+        "Programming Language :: Python :: 3.9",
     ],
     entry_points={
         "console_scripts": [
@@ -66,5 +66,5 @@ setuptools.setup(
         "python-telegram-bot >= 13.0"
     ],
     setup_requires=["setuptools_scm"],
-    # tests_require=["pytest"], TODO
+    tests_require=["pytest"],
 )

+ 8 - 6
tests/test_run.py

@@ -29,16 +29,18 @@ def test__run(tmp_path, wikimap_export_path):
             wikimap_export_path=wikimap_export_path,
         )
     assert updater_mock.call_count == 1
-    assert not updater_mock.call_args.args
-    assert set(updater_mock.call_args.kwargs.keys()) == {
+    # > Changed in version 3.8: Added args and kwargs properties.
+    # https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.call_args_list
+    init_args, init_kwargs = updater_mock.call_args
+    assert not init_args
+    assert set(init_kwargs.keys()) == {
         "persistence",
         "token",
         "use_context",
     }
-    assert updater_mock.call_args.kwargs["token"] == "secret"
-    assert updater_mock.call_args.kwargs["use_context"] is True
-    persistence = updater_mock.call_args.kwargs["persistence"]
-    photos = persistence.get_bot_data()["photos"]
+    assert init_kwargs["token"] == "secret"
+    assert init_kwargs["use_context"] is True
+    photos = init_kwargs["persistence"].get_bot_data()["photos"]
     assert len(photos) == 25
     assert (
         photos[1].photo_url