2121import time
2222import datetime as dtm
2323from collections import defaultdict
24- from pathlib import Path
2524from platform import python_implementation
2625
2726import pytest
5958from telegram .ext import ExtBot , InvalidCallbackData
6059from telegram .error import BadRequest , InvalidToken , NetworkError , RetryAfter , TelegramError
6160from telegram ._utils .datetime import from_timestamp , to_timestamp
62- from telegram .helpers import escape_markdown
6361from telegram ._utils .defaultvalue import DefaultValue
64- from tests .conftest import expect_bad_request , check_defaults_handling , GITHUB_ACTION , build_kwargs
62+ from telegram .helpers import escape_markdown
63+ from tests .conftest import (
64+ expect_bad_request ,
65+ check_defaults_handling ,
66+ GITHUB_ACTION ,
67+ build_kwargs ,
68+ data_file ,
69+ )
6570from tests .bots import FALLBACKS
6671
6772
@@ -99,7 +104,7 @@ def message(bot, chat_id):
99104
100105@pytest .fixture (scope = 'class' )
101106def media_message (bot , chat_id ):
102- with Path ( 'tests/data/ telegram.ogg' ).open ('rb' ) as f :
107+ with data_file ( ' telegram.ogg' ).open ('rb' ) as f :
103108 return bot .send_voice (chat_id , voice = f , caption = 'my caption' , timeout = 10 )
104109
105110
@@ -1039,7 +1044,7 @@ def test_get_one_user_profile_photo(self, bot, chat_id):
10391044 # get_file is tested multiple times in the test_*media* modules.
10401045 # Here we only test the behaviour for bot apis in local mode
10411046 def test_get_file_local_mode (self , bot , monkeypatch ):
1042- path = str (Path . cwd () / 'tests' / 'data' / ' game.gif' )
1047+ path = str (data_file ( ' game.gif') )
10431048
10441049 def _post (* args , ** kwargs ):
10451050 return {
@@ -1924,14 +1929,14 @@ def test_set_chat_photo(self, bot, channel_id):
19241929 def func ():
19251930 assert bot .set_chat_photo (channel_id , f )
19261931
1927- with Path ( 'tests/data/ telegram_test_channel.jpg' ).open ('rb' ) as f :
1932+ with data_file ( ' telegram_test_channel.jpg' ).open ('rb' ) as f :
19281933 expect_bad_request (func , 'Type of file mismatch' , 'Telegram did not accept the file.' )
19291934
19301935 def test_set_chat_photo_local_files (self , monkeypatch , bot , chat_id ):
19311936 # For just test that the correct paths are passed as we have no local bot API set up
19321937 test_flag = False
1933- expected = ( Path . cwd () / 'tests/data/ telegram.jpg/' ). as_uri ( )
1934- file = 'tests/data/telegram.jpg'
1938+ file = data_file ( ' telegram.jpg' )
1939+ expected = file . as_uri ()
19351940
19361941 def make_assertion (_ , data , * args , ** kwargs ):
19371942 nonlocal test_flag
@@ -2008,7 +2013,7 @@ def request_wrapper(*args, **kwargs):
20082013
20092014 # Test file uploading
20102015 with pytest .raises (OkException ):
2011- bot .send_photo (chat_id , open ( 'tests/data/ telegram.jpg', 'rb' ), timeout = TIMEOUT )
2016+ bot .send_photo (chat_id , data_file ( ' telegram.jpg'). open ( 'rb' ), timeout = TIMEOUT )
20122017
20132018 # Test JSON submission
20142019 with pytest .raises (OkException ):
@@ -2032,7 +2037,7 @@ def request_wrapper(*args, **kwargs):
20322037
20332038 # Test file uploading
20342039 with pytest .raises (OkException ):
2035- bot .send_photo (chat_id , open ( 'tests/data/ telegram.jpg', 'rb' ))
2040+ bot .send_photo (chat_id , data_file ( ' telegram.jpg'). open ( 'rb' ))
20362041
20372042 @flaky (3 , 1 )
20382043 def test_send_message_entities (self , bot , chat_id ):
0 commit comments