From 2821a5caf1b56e7bbca8d9799d9581b8a6405c8f Mon Sep 17 00:00:00 2001 From: pseusys Date: Wed, 26 Jul 2023 16:25:56 +0200 Subject: [PATCH 01/16] os.getenv -> os.environ --- tests/context_storages/test_dbs.py | 24 +++++++++---------- tutorials/context_storages/2_postgresql.py | 6 ++--- tutorials/context_storages/3_mongodb.py | 6 ++--- tutorials/context_storages/4_redis.py | 2 +- tutorials/context_storages/5_mysql.py | 6 ++--- .../context_storages/7_yandex_database.py | 4 ++-- tutorials/messengers/telegram/1_basic.py | 5 ++-- tutorials/messengers/telegram/2_buttons.py | 5 ++-- .../telegram/3_buttons_with_callback.py | 5 ++-- tutorials/messengers/telegram/4_conditions.py | 5 ++-- .../telegram/5_conditions_with_media.py | 5 ++-- .../telegram/6_conditions_extras.py | 5 ++-- .../messengers/telegram/7_polling_setup.py | 5 ++-- .../messengers/telegram/8_webhook_setup.py | 5 ++-- 14 files changed, 48 insertions(+), 40 deletions(-) diff --git a/tests/context_storages/test_dbs.py b/tests/context_storages/test_dbs.py index 3d48ff2af..3be788e5c 100644 --- a/tests/context_storages/test_dbs.py +++ b/tests/context_storages/test_dbs.py @@ -126,9 +126,9 @@ def test_mongo(testing_context, context_id): db = context_storage_factory( "mongodb://{}:{}@localhost:27017/{}".format( - os.getenv("MONGO_INITDB_ROOT_USERNAME"), - os.getenv("MONGO_INITDB_ROOT_PASSWORD"), - os.getenv("MONGO_INITDB_ROOT_USERNAME"), + os.environ["MONGO_INITDB_ROOT_USERNAME"], + os.environ["MONGO_INITDB_ROOT_PASSWORD"], + os.environ["MONGO_INITDB_ROOT_USERNAME"], ) ) generic_test(db, testing_context, context_id) @@ -138,7 +138,7 @@ def test_mongo(testing_context, context_id): @pytest.mark.skipif(not REDIS_ACTIVE, reason="Redis server is not running") @pytest.mark.skipif(not redis_available, reason="Redis dependencies missing") def test_redis(testing_context, context_id): - db = context_storage_factory("redis://{}:{}@localhost:6379/{}".format("", os.getenv("REDIS_PASSWORD"), "0")) + db = context_storage_factory("redis://{}:{}@localhost:6379/{}".format("", os.environ["REDIS_PASSWORD"], "0")) generic_test(db, testing_context, context_id) asyncio.run(delete_redis(db)) @@ -148,9 +148,9 @@ def test_redis(testing_context, context_id): def test_postgres(testing_context, context_id): db = context_storage_factory( "postgresql+asyncpg://{}:{}@localhost:5432/{}".format( - os.getenv("POSTGRES_USERNAME"), - os.getenv("POSTGRES_PASSWORD"), - os.getenv("POSTGRES_DB"), + os.environ["POSTGRES_USERNAME"], + os.environ["POSTGRES_PASSWORD"], + os.environ["POSTGRES_DB"], ) ) generic_test(db, testing_context, context_id) @@ -170,9 +170,9 @@ def test_sqlite(testing_file, testing_context, context_id): def test_mysql(testing_context, context_id): db = context_storage_factory( "mysql+asyncmy://{}:{}@localhost:3307/{}".format( - os.getenv("MYSQL_USERNAME"), - os.getenv("MYSQL_PASSWORD"), - os.getenv("MYSQL_DATABASE"), + os.environ["MYSQL_USERNAME"], + os.environ["MYSQL_PASSWORD"], + os.environ["MYSQL_DATABASE"], ) ) generic_test(db, testing_context, context_id) @@ -184,8 +184,8 @@ def test_mysql(testing_context, context_id): def test_ydb(testing_context, context_id): db = context_storage_factory( "{}{}".format( - os.getenv("YDB_ENDPOINT"), - os.getenv("YDB_DATABASE"), + os.environ["YDB_ENDPOINT"], + os.environ["YDB_DATABASE"], ), table_name="test", ) diff --git a/tutorials/context_storages/2_postgresql.py b/tutorials/context_storages/2_postgresql.py index 09aa949cf..090891d1b 100644 --- a/tutorials/context_storages/2_postgresql.py +++ b/tutorials/context_storages/2_postgresql.py @@ -22,9 +22,9 @@ # %% db_uri = "postgresql+asyncpg://{}:{}@localhost:5432/{}".format( - os.getenv("POSTGRES_USERNAME"), - os.getenv("POSTGRES_PASSWORD"), - os.getenv("POSTGRES_DB"), + os.environ["POSTGRES_USERNAME"], + os.environ["POSTGRES_PASSWORD"], + os.environ["POSTGRES_DB"], ) db = context_storage_factory(db_uri) diff --git a/tutorials/context_storages/3_mongodb.py b/tutorials/context_storages/3_mongodb.py index a6ff2ec9d..227c18766 100644 --- a/tutorials/context_storages/3_mongodb.py +++ b/tutorials/context_storages/3_mongodb.py @@ -22,9 +22,9 @@ # %% db_uri = "mongodb://{}:{}@localhost:27017/{}".format( - os.getenv("MONGO_INITDB_ROOT_USERNAME"), - os.getenv("MONGO_INITDB_ROOT_PASSWORD"), - os.getenv("MONGO_INITDB_ROOT_USERNAME"), + os.environ["MONGO_INITDB_ROOT_USERNAME"], + os.environ["MONGO_INITDB_ROOT_PASSWORD"], + os.environ["MONGO_INITDB_ROOT_USERNAME"], ) db = context_storage_factory(db_uri) diff --git a/tutorials/context_storages/4_redis.py b/tutorials/context_storages/4_redis.py index 28d6ba816..2665fdd14 100644 --- a/tutorials/context_storages/4_redis.py +++ b/tutorials/context_storages/4_redis.py @@ -21,7 +21,7 @@ # %% -db_uri = "redis://{}:{}@localhost:6379/{}".format("", os.getenv("REDIS_PASSWORD"), "0") +db_uri = "redis://{}:{}@localhost:6379/{}".format("", os.environ["REDIS_PASSWORD"], "0") db = context_storage_factory(db_uri) diff --git a/tutorials/context_storages/5_mysql.py b/tutorials/context_storages/5_mysql.py index b1f8e8a54..f9f610320 100644 --- a/tutorials/context_storages/5_mysql.py +++ b/tutorials/context_storages/5_mysql.py @@ -22,9 +22,9 @@ # %% db_uri = "mysql+asyncmy://{}:{}@localhost:3307/{}".format( - os.getenv("MYSQL_USERNAME"), - os.getenv("MYSQL_PASSWORD"), - os.getenv("MYSQL_DATABASE"), + os.environ["MYSQL_USERNAME"], + os.environ["MYSQL_PASSWORD"], + os.environ["MYSQL_DATABASE"], ) db = context_storage_factory(db_uri) diff --git a/tutorials/context_storages/7_yandex_database.py b/tutorials/context_storages/7_yandex_database.py index 2a32f724c..18fe9df05 100644 --- a/tutorials/context_storages/7_yandex_database.py +++ b/tutorials/context_storages/7_yandex_database.py @@ -30,8 +30,8 @@ # db_uri="grpc://localhost:2136/local" db_uri = "{}{}".format( - os.getenv("YDB_ENDPOINT"), - os.getenv("YDB_DATABASE"), + os.environ["YDB_ENDPOINT"], + os.environ["YDB_DATABASE"], ) db = context_storage_factory(db_uri) diff --git a/tutorials/messengers/telegram/1_basic.py b/tutorials/messengers/telegram/1_basic.py index db3c07c41..5b63aad0b 100644 --- a/tutorials/messengers/telegram/1_basic.py +++ b/tutorials/messengers/telegram/1_basic.py @@ -72,9 +72,10 @@ def main(): - if not os.getenv("TG_BOT_TOKEN"): + if os.getenv("TG_BOT_TOKEN") is None: print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") - pipeline.run() + else: + pipeline.run() if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building diff --git a/tutorials/messengers/telegram/2_buttons.py b/tutorials/messengers/telegram/2_buttons.py index 2d536dbe3..853992e53 100644 --- a/tutorials/messengers/telegram/2_buttons.py +++ b/tutorials/messengers/telegram/2_buttons.py @@ -156,9 +156,10 @@ def main(): - if not os.getenv("TG_BOT_TOKEN"): + if os.getenv("TG_BOT_TOKEN") is None: print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") - pipeline.run() + else: + pipeline.run() if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building diff --git a/tutorials/messengers/telegram/3_buttons_with_callback.py b/tutorials/messengers/telegram/3_buttons_with_callback.py index d3a469a2d..86e53f8e8 100644 --- a/tutorials/messengers/telegram/3_buttons_with_callback.py +++ b/tutorials/messengers/telegram/3_buttons_with_callback.py @@ -149,9 +149,10 @@ def main(): - if not os.getenv("TG_BOT_TOKEN"): + if os.getenv("TG_BOT_TOKEN") is None: print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") - pipeline.run() + else: + pipeline.run() if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building diff --git a/tutorials/messengers/telegram/4_conditions.py b/tutorials/messengers/telegram/4_conditions.py index f6546ef47..edec1618c 100644 --- a/tutorials/messengers/telegram/4_conditions.py +++ b/tutorials/messengers/telegram/4_conditions.py @@ -113,9 +113,10 @@ def main(): - if not os.getenv("TG_BOT_TOKEN"): + if os.getenv("TG_BOT_TOKEN") is None: print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") - pipeline.run() + else: + pipeline.run() if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building diff --git a/tutorials/messengers/telegram/5_conditions_with_media.py b/tutorials/messengers/telegram/5_conditions_with_media.py index 06c8d68fc..8c2719bc8 100644 --- a/tutorials/messengers/telegram/5_conditions_with_media.py +++ b/tutorials/messengers/telegram/5_conditions_with_media.py @@ -165,9 +165,10 @@ def extract_data(ctx: Context, _: Pipeline): # A function to extract data with def main(): - if not os.getenv("TG_BOT_TOKEN"): + if os.getenv("TG_BOT_TOKEN") is None: print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") - pipeline.run() + else: + pipeline.run() if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building diff --git a/tutorials/messengers/telegram/6_conditions_extras.py b/tutorials/messengers/telegram/6_conditions_extras.py index 1131d29b6..72184e06f 100644 --- a/tutorials/messengers/telegram/6_conditions_extras.py +++ b/tutorials/messengers/telegram/6_conditions_extras.py @@ -104,9 +104,10 @@ def main(): - if not os.getenv("TG_BOT_TOKEN"): + if os.getenv("TG_BOT_TOKEN") is None: print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") - pipeline.run() + else: + pipeline.run() if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building diff --git a/tutorials/messengers/telegram/7_polling_setup.py b/tutorials/messengers/telegram/7_polling_setup.py index 5496cebf6..4069934eb 100644 --- a/tutorials/messengers/telegram/7_polling_setup.py +++ b/tutorials/messengers/telegram/7_polling_setup.py @@ -52,9 +52,10 @@ def main(): - if not os.getenv("TG_BOT_TOKEN"): + if os.getenv("TG_BOT_TOKEN") is None: print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") - pipeline.run() + else: + pipeline.run() if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building diff --git a/tutorials/messengers/telegram/8_webhook_setup.py b/tutorials/messengers/telegram/8_webhook_setup.py index 7f65fced9..81de0b3a9 100644 --- a/tutorials/messengers/telegram/8_webhook_setup.py +++ b/tutorials/messengers/telegram/8_webhook_setup.py @@ -48,9 +48,10 @@ def main(): - if not os.getenv("TG_BOT_TOKEN"): + if os.getenv("TG_BOT_TOKEN") is None: print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") - pipeline.run() + else: + pipeline.run() if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building From d09c448f91794a690869499989adb52f068caed3 Mon Sep 17 00:00:00 2001 From: pseusys Date: Fri, 28 Jul 2023 04:31:09 +0200 Subject: [PATCH 02/16] exception raising added --- tutorials/messengers/telegram/1_basic.py | 2 +- tutorials/messengers/telegram/2_buttons.py | 2 +- tutorials/messengers/telegram/3_buttons_with_callback.py | 2 +- tutorials/messengers/telegram/4_conditions.py | 2 +- tutorials/messengers/telegram/5_conditions_with_media.py | 2 +- tutorials/messengers/telegram/6_conditions_extras.py | 2 +- tutorials/messengers/telegram/7_polling_setup.py | 2 +- tutorials/messengers/telegram/8_webhook_setup.py | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tutorials/messengers/telegram/1_basic.py b/tutorials/messengers/telegram/1_basic.py index 5b63aad0b..155c87175 100644 --- a/tutorials/messengers/telegram/1_basic.py +++ b/tutorials/messengers/telegram/1_basic.py @@ -73,7 +73,7 @@ def main(): if os.getenv("TG_BOT_TOKEN") is None: - print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") + raise RuntimeError("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") else: pipeline.run() diff --git a/tutorials/messengers/telegram/2_buttons.py b/tutorials/messengers/telegram/2_buttons.py index 853992e53..1fb44465e 100644 --- a/tutorials/messengers/telegram/2_buttons.py +++ b/tutorials/messengers/telegram/2_buttons.py @@ -157,7 +157,7 @@ def main(): if os.getenv("TG_BOT_TOKEN") is None: - print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") + raise RuntimeError("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") else: pipeline.run() diff --git a/tutorials/messengers/telegram/3_buttons_with_callback.py b/tutorials/messengers/telegram/3_buttons_with_callback.py index 86e53f8e8..87622239d 100644 --- a/tutorials/messengers/telegram/3_buttons_with_callback.py +++ b/tutorials/messengers/telegram/3_buttons_with_callback.py @@ -150,7 +150,7 @@ def main(): if os.getenv("TG_BOT_TOKEN") is None: - print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") + raise RuntimeError("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") else: pipeline.run() diff --git a/tutorials/messengers/telegram/4_conditions.py b/tutorials/messengers/telegram/4_conditions.py index edec1618c..75fe33b8d 100644 --- a/tutorials/messengers/telegram/4_conditions.py +++ b/tutorials/messengers/telegram/4_conditions.py @@ -114,7 +114,7 @@ def main(): if os.getenv("TG_BOT_TOKEN") is None: - print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") + raise RuntimeError("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") else: pipeline.run() diff --git a/tutorials/messengers/telegram/5_conditions_with_media.py b/tutorials/messengers/telegram/5_conditions_with_media.py index 8c2719bc8..193b4804d 100644 --- a/tutorials/messengers/telegram/5_conditions_with_media.py +++ b/tutorials/messengers/telegram/5_conditions_with_media.py @@ -166,7 +166,7 @@ def extract_data(ctx: Context, _: Pipeline): # A function to extract data with def main(): if os.getenv("TG_BOT_TOKEN") is None: - print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") + raise RuntimeError("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") else: pipeline.run() diff --git a/tutorials/messengers/telegram/6_conditions_extras.py b/tutorials/messengers/telegram/6_conditions_extras.py index 72184e06f..8523a198f 100644 --- a/tutorials/messengers/telegram/6_conditions_extras.py +++ b/tutorials/messengers/telegram/6_conditions_extras.py @@ -105,7 +105,7 @@ def main(): if os.getenv("TG_BOT_TOKEN") is None: - print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") + raise RuntimeError("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") else: pipeline.run() diff --git a/tutorials/messengers/telegram/7_polling_setup.py b/tutorials/messengers/telegram/7_polling_setup.py index 4069934eb..18260e7d9 100644 --- a/tutorials/messengers/telegram/7_polling_setup.py +++ b/tutorials/messengers/telegram/7_polling_setup.py @@ -53,7 +53,7 @@ def main(): if os.getenv("TG_BOT_TOKEN") is None: - print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") + raise RuntimeError("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") else: pipeline.run() diff --git a/tutorials/messengers/telegram/8_webhook_setup.py b/tutorials/messengers/telegram/8_webhook_setup.py index 81de0b3a9..c13daa6d6 100644 --- a/tutorials/messengers/telegram/8_webhook_setup.py +++ b/tutorials/messengers/telegram/8_webhook_setup.py @@ -49,7 +49,7 @@ def main(): if os.getenv("TG_BOT_TOKEN") is None: - print("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") + raise RuntimeError("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") else: pipeline.run() From 9af01dc650b98ec83ebb79cae52b0686681064b6 Mon Sep 17 00:00:00 2001 From: pseusys Date: Thu, 10 Aug 2023 00:32:23 +0200 Subject: [PATCH 03/16] skip env var added --- .env_file | 1 + tests/context_storages/test_dbs.py | 12 +++++++++++- tests/messengers/telegram/conftest.py | 5 +---- tests/messengers/telegram/test_tutorials.py | 5 ++++- tests/messengers/telegram/test_types.py | 5 +++++ tests/test_utils.py | 3 +++ tutorials/messengers/telegram/1_basic.py | 7 ++----- tutorials/messengers/telegram/2_buttons.py | 7 ++----- .../messengers/telegram/3_buttons_with_callback.py | 7 ++----- tutorials/messengers/telegram/4_conditions.py | 7 ++----- .../messengers/telegram/5_conditions_with_media.py | 7 ++----- tutorials/messengers/telegram/6_conditions_extras.py | 7 ++----- tutorials/messengers/telegram/7_polling_setup.py | 7 ++----- tutorials/messengers/telegram/8_webhook_setup.py | 7 ++----- 14 files changed, 41 insertions(+), 46 deletions(-) diff --git a/.env_file b/.env_file index d943f71b0..37be79e2f 100644 --- a/.env_file +++ b/.env_file @@ -14,3 +14,4 @@ MON_PORT=8765 YDB_ENDPOINT=grpc://localhost:2136 YDB_DATABASE=/local YDB_ANONYMOUS_CREDENTIALS=1 +TESTS_TO_SKIP= diff --git a/tests/context_storages/test_dbs.py b/tests/context_storages/test_dbs.py index 3be788e5c..548f2678c 100644 --- a/tests/context_storages/test_dbs.py +++ b/tests/context_storages/test_dbs.py @@ -31,11 +31,12 @@ delete_ydb, ) -from tests.test_utils import get_path_from_tests_to_current_dir +from tests.test_utils import get_path_from_tests_to_current_dir, tests_to_skip from dff.pipeline import Pipeline from dff.utils.testing import check_happy_path, TOY_SCRIPT_ARGS, HAPPY_PATH dot_path_to_addon = get_path_from_tests_to_current_dir(__file__, separator=".") +db_tests_to_skip = {var for var in tests_to_skip if var.startswith("db_")} def ping_localhost(port: int, timeout=60): @@ -98,6 +99,7 @@ def test_protocol_suggestion(protocol, expected): assert result == expected +@pytest.mark.skipif("db_shelve" in db_tests_to_skip, reason="Selve context storage will be skipped") def test_shelve(testing_file, testing_context, context_id): db = ShelveContextStorage(f"shelve://{testing_file}") generic_test(db, testing_context, context_id) @@ -105,6 +107,7 @@ def test_shelve(testing_file, testing_context, context_id): @pytest.mark.skipif(not json_available, reason="JSON dependencies missing") +@pytest.mark.skipif("db_json" in db_tests_to_skip, reason="JSON context storage will be skipped") def test_json(testing_file, testing_context, context_id): db = context_storage_factory(f"json://{testing_file}") generic_test(db, testing_context, context_id) @@ -112,6 +115,7 @@ def test_json(testing_file, testing_context, context_id): @pytest.mark.skipif(not pickle_available, reason="Pickle dependencies missing") +@pytest.mark.skipif("db_pickle" in db_tests_to_skip, reason="Pickle context storage will be skipped") def test_pickle(testing_file, testing_context, context_id): db = context_storage_factory(f"pickle://{testing_file}") generic_test(db, testing_context, context_id) @@ -120,6 +124,7 @@ def test_pickle(testing_file, testing_context, context_id): @pytest.mark.skipif(not MONGO_ACTIVE, reason="Mongodb server is not running") @pytest.mark.skipif(not mongo_available, reason="Mongodb dependencies missing") +@pytest.mark.skipif("db_mongo" in db_tests_to_skip, reason="MongoDB context storage will be skipped") def test_mongo(testing_context, context_id): if system() == "Windows": pytest.skip() @@ -137,6 +142,7 @@ def test_mongo(testing_context, context_id): @pytest.mark.skipif(not REDIS_ACTIVE, reason="Redis server is not running") @pytest.mark.skipif(not redis_available, reason="Redis dependencies missing") +@pytest.mark.skipif("db_redis" in db_tests_to_skip, reason="Redis context storage will be skipped") def test_redis(testing_context, context_id): db = context_storage_factory("redis://{}:{}@localhost:6379/{}".format("", os.environ["REDIS_PASSWORD"], "0")) generic_test(db, testing_context, context_id) @@ -145,6 +151,7 @@ def test_redis(testing_context, context_id): @pytest.mark.skipif(not POSTGRES_ACTIVE, reason="Postgres server is not running") @pytest.mark.skipif(not postgres_available, reason="Postgres dependencies missing") +@pytest.mark.skipif("db_postgres" in db_tests_to_skip, reason="PostgreSQL context storage will be skipped") def test_postgres(testing_context, context_id): db = context_storage_factory( "postgresql+asyncpg://{}:{}@localhost:5432/{}".format( @@ -158,6 +165,7 @@ def test_postgres(testing_context, context_id): @pytest.mark.skipif(not sqlite_available, reason="Sqlite dependencies missing") +@pytest.mark.skipif("db_sqlite" in db_tests_to_skip, reason="SQLite context storage will be skipped") def test_sqlite(testing_file, testing_context, context_id): separator = "///" if system() == "Windows" else "////" db = context_storage_factory(f"sqlite+aiosqlite:{separator}{testing_file}") @@ -167,6 +175,7 @@ def test_sqlite(testing_file, testing_context, context_id): @pytest.mark.skipif(not MYSQL_ACTIVE, reason="Mysql server is not running") @pytest.mark.skipif(not mysql_available, reason="Mysql dependencies missing") +@pytest.mark.skipif("db_mysql" in db_tests_to_skip, reason="MySQL context storage will be skipped") def test_mysql(testing_context, context_id): db = context_storage_factory( "mysql+asyncmy://{}:{}@localhost:3307/{}".format( @@ -181,6 +190,7 @@ def test_mysql(testing_context, context_id): @pytest.mark.skipif(not YDB_ACTIVE, reason="YQL server not running") @pytest.mark.skipif(not ydb_available, reason="YDB dependencies missing") +@pytest.mark.skipif("db_ydb" in db_tests_to_skip, reason="YDB context storage will be skipped") def test_ydb(testing_context, context_id): db = context_storage_factory( "{}{}".format( diff --git a/tests/messengers/telegram/conftest.py b/tests/messengers/telegram/conftest.py index d3436410a..147e08c4d 100644 --- a/tests/messengers/telegram/conftest.py +++ b/tests/messengers/telegram/conftest.py @@ -40,10 +40,7 @@ def env_vars(): env_variables = {"TG_BOT_TOKEN": None, "TG_API_ID": None, "TG_API_HASH": None, "TG_BOT_USERNAME": None} for arg in env_variables: - env_variables[arg] = os.getenv(arg) - - if env_variables[arg] is None: - pytest.skip(f"`{arg}` is not set", allow_module_level=True) + env_variables[arg] = os.environ[arg] yield env_variables diff --git a/tests/messengers/telegram/test_tutorials.py b/tests/messengers/telegram/test_tutorials.py index 6ca4009d8..7cbaf91b4 100644 --- a/tests/messengers/telegram/test_tutorials.py +++ b/tests/messengers/telegram/test_tutorials.py @@ -12,10 +12,13 @@ except ImportError: pytest.skip(reason="`telegram` is not available", allow_module_level=True) -from tests.test_utils import get_path_from_tests_to_current_dir +from tests.test_utils import get_path_from_tests_to_current_dir, tests_to_skip from dff.utils.testing.common import check_happy_path from dff.utils.testing.telegram import TelegramTesting, replace_click_button +if "messenger_telegram" in tests_to_skip: + pytest.skip(reason="Telegram messenger will be skipped", allow_module_level=True) + dot_path_to_addon = get_path_from_tests_to_current_dir(__file__, separator=".") diff --git a/tests/messengers/telegram/test_types.py b/tests/messengers/telegram/test_types.py index c67520c45..a5be26e89 100644 --- a/tests/messengers/telegram/test_types.py +++ b/tests/messengers/telegram/test_types.py @@ -25,6 +25,11 @@ from dff.utils.testing.telegram import TelegramTesting +from tests.test_utils import tests_to_skip + +if "messenger_telegram" in tests_to_skip: + pytest.skip(reason="Telegram messenger will be skipped", allow_module_level=True) + image = Image( source="https://gist.githubusercontent.com/scotthaleen/32f76a413e0dfd4b4d79c2a534d49c0b/raw" "/6c1036b1eca90b341caf06d4056d36f64fc11e88/tiny.jpg" diff --git a/tests/test_utils.py b/tests/test_utils.py index e0875af34..e9b45e1e2 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2,6 +2,9 @@ import pathlib +tests_to_skip = {var for var in os.environ["TESTS_TO_SKIP"].split(":") if var.startswith("db_")} + + def get_path_from_tests_to_current_dir(file: str, separator: str = os.sep) -> str: parents = [] for parent in pathlib.Path(file).parents: diff --git a/tutorials/messengers/telegram/1_basic.py b/tutorials/messengers/telegram/1_basic.py index 155c87175..ea047d3c0 100644 --- a/tutorials/messengers/telegram/1_basic.py +++ b/tutorials/messengers/telegram/1_basic.py @@ -59,7 +59,7 @@ # %% -interface = PollingTelegramInterface(token=os.getenv("TG_BOT_TOKEN", "")) +interface = PollingTelegramInterface(token=os.environ["TG_BOT_TOKEN"]) # %% @@ -72,10 +72,7 @@ def main(): - if os.getenv("TG_BOT_TOKEN") is None: - raise RuntimeError("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") - else: - pipeline.run() + pipeline.run() if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building diff --git a/tutorials/messengers/telegram/2_buttons.py b/tutorials/messengers/telegram/2_buttons.py index 1fb44465e..cd1ffd073 100644 --- a/tutorials/messengers/telegram/2_buttons.py +++ b/tutorials/messengers/telegram/2_buttons.py @@ -88,7 +88,7 @@ }, } -interface = PollingTelegramInterface(token=os.getenv("TG_BOT_TOKEN", "")) +interface = PollingTelegramInterface(token=os.environ["TG_BOT_TOKEN"]) # this variable is only for testing happy_path = ( @@ -156,10 +156,7 @@ def main(): - if os.getenv("TG_BOT_TOKEN") is None: - raise RuntimeError("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") - else: - pipeline.run() + pipeline.run() if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building diff --git a/tutorials/messengers/telegram/3_buttons_with_callback.py b/tutorials/messengers/telegram/3_buttons_with_callback.py index 87622239d..e0288fd31 100644 --- a/tutorials/messengers/telegram/3_buttons_with_callback.py +++ b/tutorials/messengers/telegram/3_buttons_with_callback.py @@ -136,7 +136,7 @@ ), ) -interface = PollingTelegramInterface(token=os.getenv("TG_BOT_TOKEN", "")) +interface = PollingTelegramInterface(token=os.environ["TG_BOT_TOKEN"]) # %% @@ -149,10 +149,7 @@ def main(): - if os.getenv("TG_BOT_TOKEN") is None: - raise RuntimeError("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") - else: - pipeline.run() + pipeline.run() if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building diff --git a/tutorials/messengers/telegram/4_conditions.py b/tutorials/messengers/telegram/4_conditions.py index 75fe33b8d..02735b282 100644 --- a/tutorials/messengers/telegram/4_conditions.py +++ b/tutorials/messengers/telegram/4_conditions.py @@ -100,7 +100,7 @@ # %% -interface = PollingTelegramInterface(token=os.getenv("TG_BOT_TOKEN", "")) +interface = PollingTelegramInterface(token=os.environ["TG_BOT_TOKEN"]) # %% @@ -113,10 +113,7 @@ def main(): - if os.getenv("TG_BOT_TOKEN") is None: - raise RuntimeError("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") - else: - pipeline.run() + pipeline.run() if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building diff --git a/tutorials/messengers/telegram/5_conditions_with_media.py b/tutorials/messengers/telegram/5_conditions_with_media.py index 193b4804d..83deacfc3 100644 --- a/tutorials/messengers/telegram/5_conditions_with_media.py +++ b/tutorials/messengers/telegram/5_conditions_with_media.py @@ -39,7 +39,7 @@ # %% -interface = PollingTelegramInterface(token=os.getenv("TG_BOT_TOKEN", "")) +interface = PollingTelegramInterface(token=os.environ["TG_BOT_TOKEN"]) # %% @@ -165,10 +165,7 @@ def extract_data(ctx: Context, _: Pipeline): # A function to extract data with def main(): - if os.getenv("TG_BOT_TOKEN") is None: - raise RuntimeError("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") - else: - pipeline.run() + pipeline.run() if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building diff --git a/tutorials/messengers/telegram/6_conditions_extras.py b/tutorials/messengers/telegram/6_conditions_extras.py index 8523a198f..9e808572e 100644 --- a/tutorials/messengers/telegram/6_conditions_extras.py +++ b/tutorials/messengers/telegram/6_conditions_extras.py @@ -91,7 +91,7 @@ # %% -interface = PollingTelegramInterface(token=os.getenv("TG_BOT_TOKEN", "")) +interface = PollingTelegramInterface(token=os.environ["TG_BOT_TOKEN"]) # %% @@ -104,10 +104,7 @@ def main(): - if os.getenv("TG_BOT_TOKEN") is None: - raise RuntimeError("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") - else: - pipeline.run() + pipeline.run() if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building diff --git a/tutorials/messengers/telegram/7_polling_setup.py b/tutorials/messengers/telegram/7_polling_setup.py index 18260e7d9..6880d411f 100644 --- a/tutorials/messengers/telegram/7_polling_setup.py +++ b/tutorials/messengers/telegram/7_polling_setup.py @@ -32,7 +32,7 @@ # %% interface = PollingTelegramInterface( - token=os.getenv("TG_BOT_TOKEN", ""), + token=os.environ["TG_BOT_TOKEN"], interval=2, allowed_updates=update_types, timeout=30, @@ -52,10 +52,7 @@ def main(): - if os.getenv("TG_BOT_TOKEN") is None: - raise RuntimeError("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") - else: - pipeline.run() + pipeline.run() if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building diff --git a/tutorials/messengers/telegram/8_webhook_setup.py b/tutorials/messengers/telegram/8_webhook_setup.py index c13daa6d6..98da6ae31 100644 --- a/tutorials/messengers/telegram/8_webhook_setup.py +++ b/tutorials/messengers/telegram/8_webhook_setup.py @@ -34,7 +34,7 @@ # %% -interface = CallbackTelegramInterface(token=os.getenv("TG_BOT_TOKEN", "")) +interface = CallbackTelegramInterface(token=os.environ["TG_BOT_TOKEN"]) # %% @@ -48,10 +48,7 @@ def main(): - if os.getenv("TG_BOT_TOKEN") is None: - raise RuntimeError("`TG_BOT_TOKEN` variable needs to be set to use TelegramInterface.") - else: - pipeline.run() + pipeline.run() if __name__ == "__main__" and is_interactive_mode(): # prevent run during doc building From 23be1c7b3feaee062f73548c509bf477855becde Mon Sep 17 00:00:00 2001 From: pseusys Date: Thu, 10 Aug 2023 00:41:25 +0200 Subject: [PATCH 04/16] tests skipped accordingly --- .env_file | 1 - tests/context_storages/test_dbs.py | 12 +----------- tests/messengers/telegram/test_tutorials.py | 5 +---- tests/messengers/telegram/test_types.py | 5 ----- tests/test_utils.py | 3 --- 5 files changed, 2 insertions(+), 24 deletions(-) diff --git a/.env_file b/.env_file index 37be79e2f..d943f71b0 100644 --- a/.env_file +++ b/.env_file @@ -14,4 +14,3 @@ MON_PORT=8765 YDB_ENDPOINT=grpc://localhost:2136 YDB_DATABASE=/local YDB_ANONYMOUS_CREDENTIALS=1 -TESTS_TO_SKIP= diff --git a/tests/context_storages/test_dbs.py b/tests/context_storages/test_dbs.py index 3c0ea823b..296e9b779 100644 --- a/tests/context_storages/test_dbs.py +++ b/tests/context_storages/test_dbs.py @@ -31,12 +31,11 @@ delete_ydb, ) -from tests.test_utils import get_path_from_tests_to_current_dir, tests_to_skip +from tests.test_utils import get_path_from_tests_to_current_dir from dff.pipeline import Pipeline from dff.utils.testing import check_happy_path, TOY_SCRIPT_ARGS, HAPPY_PATH dot_path_to_addon = get_path_from_tests_to_current_dir(__file__, separator=".") -db_tests_to_skip = {var for var in tests_to_skip if var.startswith("db_")} def ping_localhost(port: int, timeout=60): @@ -102,7 +101,6 @@ def test_protocol_suggestion(protocol, expected): assert result == expected -@pytest.mark.skipif("db_shelve" in db_tests_to_skip, reason="Selve context storage will be skipped") def test_shelve(testing_file, testing_context, context_id): db = ShelveContextStorage(f"shelve://{testing_file}") generic_test(db, testing_context, context_id) @@ -110,7 +108,6 @@ def test_shelve(testing_file, testing_context, context_id): @pytest.mark.skipif(not json_available, reason="JSON dependencies missing") -@pytest.mark.skipif("db_json" in db_tests_to_skip, reason="JSON context storage will be skipped") def test_json(testing_file, testing_context, context_id): db = context_storage_factory(f"json://{testing_file}") generic_test(db, testing_context, context_id) @@ -118,7 +115,6 @@ def test_json(testing_file, testing_context, context_id): @pytest.mark.skipif(not pickle_available, reason="Pickle dependencies missing") -@pytest.mark.skipif("db_pickle" in db_tests_to_skip, reason="Pickle context storage will be skipped") def test_pickle(testing_file, testing_context, context_id): db = context_storage_factory(f"pickle://{testing_file}") generic_test(db, testing_context, context_id) @@ -128,7 +124,6 @@ def test_pickle(testing_file, testing_context, context_id): @pytest.mark.docker @pytest.mark.skipif(not MONGO_ACTIVE, reason="Mongodb server is not running") @pytest.mark.skipif(not mongo_available, reason="Mongodb dependencies missing") -@pytest.mark.skipif("db_mongo" in db_tests_to_skip, reason="MongoDB context storage will be skipped") def test_mongo(testing_context, context_id): if system() == "Windows": pytest.skip() @@ -147,7 +142,6 @@ def test_mongo(testing_context, context_id): @pytest.mark.docker @pytest.mark.skipif(not REDIS_ACTIVE, reason="Redis server is not running") @pytest.mark.skipif(not redis_available, reason="Redis dependencies missing") -@pytest.mark.skipif("db_redis" in db_tests_to_skip, reason="Redis context storage will be skipped") def test_redis(testing_context, context_id): db = context_storage_factory("redis://{}:{}@localhost:6379/{}".format("", os.environ["REDIS_PASSWORD"], "0")) generic_test(db, testing_context, context_id) @@ -157,7 +151,6 @@ def test_redis(testing_context, context_id): @pytest.mark.docker @pytest.mark.skipif(not POSTGRES_ACTIVE, reason="Postgres server is not running") @pytest.mark.skipif(not postgres_available, reason="Postgres dependencies missing") -@pytest.mark.skipif("db_postgres" in db_tests_to_skip, reason="PostgreSQL context storage will be skipped") def test_postgres(testing_context, context_id): db = context_storage_factory( "postgresql+asyncpg://{}:{}@localhost:5432/{}".format( @@ -171,7 +164,6 @@ def test_postgres(testing_context, context_id): @pytest.mark.skipif(not sqlite_available, reason="Sqlite dependencies missing") -@pytest.mark.skipif("db_sqlite" in db_tests_to_skip, reason="SQLite context storage will be skipped") def test_sqlite(testing_file, testing_context, context_id): separator = "///" if system() == "Windows" else "////" db = context_storage_factory(f"sqlite+aiosqlite:{separator}{testing_file}") @@ -182,7 +174,6 @@ def test_sqlite(testing_file, testing_context, context_id): @pytest.mark.docker @pytest.mark.skipif(not MYSQL_ACTIVE, reason="Mysql server is not running") @pytest.mark.skipif(not mysql_available, reason="Mysql dependencies missing") -@pytest.mark.skipif("db_mysql" in db_tests_to_skip, reason="MySQL context storage will be skipped") def test_mysql(testing_context, context_id): db = context_storage_factory( "mysql+asyncmy://{}:{}@localhost:3307/{}".format( @@ -198,7 +189,6 @@ def test_mysql(testing_context, context_id): @pytest.mark.docker @pytest.mark.skipif(not YDB_ACTIVE, reason="YQL server not running") @pytest.mark.skipif(not ydb_available, reason="YDB dependencies missing") -@pytest.mark.skipif("db_ydb" in db_tests_to_skip, reason="YDB context storage will be skipped") def test_ydb(testing_context, context_id): db = context_storage_factory( "{}{}".format( diff --git a/tests/messengers/telegram/test_tutorials.py b/tests/messengers/telegram/test_tutorials.py index 3865ae2d2..625bad386 100644 --- a/tests/messengers/telegram/test_tutorials.py +++ b/tests/messengers/telegram/test_tutorials.py @@ -12,13 +12,10 @@ except ImportError: pytest.skip(reason="`telegram` is not available", allow_module_level=True) -from tests.test_utils import get_path_from_tests_to_current_dir, tests_to_skip +from tests.test_utils import get_path_from_tests_to_current_dir from dff.utils.testing.common import check_happy_path from dff.utils.testing.telegram import TelegramTesting, replace_click_button -if "messenger_telegram" in tests_to_skip: - pytest.skip(reason="Telegram messenger will be skipped", allow_module_level=True) - dot_path_to_addon = get_path_from_tests_to_current_dir(__file__, separator=".") diff --git a/tests/messengers/telegram/test_types.py b/tests/messengers/telegram/test_types.py index 790e8031a..cc50ae558 100644 --- a/tests/messengers/telegram/test_types.py +++ b/tests/messengers/telegram/test_types.py @@ -25,11 +25,6 @@ from dff.utils.testing.telegram import TelegramTesting -from tests.test_utils import tests_to_skip - -if "messenger_telegram" in tests_to_skip: - pytest.skip(reason="Telegram messenger will be skipped", allow_module_level=True) - image = Image( source="https://gist.githubusercontent.com/scotthaleen/32f76a413e0dfd4b4d79c2a534d49c0b/raw" "/6c1036b1eca90b341caf06d4056d36f64fc11e88/tiny.jpg" diff --git a/tests/test_utils.py b/tests/test_utils.py index e9b45e1e2..e0875af34 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2,9 +2,6 @@ import pathlib -tests_to_skip = {var for var in os.environ["TESTS_TO_SKIP"].split(":") if var.startswith("db_")} - - def get_path_from_tests_to_current_dir(file: str, separator: str = os.sep) -> str: parents = [] for parent in pathlib.Path(file).parents: From 5c391c8952161eb046934e731f5b8cd31c5189d5 Mon Sep 17 00:00:00 2001 From: pseusys Date: Fri, 11 Aug 2023 03:29:47 +0200 Subject: [PATCH 05/16] telegram skip added --- tests/messengers/telegram/test_tutorials.py | 4 ++++ tests/messengers/telegram/test_types.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/tests/messengers/telegram/test_tutorials.py b/tests/messengers/telegram/test_tutorials.py index 625bad386..4408db9fe 100644 --- a/tests/messengers/telegram/test_tutorials.py +++ b/tests/messengers/telegram/test_tutorials.py @@ -3,6 +3,7 @@ """ import importlib import logging +import os import pytest @@ -12,6 +13,9 @@ except ImportError: pytest.skip(reason="`telegram` is not available", allow_module_level=True) +if "TG_BOT_TOKEN" not in os.environ: + pytest.skip(reason="Telegram token is not available", allow_module_level=True) + from tests.test_utils import get_path_from_tests_to_current_dir from dff.utils.testing.common import check_happy_path from dff.utils.testing.telegram import TelegramTesting, replace_click_button diff --git a/tests/messengers/telegram/test_types.py b/tests/messengers/telegram/test_types.py index cc50ae558..b923217f1 100644 --- a/tests/messengers/telegram/test_types.py +++ b/tests/messengers/telegram/test_types.py @@ -1,3 +1,4 @@ +import os import json from io import IOBase from pathlib import Path @@ -10,6 +11,9 @@ except ImportError: pytest.skip(reason="`telegram` is not available", allow_module_level=True) +if "TG_BOT_TOKEN" not in os.environ: + pytest.skip(reason="Telegram token is not available", allow_module_level=True) + from pydantic import ValidationError from telebot import types From c4703c4ecd1a5b4917f6c019584bd8113fed3412 Mon Sep 17 00:00:00 2001 From: pseusys Date: Mon, 14 Aug 2023 09:02:20 +0200 Subject: [PATCH 06/16] build environment published in github actions --- .github/workflows/build_and_publish_docs.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build_and_publish_docs.yml b/.github/workflows/build_and_publish_docs.yml index d05847331..4da0c6ec0 100644 --- a/.github/workflows/build_and_publish_docs.yml +++ b/.github/workflows/build_and_publish_docs.yml @@ -39,6 +39,11 @@ jobs: make venv - name: build documentation + env: + TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }} + TG_API_ID: ${{ secrets.TG_API_ID }} + TG_API_HASH: ${{ secrets.TG_API_HASH }} + TG_BOT_USERNAME: ${{ secrets.TG_BOT_USERNAME }} run: | make doc From e40ed50da9ed93f8b5472df08638a9ac9f0db35c Mon Sep 17 00:00:00 2001 From: pseusys Date: Mon, 21 Aug 2023 10:31:12 +0200 Subject: [PATCH 07/16] module level skipping removed --- tests/messengers/telegram/conftest.py | 5 ++++- tests/messengers/telegram/test_tutorials.py | 7 ++----- tests/messengers/telegram/test_types.py | 4 ---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/messengers/telegram/conftest.py b/tests/messengers/telegram/conftest.py index 147e08c4d..d3436410a 100644 --- a/tests/messengers/telegram/conftest.py +++ b/tests/messengers/telegram/conftest.py @@ -40,7 +40,10 @@ def env_vars(): env_variables = {"TG_BOT_TOKEN": None, "TG_API_ID": None, "TG_API_HASH": None, "TG_BOT_USERNAME": None} for arg in env_variables: - env_variables[arg] = os.environ[arg] + env_variables[arg] = os.getenv(arg) + + if env_variables[arg] is None: + pytest.skip(f"`{arg}` is not set", allow_module_level=True) yield env_variables diff --git a/tests/messengers/telegram/test_tutorials.py b/tests/messengers/telegram/test_tutorials.py index 4408db9fe..9e0215934 100644 --- a/tests/messengers/telegram/test_tutorials.py +++ b/tests/messengers/telegram/test_tutorials.py @@ -3,7 +3,6 @@ """ import importlib import logging -import os import pytest @@ -13,9 +12,6 @@ except ImportError: pytest.skip(reason="`telegram` is not available", allow_module_level=True) -if "TG_BOT_TOKEN" not in os.environ: - pytest.skip(reason="Telegram token is not available", allow_module_level=True) - from tests.test_utils import get_path_from_tests_to_current_dir from dff.utils.testing.common import check_happy_path from dff.utils.testing.telegram import TelegramTesting, replace_click_button @@ -31,7 +27,8 @@ "3_buttons_with_callback", ], ) -def test_client_tutorials_without_telegram(tutorial_module_name): +def test_client_tutorials_without_telegram(tutorial_module_name, env_vars): + assert "TG_BOT_TOKEN" in env_vars tutorial_module = importlib.import_module(f"tutorials.{dot_path_to_addon}.{tutorial_module_name}") pipeline = tutorial_module.pipeline happy_path = tutorial_module.happy_path diff --git a/tests/messengers/telegram/test_types.py b/tests/messengers/telegram/test_types.py index b923217f1..cc50ae558 100644 --- a/tests/messengers/telegram/test_types.py +++ b/tests/messengers/telegram/test_types.py @@ -1,4 +1,3 @@ -import os import json from io import IOBase from pathlib import Path @@ -11,9 +10,6 @@ except ImportError: pytest.skip(reason="`telegram` is not available", allow_module_level=True) -if "TG_BOT_TOKEN" not in os.environ: - pytest.skip(reason="Telegram token is not available", allow_module_level=True) - from pydantic import ValidationError from telebot import types From 6bf22e1895fab854bf4302187e896cfe1858d1b6 Mon Sep 17 00:00:00 2001 From: pseusys Date: Mon, 21 Aug 2023 11:00:30 +0200 Subject: [PATCH 08/16] test marked telegram --- tests/messengers/telegram/test_tutorials.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/messengers/telegram/test_tutorials.py b/tests/messengers/telegram/test_tutorials.py index 9e0215934..551f90c06 100644 --- a/tests/messengers/telegram/test_tutorials.py +++ b/tests/messengers/telegram/test_tutorials.py @@ -27,6 +27,7 @@ "3_buttons_with_callback", ], ) +@pytest.mark.telegram def test_client_tutorials_without_telegram(tutorial_module_name, env_vars): assert "TG_BOT_TOKEN" in env_vars tutorial_module = importlib.import_module(f"tutorials.{dot_path_to_addon}.{tutorial_module_name}") From 3031545e0b7bbc2e15a9429584bde69d20e3387e Mon Sep 17 00:00:00 2001 From: pseusys Date: Tue, 22 Aug 2023 03:46:00 +0200 Subject: [PATCH 09/16] tutorial skipping added --- tutorials/messengers/telegram/1_basic.py | 8 ++++++++ tutorials/messengers/telegram/2_buttons.py | 8 ++++++++ tutorials/messengers/telegram/3_buttons_with_callback.py | 8 ++++++++ tutorials/messengers/telegram/4_conditions.py | 8 ++++++++ tutorials/messengers/telegram/5_conditions_with_media.py | 8 ++++++++ tutorials/messengers/telegram/6_conditions_extras.py | 8 ++++++++ tutorials/messengers/telegram/7_polling_setup.py | 8 ++++++++ tutorials/messengers/telegram/8_webhook_setup.py | 8 ++++++++ 8 files changed, 64 insertions(+) diff --git a/tutorials/messengers/telegram/1_basic.py b/tutorials/messengers/telegram/1_basic.py index ea047d3c0..ad9bd8a6c 100644 --- a/tutorials/messengers/telegram/1_basic.py +++ b/tutorials/messengers/telegram/1_basic.py @@ -18,6 +18,14 @@ from dff.utils.testing.common import is_interactive_mode +try: + import pytest + if "TG_BOT_TOKEN" not in os.environ: + pytest.skip("`telegram` token not available.") +except ImportError: + pass + + # %% [markdown] """ In order to integrate your script with Telegram, you need an instance of diff --git a/tutorials/messengers/telegram/2_buttons.py b/tutorials/messengers/telegram/2_buttons.py index cd1ffd073..24eb2aa58 100644 --- a/tutorials/messengers/telegram/2_buttons.py +++ b/tutorials/messengers/telegram/2_buttons.py @@ -22,6 +22,14 @@ from dff.utils.testing.common import is_interactive_mode +try: + import pytest + if "TG_BOT_TOKEN" not in os.environ: + pytest.skip("`telegram` token not available.") +except ImportError: + pass + + # %% [markdown] """ To display or hide a keyboard, you can utilize the `ui` field of the `TelegramMessage` class. diff --git a/tutorials/messengers/telegram/3_buttons_with_callback.py b/tutorials/messengers/telegram/3_buttons_with_callback.py index e0288fd31..234f6c54a 100644 --- a/tutorials/messengers/telegram/3_buttons_with_callback.py +++ b/tutorials/messengers/telegram/3_buttons_with_callback.py @@ -23,6 +23,14 @@ from dff.utils.testing.common import is_interactive_mode +try: + import pytest + if "TG_BOT_TOKEN" not in os.environ: + pytest.skip("`telegram` token not available.") +except ImportError: + pass + + # %% [markdown] """ If you want to send an inline keyboard to your Telegram chat, diff --git a/tutorials/messengers/telegram/4_conditions.py b/tutorials/messengers/telegram/4_conditions.py index 02735b282..5fba55e39 100644 --- a/tutorials/messengers/telegram/4_conditions.py +++ b/tutorials/messengers/telegram/4_conditions.py @@ -21,6 +21,14 @@ from dff.utils.testing.common import is_interactive_mode +try: + import pytest + if "TG_BOT_TOKEN" not in os.environ: + pytest.skip("`telegram` token not available.") +except ImportError: + pass + + # %% [markdown] """ In our Telegram module, we adopted the system of filters diff --git a/tutorials/messengers/telegram/5_conditions_with_media.py b/tutorials/messengers/telegram/5_conditions_with_media.py index 83deacfc3..59891a976 100644 --- a/tutorials/messengers/telegram/5_conditions_with_media.py +++ b/tutorials/messengers/telegram/5_conditions_with_media.py @@ -22,6 +22,14 @@ from dff.utils.testing.common import is_interactive_mode +try: + import pytest + if "TG_BOT_TOKEN" not in os.environ: + pytest.skip("`telegram` token not available.") +except ImportError: + pass + + # %% picture_url = ( diff --git a/tutorials/messengers/telegram/6_conditions_extras.py b/tutorials/messengers/telegram/6_conditions_extras.py index 9e808572e..01af2f574 100644 --- a/tutorials/messengers/telegram/6_conditions_extras.py +++ b/tutorials/messengers/telegram/6_conditions_extras.py @@ -21,6 +21,14 @@ from dff.utils.testing.common import is_interactive_mode +try: + import pytest + if "TG_BOT_TOKEN" not in os.environ: + pytest.skip("`telegram` token not available.") +except ImportError: + pass + + # %% [markdown] """ In our Telegram module, we adopted the system of filters diff --git a/tutorials/messengers/telegram/7_polling_setup.py b/tutorials/messengers/telegram/7_polling_setup.py index 6880d411f..b6e9e6617 100644 --- a/tutorials/messengers/telegram/7_polling_setup.py +++ b/tutorials/messengers/telegram/7_polling_setup.py @@ -18,6 +18,14 @@ from telebot.util import update_types +try: + import pytest + if "TG_BOT_TOKEN" not in os.environ: + pytest.skip("`telegram` token not available.") +except ImportError: + pass + + # %% [markdown] """ `PollingTelegramInterface` can be configured with the same parameters diff --git a/tutorials/messengers/telegram/8_webhook_setup.py b/tutorials/messengers/telegram/8_webhook_setup.py index 98da6ae31..4b191b2a1 100644 --- a/tutorials/messengers/telegram/8_webhook_setup.py +++ b/tutorials/messengers/telegram/8_webhook_setup.py @@ -18,6 +18,14 @@ from dff.utils.testing.common import is_interactive_mode +try: + import pytest + if "TG_BOT_TOKEN" not in os.environ: + pytest.skip("`telegram` token not available.") +except ImportError: + pass + + # %% [markdown] """ To set up a webhook, you need a messenger and a web application instance. From 87da3fbee1a178b88a42295ed2ee91e9b5739911 Mon Sep 17 00:00:00 2001 From: pseusys Date: Fri, 25 Aug 2023 00:17:27 +0200 Subject: [PATCH 10/16] lint fixed --- tutorials/messengers/telegram/1_basic.py | 1 + tutorials/messengers/telegram/2_buttons.py | 1 + tutorials/messengers/telegram/3_buttons_with_callback.py | 1 + tutorials/messengers/telegram/4_conditions.py | 1 + tutorials/messengers/telegram/5_conditions_with_media.py | 1 + tutorials/messengers/telegram/6_conditions_extras.py | 1 + tutorials/messengers/telegram/7_polling_setup.py | 1 + tutorials/messengers/telegram/8_webhook_setup.py | 1 + 8 files changed, 8 insertions(+) diff --git a/tutorials/messengers/telegram/1_basic.py b/tutorials/messengers/telegram/1_basic.py index ad9bd8a6c..f889e1ca1 100644 --- a/tutorials/messengers/telegram/1_basic.py +++ b/tutorials/messengers/telegram/1_basic.py @@ -20,6 +20,7 @@ try: import pytest + if "TG_BOT_TOKEN" not in os.environ: pytest.skip("`telegram` token not available.") except ImportError: diff --git a/tutorials/messengers/telegram/2_buttons.py b/tutorials/messengers/telegram/2_buttons.py index 24eb2aa58..a2bc0695f 100644 --- a/tutorials/messengers/telegram/2_buttons.py +++ b/tutorials/messengers/telegram/2_buttons.py @@ -24,6 +24,7 @@ try: import pytest + if "TG_BOT_TOKEN" not in os.environ: pytest.skip("`telegram` token not available.") except ImportError: diff --git a/tutorials/messengers/telegram/3_buttons_with_callback.py b/tutorials/messengers/telegram/3_buttons_with_callback.py index 234f6c54a..365764cd4 100644 --- a/tutorials/messengers/telegram/3_buttons_with_callback.py +++ b/tutorials/messengers/telegram/3_buttons_with_callback.py @@ -25,6 +25,7 @@ try: import pytest + if "TG_BOT_TOKEN" not in os.environ: pytest.skip("`telegram` token not available.") except ImportError: diff --git a/tutorials/messengers/telegram/4_conditions.py b/tutorials/messengers/telegram/4_conditions.py index 5fba55e39..92347e46a 100644 --- a/tutorials/messengers/telegram/4_conditions.py +++ b/tutorials/messengers/telegram/4_conditions.py @@ -23,6 +23,7 @@ try: import pytest + if "TG_BOT_TOKEN" not in os.environ: pytest.skip("`telegram` token not available.") except ImportError: diff --git a/tutorials/messengers/telegram/5_conditions_with_media.py b/tutorials/messengers/telegram/5_conditions_with_media.py index 59891a976..e16a2cfd8 100644 --- a/tutorials/messengers/telegram/5_conditions_with_media.py +++ b/tutorials/messengers/telegram/5_conditions_with_media.py @@ -24,6 +24,7 @@ try: import pytest + if "TG_BOT_TOKEN" not in os.environ: pytest.skip("`telegram` token not available.") except ImportError: diff --git a/tutorials/messengers/telegram/6_conditions_extras.py b/tutorials/messengers/telegram/6_conditions_extras.py index 01af2f574..8d6387ea9 100644 --- a/tutorials/messengers/telegram/6_conditions_extras.py +++ b/tutorials/messengers/telegram/6_conditions_extras.py @@ -23,6 +23,7 @@ try: import pytest + if "TG_BOT_TOKEN" not in os.environ: pytest.skip("`telegram` token not available.") except ImportError: diff --git a/tutorials/messengers/telegram/7_polling_setup.py b/tutorials/messengers/telegram/7_polling_setup.py index b6e9e6617..db8d58b53 100644 --- a/tutorials/messengers/telegram/7_polling_setup.py +++ b/tutorials/messengers/telegram/7_polling_setup.py @@ -20,6 +20,7 @@ try: import pytest + if "TG_BOT_TOKEN" not in os.environ: pytest.skip("`telegram` token not available.") except ImportError: diff --git a/tutorials/messengers/telegram/8_webhook_setup.py b/tutorials/messengers/telegram/8_webhook_setup.py index 4b191b2a1..ef2c6f694 100644 --- a/tutorials/messengers/telegram/8_webhook_setup.py +++ b/tutorials/messengers/telegram/8_webhook_setup.py @@ -20,6 +20,7 @@ try: import pytest + if "TG_BOT_TOKEN" not in os.environ: pytest.skip("`telegram` token not available.") except ImportError: From b41ebff2a3210a2cf37fa378e5d87593752684ff Mon Sep 17 00:00:00 2001 From: pseusys Date: Fri, 25 Aug 2023 00:26:50 +0200 Subject: [PATCH 11/16] tutorial test venv skip allowed --- tests/tutorials/test_tutorials.py | 2 +- tutorials/messengers/telegram/1_basic.py | 2 +- tutorials/messengers/telegram/2_buttons.py | 2 +- tutorials/messengers/telegram/3_buttons_with_callback.py | 2 +- tutorials/messengers/telegram/4_conditions.py | 2 +- tutorials/messengers/telegram/5_conditions_with_media.py | 2 +- tutorials/messengers/telegram/6_conditions_extras.py | 2 +- tutorials/messengers/telegram/7_polling_setup.py | 2 +- tutorials/messengers/telegram/8_webhook_setup.py | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/tutorials/test_tutorials.py b/tests/tutorials/test_tutorials.py index d21ad1b6f..f19d97dfa 100644 --- a/tests/tutorials/test_tutorials.py +++ b/tests/tutorials/test_tutorials.py @@ -31,7 +31,7 @@ def check_tutorial_dependencies(venv: "VirtualEnv", tutorial_source_code: str): fd.write(tutorial_source_code) for deps in re.findall(InstallationCell.pattern, tutorial_source_code): - venv.run(f"python -m pip install {deps}", check_rc=True) + venv.run(f"python -m pip install {deps} pytest", check_rc=True) venv.run(f"python {tutorial_path}", check_rc=True) diff --git a/tutorials/messengers/telegram/1_basic.py b/tutorials/messengers/telegram/1_basic.py index 5b2cd9f70..cadc35428 100644 --- a/tutorials/messengers/telegram/1_basic.py +++ b/tutorials/messengers/telegram/1_basic.py @@ -23,7 +23,7 @@ import pytest if "TG_BOT_TOKEN" not in os.environ: - pytest.skip("`telegram` token not available.") + pytest.skip("`telegram` token not available.", allow_module_level=True) except ImportError: pass diff --git a/tutorials/messengers/telegram/2_buttons.py b/tutorials/messengers/telegram/2_buttons.py index 764483579..73847eff4 100644 --- a/tutorials/messengers/telegram/2_buttons.py +++ b/tutorials/messengers/telegram/2_buttons.py @@ -28,7 +28,7 @@ import pytest if "TG_BOT_TOKEN" not in os.environ: - pytest.skip("`telegram` token not available.") + pytest.skip("`telegram` token not available.", allow_module_level=True) except ImportError: pass diff --git a/tutorials/messengers/telegram/3_buttons_with_callback.py b/tutorials/messengers/telegram/3_buttons_with_callback.py index 4b422891c..e0306407b 100644 --- a/tutorials/messengers/telegram/3_buttons_with_callback.py +++ b/tutorials/messengers/telegram/3_buttons_with_callback.py @@ -29,7 +29,7 @@ import pytest if "TG_BOT_TOKEN" not in os.environ: - pytest.skip("`telegram` token not available.") + pytest.skip("`telegram` token not available.", allow_module_level=True) except ImportError: pass diff --git a/tutorials/messengers/telegram/4_conditions.py b/tutorials/messengers/telegram/4_conditions.py index eedde2668..40b756260 100644 --- a/tutorials/messengers/telegram/4_conditions.py +++ b/tutorials/messengers/telegram/4_conditions.py @@ -27,7 +27,7 @@ import pytest if "TG_BOT_TOKEN" not in os.environ: - pytest.skip("`telegram` token not available.") + pytest.skip("`telegram` token not available.", allow_module_level=True) except ImportError: pass diff --git a/tutorials/messengers/telegram/5_conditions_with_media.py b/tutorials/messengers/telegram/5_conditions_with_media.py index 6f3c968e6..c0c8ae820 100644 --- a/tutorials/messengers/telegram/5_conditions_with_media.py +++ b/tutorials/messengers/telegram/5_conditions_with_media.py @@ -28,7 +28,7 @@ import pytest if "TG_BOT_TOKEN" not in os.environ: - pytest.skip("`telegram` token not available.") + pytest.skip("`telegram` token not available.", allow_module_level=True) except ImportError: pass diff --git a/tutorials/messengers/telegram/6_conditions_extras.py b/tutorials/messengers/telegram/6_conditions_extras.py index dda99176c..5a0e3598e 100644 --- a/tutorials/messengers/telegram/6_conditions_extras.py +++ b/tutorials/messengers/telegram/6_conditions_extras.py @@ -27,7 +27,7 @@ import pytest if "TG_BOT_TOKEN" not in os.environ: - pytest.skip("`telegram` token not available.") + pytest.skip("`telegram` token not available.", allow_module_level=True) except ImportError: pass diff --git a/tutorials/messengers/telegram/7_polling_setup.py b/tutorials/messengers/telegram/7_polling_setup.py index 8b9354400..bbf4eb0fb 100644 --- a/tutorials/messengers/telegram/7_polling_setup.py +++ b/tutorials/messengers/telegram/7_polling_setup.py @@ -23,7 +23,7 @@ import pytest if "TG_BOT_TOKEN" not in os.environ: - pytest.skip("`telegram` token not available.") + pytest.skip("`telegram` token not available.", allow_module_level=True) except ImportError: pass diff --git a/tutorials/messengers/telegram/8_webhook_setup.py b/tutorials/messengers/telegram/8_webhook_setup.py index 9a2c03ddc..588e57eeb 100644 --- a/tutorials/messengers/telegram/8_webhook_setup.py +++ b/tutorials/messengers/telegram/8_webhook_setup.py @@ -23,7 +23,7 @@ import pytest if "TG_BOT_TOKEN" not in os.environ: - pytest.skip("`telegram` token not available.") + pytest.skip("`telegram` token not available.", allow_module_level=True) except ImportError: pass From 5b30499f147e4145851b28cb542e3f25aa045d0d Mon Sep 17 00:00:00 2001 From: pseusys Date: Fri, 25 Aug 2023 00:41:14 +0200 Subject: [PATCH 12/16] telegram tutorial ends --- tests/tutorials/test_tutorials.py | 2 +- tutorials/messengers/telegram/1_basic.py | 10 +++------- tutorials/messengers/telegram/2_buttons.py | 10 +++------- .../messengers/telegram/3_buttons_with_callback.py | 10 +++------- tutorials/messengers/telegram/4_conditions.py | 10 +++------- .../messengers/telegram/5_conditions_with_media.py | 10 +++------- tutorials/messengers/telegram/6_conditions_extras.py | 10 +++------- tutorials/messengers/telegram/7_polling_setup.py | 10 +++------- tutorials/messengers/telegram/8_webhook_setup.py | 10 +++------- 9 files changed, 25 insertions(+), 57 deletions(-) diff --git a/tests/tutorials/test_tutorials.py b/tests/tutorials/test_tutorials.py index f19d97dfa..d21ad1b6f 100644 --- a/tests/tutorials/test_tutorials.py +++ b/tests/tutorials/test_tutorials.py @@ -31,7 +31,7 @@ def check_tutorial_dependencies(venv: "VirtualEnv", tutorial_source_code: str): fd.write(tutorial_source_code) for deps in re.findall(InstallationCell.pattern, tutorial_source_code): - venv.run(f"python -m pip install {deps} pytest", check_rc=True) + venv.run(f"python -m pip install {deps}", check_rc=True) venv.run(f"python {tutorial_path}", check_rc=True) diff --git a/tutorials/messengers/telegram/1_basic.py b/tutorials/messengers/telegram/1_basic.py index cadc35428..f811a4bf1 100644 --- a/tutorials/messengers/telegram/1_basic.py +++ b/tutorials/messengers/telegram/1_basic.py @@ -19,13 +19,9 @@ from dff.utils.testing.common import is_interactive_mode -try: - import pytest - - if "TG_BOT_TOKEN" not in os.environ: - pytest.skip("`telegram` token not available.", allow_module_level=True) -except ImportError: - pass +if "TG_BOT_TOKEN" not in os.environ: + print("`telegram` token not available.") + exit(0) # %% [markdown] diff --git a/tutorials/messengers/telegram/2_buttons.py b/tutorials/messengers/telegram/2_buttons.py index 73847eff4..f159f690c 100644 --- a/tutorials/messengers/telegram/2_buttons.py +++ b/tutorials/messengers/telegram/2_buttons.py @@ -24,13 +24,9 @@ from dff.utils.testing.common import is_interactive_mode -try: - import pytest - - if "TG_BOT_TOKEN" not in os.environ: - pytest.skip("`telegram` token not available.", allow_module_level=True) -except ImportError: - pass +if "TG_BOT_TOKEN" not in os.environ: + print("`telegram` token not available.") + exit(0) # %% [markdown] diff --git a/tutorials/messengers/telegram/3_buttons_with_callback.py b/tutorials/messengers/telegram/3_buttons_with_callback.py index e0306407b..610b4143f 100644 --- a/tutorials/messengers/telegram/3_buttons_with_callback.py +++ b/tutorials/messengers/telegram/3_buttons_with_callback.py @@ -25,13 +25,9 @@ from dff.utils.testing.common import is_interactive_mode -try: - import pytest - - if "TG_BOT_TOKEN" not in os.environ: - pytest.skip("`telegram` token not available.", allow_module_level=True) -except ImportError: - pass +if "TG_BOT_TOKEN" not in os.environ: + print("`telegram` token not available.") + exit(0) # %% [markdown] diff --git a/tutorials/messengers/telegram/4_conditions.py b/tutorials/messengers/telegram/4_conditions.py index 40b756260..3afcf040e 100644 --- a/tutorials/messengers/telegram/4_conditions.py +++ b/tutorials/messengers/telegram/4_conditions.py @@ -23,13 +23,9 @@ from dff.utils.testing.common import is_interactive_mode -try: - import pytest - - if "TG_BOT_TOKEN" not in os.environ: - pytest.skip("`telegram` token not available.", allow_module_level=True) -except ImportError: - pass +if "TG_BOT_TOKEN" not in os.environ: + print("`telegram` token not available.") + exit(0) # %% [markdown] diff --git a/tutorials/messengers/telegram/5_conditions_with_media.py b/tutorials/messengers/telegram/5_conditions_with_media.py index c0c8ae820..b47135f6f 100644 --- a/tutorials/messengers/telegram/5_conditions_with_media.py +++ b/tutorials/messengers/telegram/5_conditions_with_media.py @@ -24,13 +24,9 @@ from dff.utils.testing.common import is_interactive_mode -try: - import pytest - - if "TG_BOT_TOKEN" not in os.environ: - pytest.skip("`telegram` token not available.", allow_module_level=True) -except ImportError: - pass +if "TG_BOT_TOKEN" not in os.environ: + print("`telegram` token not available.") + exit(0) # %% diff --git a/tutorials/messengers/telegram/6_conditions_extras.py b/tutorials/messengers/telegram/6_conditions_extras.py index 5a0e3598e..e33742d76 100644 --- a/tutorials/messengers/telegram/6_conditions_extras.py +++ b/tutorials/messengers/telegram/6_conditions_extras.py @@ -23,13 +23,9 @@ from dff.utils.testing.common import is_interactive_mode -try: - import pytest - - if "TG_BOT_TOKEN" not in os.environ: - pytest.skip("`telegram` token not available.", allow_module_level=True) -except ImportError: - pass +if "TG_BOT_TOKEN" not in os.environ: + print("`telegram` token not available.") + exit(0) # %% [markdown] diff --git a/tutorials/messengers/telegram/7_polling_setup.py b/tutorials/messengers/telegram/7_polling_setup.py index bbf4eb0fb..bd3aff2f1 100644 --- a/tutorials/messengers/telegram/7_polling_setup.py +++ b/tutorials/messengers/telegram/7_polling_setup.py @@ -19,13 +19,9 @@ from telebot.util import update_types -try: - import pytest - - if "TG_BOT_TOKEN" not in os.environ: - pytest.skip("`telegram` token not available.", allow_module_level=True) -except ImportError: - pass +if "TG_BOT_TOKEN" not in os.environ: + print("`telegram` token not available.") + exit(0) # %% [markdown] diff --git a/tutorials/messengers/telegram/8_webhook_setup.py b/tutorials/messengers/telegram/8_webhook_setup.py index 588e57eeb..ab2208af5 100644 --- a/tutorials/messengers/telegram/8_webhook_setup.py +++ b/tutorials/messengers/telegram/8_webhook_setup.py @@ -19,13 +19,9 @@ from dff.utils.testing.common import is_interactive_mode -try: - import pytest - - if "TG_BOT_TOKEN" not in os.environ: - pytest.skip("`telegram` token not available.", allow_module_level=True) -except ImportError: - pass +if "TG_BOT_TOKEN" not in os.environ: + print("`telegram` token not available.") + exit(0) # %% [markdown] From d8e9b2c8588a959be512c5e8d976ea4e69c63954 Mon Sep 17 00:00:00 2001 From: pseusys Date: Fri, 25 Aug 2023 11:19:18 +0200 Subject: [PATCH 13/16] telegram tokens in gh actions --- .github/workflows/test_coverage.yml | 7 ++++++- .github/workflows/test_full.yml | 14 ++++++++++++-- tutorials/messengers/telegram/1_basic.py | 5 ----- tutorials/messengers/telegram/2_buttons.py | 5 ----- .../messengers/telegram/3_buttons_with_callback.py | 5 ----- tutorials/messengers/telegram/4_conditions.py | 5 ----- .../messengers/telegram/5_conditions_with_media.py | 5 ----- .../messengers/telegram/6_conditions_extras.py | 5 ----- tutorials/messengers/telegram/7_polling_setup.py | 5 ----- tutorials/messengers/telegram/8_webhook_setup.py | 5 ----- 10 files changed, 18 insertions(+), 43 deletions(-) diff --git a/.github/workflows/test_coverage.yml b/.github/workflows/test_coverage.yml index 16416d9d6..2caf129cc 100644 --- a/.github/workflows/test_coverage.yml +++ b/.github/workflows/test_coverage.yml @@ -50,5 +50,10 @@ jobs: touch venv # disable venv target - name: run tests + env: + TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }} + TG_API_ID: ${{ secrets.TG_API_ID }} + TG_API_HASH: ${{ secrets.TG_API_HASH }} + TG_BOT_USERNAME: ${{ secrets.TG_BOT_USERNAME }} run: | - make test TEST_ALLOW_SKIP=telegram + make test diff --git a/.github/workflows/test_full.yml b/.github/workflows/test_full.yml index 66134f756..f47db78e8 100644 --- a/.github/workflows/test_full.yml +++ b/.github/workflows/test_full.yml @@ -43,12 +43,17 @@ jobs: shell: bash - name: run pytest + env: + TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }} + TG_API_ID: ${{ secrets.TG_API_ID }} + TG_API_HASH: ${{ secrets.TG_API_HASH }} + TG_BOT_USERNAME: ${{ secrets.TG_BOT_USERNAME }} run: | if [ "$RUNNER_OS" == "Linux" ]; then source <(cat .env_file | sed 's/=/=/' | sed 's/^/export /') - pytest --tb=long -vv --cache-clear --no-cov --allow-skip=telegram tests/ + pytest --tb=long -vv --cache-clear --no-cov tests/ else - pytest -m "not docker" --tb=long -vv --cache-clear --no-cov --allow-skip=telegram,docker tests/ + pytest -m "not docker" --tb=long -vv --cache-clear --no-cov --allow-skip=docker tests/ fi shell: bash test_no_deps: @@ -72,6 +77,11 @@ jobs: shell: bash - name: run pytest + env: + TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }} + TG_API_ID: ${{ secrets.TG_API_ID }} + TG_API_HASH: ${{ secrets.TG_API_HASH }} + TG_BOT_USERNAME: ${{ secrets.TG_BOT_USERNAME }} run: | source <(cat .env_file | sed 's/=/=/' | sed 's/^/export /') pytest --tb=long -vv --cache-clear --no-cov --allow-skip=all tests/ diff --git a/tutorials/messengers/telegram/1_basic.py b/tutorials/messengers/telegram/1_basic.py index f811a4bf1..81855bde5 100644 --- a/tutorials/messengers/telegram/1_basic.py +++ b/tutorials/messengers/telegram/1_basic.py @@ -19,11 +19,6 @@ from dff.utils.testing.common import is_interactive_mode -if "TG_BOT_TOKEN" not in os.environ: - print("`telegram` token not available.") - exit(0) - - # %% [markdown] """ In order to integrate your script with Telegram, you need an instance of diff --git a/tutorials/messengers/telegram/2_buttons.py b/tutorials/messengers/telegram/2_buttons.py index f159f690c..d395c75e1 100644 --- a/tutorials/messengers/telegram/2_buttons.py +++ b/tutorials/messengers/telegram/2_buttons.py @@ -24,11 +24,6 @@ from dff.utils.testing.common import is_interactive_mode -if "TG_BOT_TOKEN" not in os.environ: - print("`telegram` token not available.") - exit(0) - - # %% [markdown] """ To display or hide a keyboard, you can utilize the `ui` field of the `TelegramMessage` class. diff --git a/tutorials/messengers/telegram/3_buttons_with_callback.py b/tutorials/messengers/telegram/3_buttons_with_callback.py index 610b4143f..c3ecf4d70 100644 --- a/tutorials/messengers/telegram/3_buttons_with_callback.py +++ b/tutorials/messengers/telegram/3_buttons_with_callback.py @@ -25,11 +25,6 @@ from dff.utils.testing.common import is_interactive_mode -if "TG_BOT_TOKEN" not in os.environ: - print("`telegram` token not available.") - exit(0) - - # %% [markdown] """ If you want to send an inline keyboard to your Telegram chat, diff --git a/tutorials/messengers/telegram/4_conditions.py b/tutorials/messengers/telegram/4_conditions.py index 3afcf040e..1a49b2f09 100644 --- a/tutorials/messengers/telegram/4_conditions.py +++ b/tutorials/messengers/telegram/4_conditions.py @@ -23,11 +23,6 @@ from dff.utils.testing.common import is_interactive_mode -if "TG_BOT_TOKEN" not in os.environ: - print("`telegram` token not available.") - exit(0) - - # %% [markdown] """ In our Telegram module, we adopted the system of filters diff --git a/tutorials/messengers/telegram/5_conditions_with_media.py b/tutorials/messengers/telegram/5_conditions_with_media.py index b47135f6f..49c02f921 100644 --- a/tutorials/messengers/telegram/5_conditions_with_media.py +++ b/tutorials/messengers/telegram/5_conditions_with_media.py @@ -24,11 +24,6 @@ from dff.utils.testing.common import is_interactive_mode -if "TG_BOT_TOKEN" not in os.environ: - print("`telegram` token not available.") - exit(0) - - # %% picture_url = ( diff --git a/tutorials/messengers/telegram/6_conditions_extras.py b/tutorials/messengers/telegram/6_conditions_extras.py index e33742d76..bc1ef5e6a 100644 --- a/tutorials/messengers/telegram/6_conditions_extras.py +++ b/tutorials/messengers/telegram/6_conditions_extras.py @@ -23,11 +23,6 @@ from dff.utils.testing.common import is_interactive_mode -if "TG_BOT_TOKEN" not in os.environ: - print("`telegram` token not available.") - exit(0) - - # %% [markdown] """ In our Telegram module, we adopted the system of filters diff --git a/tutorials/messengers/telegram/7_polling_setup.py b/tutorials/messengers/telegram/7_polling_setup.py index bd3aff2f1..68a2b1f0a 100644 --- a/tutorials/messengers/telegram/7_polling_setup.py +++ b/tutorials/messengers/telegram/7_polling_setup.py @@ -19,11 +19,6 @@ from telebot.util import update_types -if "TG_BOT_TOKEN" not in os.environ: - print("`telegram` token not available.") - exit(0) - - # %% [markdown] """ `PollingTelegramInterface` can be configured with the same parameters diff --git a/tutorials/messengers/telegram/8_webhook_setup.py b/tutorials/messengers/telegram/8_webhook_setup.py index ab2208af5..709cf5e3e 100644 --- a/tutorials/messengers/telegram/8_webhook_setup.py +++ b/tutorials/messengers/telegram/8_webhook_setup.py @@ -19,11 +19,6 @@ from dff.utils.testing.common import is_interactive_mode -if "TG_BOT_TOKEN" not in os.environ: - print("`telegram` token not available.") - exit(0) - - # %% [markdown] """ To set up a webhook, you need a messenger and a web application instance. From b53df8886a98645f24b52a286c64307d516f68a0 Mon Sep 17 00:00:00 2001 From: pseusys Date: Fri, 25 Aug 2023 11:36:42 +0200 Subject: [PATCH 14/16] all skips allowed --- .github/workflows/test_coverage.yml | 2 +- .github/workflows/test_full.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_coverage.yml b/.github/workflows/test_coverage.yml index 2caf129cc..b1d91e381 100644 --- a/.github/workflows/test_coverage.yml +++ b/.github/workflows/test_coverage.yml @@ -56,4 +56,4 @@ jobs: TG_API_HASH: ${{ secrets.TG_API_HASH }} TG_BOT_USERNAME: ${{ secrets.TG_BOT_USERNAME }} run: | - make test + make test TEST_ALLOW_SKIP=telegram diff --git a/.github/workflows/test_full.yml b/.github/workflows/test_full.yml index f47db78e8..4e7a24bb1 100644 --- a/.github/workflows/test_full.yml +++ b/.github/workflows/test_full.yml @@ -51,9 +51,9 @@ jobs: run: | if [ "$RUNNER_OS" == "Linux" ]; then source <(cat .env_file | sed 's/=/=/' | sed 's/^/export /') - pytest --tb=long -vv --cache-clear --no-cov tests/ + pytest --tb=long -vv --cache-clear --no-cov --allow-skip=telegram tests/ else - pytest -m "not docker" --tb=long -vv --cache-clear --no-cov --allow-skip=docker tests/ + pytest -m "not docker" --tb=long -vv --cache-clear --no-cov --allow-skip=telegram,docker tests/ fi shell: bash test_no_deps: From 648b8748fa44972f3042f696efa0169c8498c0a6 Mon Sep 17 00:00:00 2001 From: pseusys Date: Wed, 30 Aug 2023 08:24:42 +0200 Subject: [PATCH 15/16] review comments fixed --- tests/messengers/telegram/test_tutorials.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/messengers/telegram/test_tutorials.py b/tests/messengers/telegram/test_tutorials.py index 551f90c06..c92e0e048 100644 --- a/tests/messengers/telegram/test_tutorials.py +++ b/tests/messengers/telegram/test_tutorials.py @@ -27,9 +27,7 @@ "3_buttons_with_callback", ], ) -@pytest.mark.telegram def test_client_tutorials_without_telegram(tutorial_module_name, env_vars): - assert "TG_BOT_TOKEN" in env_vars tutorial_module = importlib.import_module(f"tutorials.{dot_path_to_addon}.{tutorial_module_name}") pipeline = tutorial_module.pipeline happy_path = tutorial_module.happy_path From 47af721aafd6c367b8088dae55dde9f155a2dba2 Mon Sep 17 00:00:00 2001 From: pseusys Date: Tue, 5 Sep 2023 11:25:22 +0200 Subject: [PATCH 16/16] docker marker order reverted --- tests/context_storages/test_dbs.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/context_storages/test_dbs.py b/tests/context_storages/test_dbs.py index 296e9b779..de39c39dc 100644 --- a/tests/context_storages/test_dbs.py +++ b/tests/context_storages/test_dbs.py @@ -121,9 +121,9 @@ def test_pickle(testing_file, testing_context, context_id): asyncio.run(delete_pickle(db)) -@pytest.mark.docker @pytest.mark.skipif(not MONGO_ACTIVE, reason="Mongodb server is not running") @pytest.mark.skipif(not mongo_available, reason="Mongodb dependencies missing") +@pytest.mark.docker def test_mongo(testing_context, context_id): if system() == "Windows": pytest.skip() @@ -139,18 +139,18 @@ def test_mongo(testing_context, context_id): asyncio.run(delete_mongo(db)) -@pytest.mark.docker @pytest.mark.skipif(not REDIS_ACTIVE, reason="Redis server is not running") @pytest.mark.skipif(not redis_available, reason="Redis dependencies missing") +@pytest.mark.docker def test_redis(testing_context, context_id): db = context_storage_factory("redis://{}:{}@localhost:6379/{}".format("", os.environ["REDIS_PASSWORD"], "0")) generic_test(db, testing_context, context_id) asyncio.run(delete_redis(db)) -@pytest.mark.docker @pytest.mark.skipif(not POSTGRES_ACTIVE, reason="Postgres server is not running") @pytest.mark.skipif(not postgres_available, reason="Postgres dependencies missing") +@pytest.mark.docker def test_postgres(testing_context, context_id): db = context_storage_factory( "postgresql+asyncpg://{}:{}@localhost:5432/{}".format( @@ -171,9 +171,9 @@ def test_sqlite(testing_file, testing_context, context_id): asyncio.run(delete_sql(db)) -@pytest.mark.docker @pytest.mark.skipif(not MYSQL_ACTIVE, reason="Mysql server is not running") @pytest.mark.skipif(not mysql_available, reason="Mysql dependencies missing") +@pytest.mark.docker def test_mysql(testing_context, context_id): db = context_storage_factory( "mysql+asyncmy://{}:{}@localhost:3307/{}".format( @@ -186,9 +186,9 @@ def test_mysql(testing_context, context_id): asyncio.run(delete_sql(db)) -@pytest.mark.docker @pytest.mark.skipif(not YDB_ACTIVE, reason="YQL server not running") @pytest.mark.skipif(not ydb_available, reason="YDB dependencies missing") +@pytest.mark.docker def test_ydb(testing_context, context_id): db = context_storage_factory( "{}{}".format(