:obj:`bool`: The boolean returned represents whether our parameter's requirement (optional or required) is the same as Telegram's or not. """ is_ours_required = param.default is inspect.Parameter.empty telegram_requires = is_parameter_required_by_tg(param_desc[2]) # Handle cases where we provide convenience intentionally- if param.name in ignored_param_requirements.get(method_or_obj_name, {}): return True return telegram_requires is is_ours_required def check_defaults_type(ptb_param: inspect.Parameter) -> bool: return True if DefaultValue.get_value(ptb_param.default) is None else False to_run = env_var_2_bool(os.getenv("TEST_OFFICIAL")) argvalues = [] names = [] if to_run: argvalues = [] names = [] request = httpx.get("https://core.telegram.org/bots/api") soup = BeautifulSoup(request.text, "html.parser") for thing in soup.select("h4 > a.anchor"): # Methods and types don't have spaces in them, luckily all other sections of the docs do # TODO: don't depend on that if "-" not in thing["name"]: h4 = thing.parent
RELATIVE_TIME_SPECS = DELTA_TIME_SPECS + TIME_OF_DAY_TIME_SPECS TIME_SPECS = ABSOLUTE_TIME_SPECS + RELATIVE_TIME_SPECS """ This part is here for ptb-raw, where we don't have pytz (unless the user installs it) Because imports in pytest are intricate, we just run pytest -k test_helpers.py with the TEST_NO_PYTZ environment variable set in addition to the regular test suite. Because actually uninstalling pytz would lead to errors in the test suite we just mock the import to raise the expected exception. Note that a fixture that just does this for every test that needs it is a nice idea, but for some reason makes test_updater.py hang indefinitely on GitHub Actions (at least when Hinrich tried that) """ TEST_NO_PYTZ = env_var_2_bool(os.getenv('TEST_NO_PYTZ', False)) if TEST_NO_PYTZ: orig_import = __import__ def import_mock(module_name, *args, **kwargs): if module_name == 'pytz': raise ModuleNotFoundError('We are testing without pytz here') return orig_import(module_name, *args, **kwargs) with mock.patch('builtins.__import__', side_effect=import_mock): reload(helpers) class TestHelpers: def test_helpers_utc(self):
just mock the import to raise the expected exception. Note that a fixture that just does this for every test that needs it is a nice idea, but for some reason makes test_updater.py hang indefinitely on GitHub Actions (at least when Hinrich tried that) """ import os from importlib import reload from unittest import mock import pytest from telegram import bot from telegram.passport import credentials from tests.conftest import env_var_2_bool TEST_NO_PASSPORT = env_var_2_bool(os.getenv('TEST_NO_PASSPORT', False)) if TEST_NO_PASSPORT: orig_import = __import__ def import_mock(module_name, *args, **kwargs): if module_name.startswith('cryptography'): raise ModuleNotFoundError('We are testing without cryptography here') return orig_import(module_name, *args, **kwargs) with mock.patch('builtins.__import__', side_effect=import_mock): reload(bot) reload(credentials) class TestNoPassport:
assert (sig.parameters.keys() ^ checked) - ignored == set() argvalues = [] names = [] http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where()) request = http.request('GET', 'https://core.telegram.org/bots/api') soup = BeautifulSoup(request.data.decode('utf-8'), 'html.parser') for thing in soup.select('h4 > a.anchor'): # Methods and types don't have spaces in them, luckily all other sections of the docs do # TODO: don't depend on that if '-' not in thing['name']: h4 = thing.parent # Is it a method if h4.text[0].lower() == h4.text[0]: argvalues.append((check_method, h4)) names.append(h4.text) elif h4.text not in IGNORED_OBJECTS: # Or a type/object argvalues.append((check_object, h4)) names.append(h4.text) @pytest.mark.parametrize(('method', 'data'), argvalues=argvalues, ids=names) @pytest.mark.skipif( not env_var_2_bool(os.getenv('TEST_OFFICIAL')), reason='test_official is not enabled' ) def test_official(method, data): method(data)
just mock the import to raise the expected exception. Note that a fixture that just does this for every test that needs it is a nice idea, but for some reason makes test_updater.py hang indefinitely on GitHub Actions (at least when Hinrich tried that) """ import os from importlib import reload from unittest import mock import pytest from telegram import _bot as bot from telegram._passport import credentials as credentials from tests.conftest import env_var_2_bool TEST_NO_PASSPORT = env_var_2_bool(os.getenv("TEST_NO_PASSPORT", False)) if TEST_NO_PASSPORT: orig_import = __import__ def import_mock(module_name, *args, **kwargs): if module_name.startswith("cryptography"): raise ModuleNotFoundError( "We are testing without cryptography here") return orig_import(module_name, *args, **kwargs) with mock.patch("builtins.__import__", side_effect=import_mock): reload(bot) reload(credentials)
# # 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/]. import os import pytest from tests.conftest import env_var_2_bool @pytest.mark.skipif(not env_var_2_bool(os.getenv('TEST_BUILD', False)), reason='TEST_BUILD not enabled') def test_build(): assert os.system('python setup.py bdist_dumb') == 0 # pragma: no cover @pytest.mark.skipif(not env_var_2_bool(os.getenv('TEST_BUILD', False)), reason='TEST_BUILD not enabled') def test_build_raw(): assert os.system('python setup-raw.py bdist_dumb') == 0 # pragma: no cover
RELATIVE_TIME_SPECS = DELTA_TIME_SPECS + TIME_OF_DAY_TIME_SPECS TIME_SPECS = ABSOLUTE_TIME_SPECS + RELATIVE_TIME_SPECS """ This part is here for ptb-raw, where we don't have pytz (unless the user installs it) Because imports in pytest are intricate, we just run pytest -k test_helpers.py with the TEST_NO_PYTZ environment variable set in addition to the regular test suite. Because actually uninstalling pytz would lead to errors in the test suite we just mock the import to raise the expected exception. Note that a fixture that just does this for every test that needs it is a nice idea, but for some reason makes test_updater.py hang indefinitely on GitHub Actions (at least when Hinrich tried that) """ TEST_NO_PYTZ = env_var_2_bool(os.getenv("TEST_NO_PYTZ", False)) if TEST_NO_PYTZ: orig_import = __import__ def import_mock(module_name, *args, **kwargs): if module_name == "pytz": raise ModuleNotFoundError("We are testing without pytz here") return orig_import(module_name, *args, **kwargs) with mock.patch("builtins.__import__", side_effect=import_mock): reload(tg_dtm) class TestDatetime: def test_helpers_utc(self):
# 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/]. import os import pytest from tests.conftest import env_var_2_bool @pytest.mark.skipif( not env_var_2_bool(os.getenv('TEST_BUILD', False)), reason='TEST_BUILD not enabled' ) def test_build(): assert os.system('python setup.py bdist_dumb') == 0 # pragma: no cover @pytest.mark.skipif( not env_var_2_bool(os.getenv('TEST_BUILD', False)), reason='TEST_BUILD not enabled' ) def test_build_raw(): assert os.system('python setup-raw.py bdist_dumb') == 0 # pragma: no cover
# # 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/]. import os import pytest from tests.conftest import env_var_2_bool skip_disabled = pytest.mark.skipif( not env_var_2_bool(os.getenv("TEST_BUILD", False)), reason="TEST_BUILD not enabled") # To make the tests agnostic of the cwd @pytest.fixture(autouse=True) def change_test_dir(request, monkeypatch): monkeypatch.chdir(request.config.rootdir) @skip_disabled def test_build(): assert os.system("python setup.py bdist_dumb") == 0 # pragma: no cover @skip_disabled
assert (sig.parameters.keys() ^ checked) - ignored == set() argvalues = [] names = [] http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where()) request = http.request('GET', 'https://core.telegram.org/bots/api') soup = BeautifulSoup(request.data.decode('utf-8'), 'html.parser') for thing in soup.select('h4 > a.anchor'): # Methods and types don't have spaces in them, luckily all other sections of the docs do # TODO: don't depend on that if '-' not in thing['name']: h4 = thing.parent # Is it a method if h4.text[0].lower() == h4.text[0]: argvalues.append((check_method, h4)) names.append(h4.text) elif h4.text not in IGNORED_OBJECTS: # Or a type/object argvalues.append((check_object, h4)) names.append(h4.text) @pytest.mark.parametrize(('method', 'data'), argvalues=argvalues, ids=names) @pytest.mark.skipif(not env_var_2_bool(os.getenv('TEST_OFFICIAL')), reason='test_official is not enabled') def test_official(method, data): method(data)