Skip to main content

Library telemulator3

GitHub Workflow Status GitHub Workflow Status Codacy Badge Codacy Badge

The free, open-source telemulator3 library designed to simplify automatic testing of Telegram bots created using the pyTelegramBotAPI library.

The telemulator3 library partially emulates the Telegram Bot API in unit tests and allows you to create typical scenarios for the interaction of your bot with the Telegram Bot API.

Installation

pip install telemulator3

Usage

Create TeleBot instance and start emulate Telegram API for bot.

from telebot import TeleBot
from telemulator3 import Telemulator

bot = TeleBot('xxx-yyy-zzz', threaded=False)

@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
    bot.reply_to(message, "Howdy, how are you doing?")

telemul = Telemulator()
telemul.set_tested_bot(bot, username='my_bot', name='My Bot')

At start, there are no registered users in emulated API.

assert not telemul.api.users

Make API user, that represent our bot. It's a first registered user.

mybot = telemul.api.get_me()
assert mybot.is_bot
assert mybot.username == 'my_bot'
assert len(telemul.api.users) == 1

New user open private chat with bot and send /start command. Bot must answer as defined and his answer must be in chat history.

from telemulator3 import send_command

user = telemul.api.create_user('User')
chat = user.private()
send_command(chat, '/start', user)
assert chat.history.contain('Howdy, how are you doing?')

User create group and add bot as member.

group = user.create_group('My group')
group.add_members(user, [mybot])
assert group.history.contain('invite new members:')

And so on.

mybot.leave(group)
assert group.history.contain('My Bot (ID 1) left chat')
# group.history.dump()

Development

git clone git@github.com:vb64/telemulator3
cd telemulator3
make setup PYTHON_BIN=/path/to/python3
make tests

Metadata

Release files for telemulator3 1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for telemulator3 1.5
File Size Uploaded
telemulator3-1.5.tar.gz 20.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for telemulator3 1.5
File Interpreter ABI Platform
telemulator3-1.5-py3-none-any.whl Python 3 none any Details

Total release size: 50.8 kB

Release files / telemulator3-1.5.tar.gz

Download URL telemulator3-1.5.tar.gz
Size 20.3 kB
Tags Source
SHA-256 checksum
How to use checksums
130e40a8ab1ca7f90b631659da306bb6cbfa1d682b664244621a3361dea02f43
BLAKE2b-256 checksum
How to use checksums
4b28a8f0015f0692beb1e51ee067deeac93c0bc40910393dc02822ac09e28288
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / telemulator3-1.5-py3-none-any.whl

Download URL telemulator3-1.5-py3-none-any.whl
Size 30.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fde2e854bc174d6408e26069010238848931c3fb272cb00312dec4ba56b106cd
BLAKE2b-256 checksum
How to use checksums
1a5b58c2fcc235c8f3d45179bca5645682aefdf8c30693a5aa54bfc58c981957
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

1.5 This release

2 release files

1.4

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

1.0.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page