-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Decrease test collisions #657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| flake8 | ||
| nose | ||
| nose-randomly | ||
| pep257 | ||
| pylint | ||
| flaky | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import sys | ||
|
|
||
| sys.path.append('.') | ||
|
|
||
| import telegram | ||
|
|
||
| bots = [ | ||
| { | ||
| 'token': '133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0', | ||
| 'chat_id': '12173560', | ||
| 'group_id': '-49740850', | ||
| 'channel_id': '@pythontelegrambottests', | ||
| 'payment_provider_token': '284685063:TEST:ZGJlMmQxZDI3ZTc3', | ||
| 'user': telegram.User(133505823, 'PythonTelegramBot', username='PythonTelegramBot') | ||
| } | ||
| ] | ||
|
|
||
|
|
||
| def get_bot(): | ||
| return bots[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import logging | ||
| import sys | ||
|
|
||
| sys.path.append('.') | ||
|
|
||
| import telegram | ||
| from tests.bots import get_bot | ||
|
|
||
| logger = logging.getLogger('tests.reupload') | ||
|
|
||
| bot_data = get_bot() | ||
| bot = telegram.Bot(bot_data['token']) | ||
|
|
||
| FILES = { | ||
| 'audio': { | ||
| 'file': 'telegram.mp3', | ||
| 'url': 'https://raw.githubusercontent.com/python-telegram-bot/python-telegram-bot/master/tests/data/telegram.mp3' | ||
| } | ||
| } | ||
|
|
||
| sent_files = {file_type: {t: None for t, file in files.items()} for file_type, files in | ||
| FILES.items()} | ||
|
|
||
|
|
||
| def reupload(file_type): | ||
| for t, file in FILES[file_type].items(): | ||
| file = file if t == 'url' else open('tests/data/' + file, 'rb') | ||
| msg = getattr(bot, 'send_' + file_type)(bot_data['chat_id'], file) | ||
| sent_files[file_type][t] = getattr(msg, file_type) | ||
|
|
||
|
|
||
| def get_file_id(file_type, url=False, thumb=False): | ||
| file = sent_files[file_type]['url' if url else 'file'] | ||
| if file is None: | ||
| reupload(file_type) | ||
| return get_file_id(file_type, url, thumb) | ||
| if thumb: | ||
| file = file.thumb | ||
| return file.file_id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would upload the file for every test in test_audio. setUp() is called before every test. I would go for setUpClass in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right... Whoops. Originally had it only do it when the class was imported (which would make it only run once in total over the entire lifetime of the tests). But along the way I realised that in some cases there's no need to upload all files if you for example are only running audio tests. But since it would have to way of figuring out which tests are gonna be run, I'll just switch it back to uploading on import I think. Unless you have a better idea? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually.... are you sure? In get_file_id there's a test to see if it's already been uploaded... wouldn't that be global across all tests in theory?