Skip to content

Commit

Permalink
Fix pipeline for readme example
Browse files Browse the repository at this point in the history
  • Loading branch information
Joscha Götzer committed Oct 25, 2020
1 parent 3c0bff0 commit 9c3cba2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
38 changes: 22 additions & 16 deletions examples/readme_example/readmeexample.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,30 @@

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

client = Client(
"tgintegration_examples",
workdir=examples_dir,
config_file=examples_dir / "config.ini",
)

controller = BotController(
peer="@BotListBot", # We are going to run tests on https://t.me/BotListBot
client=client,
max_wait=8, # Maximum timeout for responses (optional)
wait_consecutive=2, # Minimum time to wait for more/consecutive messages (optional)
raise_no_response=True, # Raise `InvalidResponseError` when no response received (defaults to True)
global_action_delay=2.5, # Choosing a rather high delay so we can follow along in realtime (optional)
)

# This example uses the configuration of `config.ini` (see examples/README)
def create_client(session_name: str = SESSION_NAME) -> Client:
client = Client(
session_name=session_name,
workdir=examples_dir,
config_file=examples_dir / "config.ini",
)
client.load_config()
return client


async def run_example(client: Client):
controller = BotController(
peer="@BotListBot", # We are going to run tests on https://t.me/BotListBot
client=client,
max_wait=8, # Maximum timeout for responses (optional)
wait_consecutive=2, # Minimum time to wait for more/consecutive messages (optional)
raise_no_response=True, # Raise `InvalidResponseError` when no response received (defaults to True)
global_action_delay=2.5, # Choosing a rather high delay so we can follow along in realtime (optional)
)

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

Expand Down Expand Up @@ -80,4 +86,4 @@ async def run_example():


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(run_example())
asyncio.get_event_loop().run_until_complete(run_example(create_client()))
3 changes: 2 additions & 1 deletion tests/integration/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ async def test_readme_example(session_name):
# Late import so that the autouse fixtures run first
from examples.readme_example import readmeexample

await readmeexample.run_example()
client = readmeexample.create_client(session_name)
await readmeexample.run_example(client)

0 comments on commit 9c3cba2

Please sign in to comment.