Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 9c3cba2

Browse files
author
Joscha Götzer
committed
Fix pipeline for readme example
1 parent 3c0bff0 commit 9c3cba2

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

examples/readme_example/readmeexample.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,30 @@
1111

1212
# This example uses the configuration of `config.ini` (see examples/README)
1313
examples_dir = Path(__file__).parent.parent.absolute()
14+
SESSION_NAME: str = "tgintegration_examples"
1415

15-
client = Client(
16-
"tgintegration_examples",
17-
workdir=examples_dir,
18-
config_file=examples_dir / "config.ini",
19-
)
20-
21-
controller = BotController(
22-
peer="@BotListBot", # We are going to run tests on https://t.me/BotListBot
23-
client=client,
24-
max_wait=8, # Maximum timeout for responses (optional)
25-
wait_consecutive=2, # Minimum time to wait for more/consecutive messages (optional)
26-
raise_no_response=True, # Raise `InvalidResponseError` when no response received (defaults to True)
27-
global_action_delay=2.5, # Choosing a rather high delay so we can follow along in realtime (optional)
28-
)
2916

17+
# This example uses the configuration of `config.ini` (see examples/README)
18+
def create_client(session_name: str = SESSION_NAME) -> Client:
19+
client = Client(
20+
session_name=session_name,
21+
workdir=examples_dir,
22+
config_file=examples_dir / "config.ini",
23+
)
24+
client.load_config()
25+
return client
26+
27+
28+
async def run_example(client: Client):
29+
controller = BotController(
30+
peer="@BotListBot", # We are going to run tests on https://t.me/BotListBot
31+
client=client,
32+
max_wait=8, # Maximum timeout for responses (optional)
33+
wait_consecutive=2, # Minimum time to wait for more/consecutive messages (optional)
34+
raise_no_response=True, # Raise `InvalidResponseError` when no response received (defaults to True)
35+
global_action_delay=2.5, # Choosing a rather high delay so we can follow along in realtime (optional)
36+
)
3037

31-
async def run_example():
3238
print("Clearing chat to start with a blank screen...")
3339
await controller.clear_chat()
3440

@@ -80,4 +86,4 @@ async def run_example():
8086

8187

8288
if __name__ == "__main__":
83-
asyncio.get_event_loop().run_until_complete(run_example())
89+
asyncio.get_event_loop().run_until_complete(run_example(create_client()))

tests/integration/test_examples.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ async def test_readme_example(session_name):
5656
# Late import so that the autouse fixtures run first
5757
from examples.readme_example import readmeexample
5858

59-
await readmeexample.run_example()
59+
client = readmeexample.create_client(session_name)
60+
await readmeexample.run_example(client)

0 commit comments

Comments
 (0)