anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: aiogram/aiogram
Issue: check_token bug report

## Context

```python
from aiogram.bot.api import check_token

check_token('1234:') # True
check_token('12:ABC-DEF1234ghIkl-zyx57W2v1u123ew11') # ValidationError
```
* aiogram version: 2.4

## Expected Behavior

In the first case I expect an exception, in the second I expect True


Changed files:
aiogram/bot/api.py, tests/test_bot/test_api.py

diff --git a/aiogram/bot/api.py b/aiogram/bot/api.py
index 675626ac..9589c3e5 100644
--- a/aiogram/bot/api.py
+++ b/aiogram/bot/api.py
@@ -24,11 +24,17 @@ def check_token(token: str) -> bool:
     :param token:
     :return:
     """
+    if not isinstance(token, str):
+        message = (f"Token is invalid! "
+                   f"It must be 'str' type instead of {type(token)} type.")
+        raise exceptions.ValidationError(message)
+
     if any(x.isspace() for x in token):
-        raise exceptions.ValidationError('Token is invalid!')
+        message = "Token is invalid! It can't contains spaces."
+        raise exceptions.ValidationError(message)
 
     left, sep, right = token.partition(':')
-    if (not sep) or (not left.isdigit()) or (len(left) < 3):
+    if (not sep) or (not left.isdigit()) or (not right):
         raise exceptions.ValidationError('Token is invalid!')
 
     return True
diff --git a/tests/test_bot/test_api.py b/tests/test_bot/test_api.py
index c5193bcc..29418169 100644
--- a/tests/test_bot/test_api.py
+++ b/tests/test_bot/test_api.py
@@ -1,18 +1,32 @@
 import pytest
-from aiogram.bot.api import check_token
 
+from aiogram.bot.api import check_token
 from aiogram.utils.exceptions import ValidationError
 
-
 VALID_TOKEN = '123456789:AABBCCDDEEFFaabbccddeeff-1234567890'
-INVALID_TOKEN = '123456789:AABBCCDDEEFFaabbccddeeff 123456789'  # Space in token and wrong length
+INVALID_TOKENS = [
+    '123456789:AABBCCDDEEFFaabbccddeeff 123456789',  # space is exists
+    'ABC:AABBCCDDEEFFaabbccddeeff123456789',  # left part is not digit
+    ':AABBCCDDEEFFaabbccddeeff123456789',  # there is no left part
+    '123456789:',  # there is no right part
+    'ABC AABBCCDDEEFFaabbccddeeff123456789',  # there is no ':' separator
+    None,  # is None
+    12345678,  # is digit
+    {},  # is dict
+    [],  # is dict
+]
+
+
+@pytest.fixture(params=INVALID_TOKENS, name='invalid_token')
+def invalid_token_fixture(request):
+    return request.param
 
 
-class Test_check_token:
+class TestCheckToken:
 
     def test_valid(self):
         assert check_token(VALID_TOKEN) is True
 
-    def test_invalid_token(self):
+    def test_invalid_token(self, invalid_token):
         with pytest.raises(ValidationError):
-            check_token(INVALID_TOKEN)
+            check_token(invalid_token)
Repository: aiogram/aiogram
Issue: Default parse_mode not working for send_animation method

## Context
* Operating System: Linux, MacOS
* Python Version: 3.7.7
* aiogram version: 2.6.1
* aiohttp version: 3.6.2
* uvloop version (if installed): 0.14.0

## Expected Behavior
1. Set default parse mode for bot: Bot(..., parse_mode=ParseMode.HTML)
2. Call send_animation method without parse_mode param.
3. Caption parsed with default parse_mode from step 1.

## Current Behavior
1. Set default parse mode for bot: Bot(..., parse_mode=ParseMode.HTML)
2. Call send_animation method without parse_mode param.
3. Caption NOT parsed


Changed files:
aiogram/bot/bot.py

diff --git a/aiogram/bot/bot.py b/aiogram/bot/bot.py
index 39313558..c7b6dcbe 100644
--- a/aiogram/bot/bot.py
+++ b/aiogram/bot/bot.py
@@ -523,6 +523,8 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
         """
         reply_markup = prepare_arg(reply_markup)
         payload = generate_payload(**locals(), exclude=["animation", "thumb"])
+        if self.parse_mode:
+            payload.setdefault('parse_mode', self.parse_mode)
 
         files = {}
         prepare_file(payload, files, 'animation', animation)
Repository: aiogram/aiogram
Issue: JSONStorage and PickleStorage aren't persistent

## Context

* Operating System: Linux Linux Mint 19.1 Tessa
* Python Version: 3.7.1
* aiogram version: 2.2
* aiohttp version: 3.5.4

## Expected Behavior
The user's states will be saved with calling 
```python3
await dispatcher.storage.close()
await dispatcher.storage.wait_closed()
``` 
on shutdown and after the restart will stay the same as before.

## Current Behavior

The states are not saved on the disk, the empty object is saved instead. 

## Failure Information

During the shutdown, the storage makes 2 writing operations on the disk: first one with the correct data and the second with an empty object. The invocation of dispatcher.storage.close() performs these 2 operations. 
There is no bug in restoring data: if saving was successful, everything works correctly. 

### Steps to Reproduce

1. Run [this](https://gist.github.com/Birdi7/ffb3077b89d81f897df0d51072a8dbbd) gist. The JSONStorage is used there, but the situation with the PickleStorage is the same
2. Set your state with `/s1` or `/s2` and check if it is set with `/g`
3. Restart the script. An empty object will be saved In your "fsm_data.json" file 
4. Check that your state has changed after rebooting with `/g`



Changed files:
aiogram/contrib/fsm_storage/files.py

diff --git a/aiogram/contrib/fsm_storage/files.py b/aiogram/contrib/fsm_storage/files.py
index f67a6f69..455ca3f0 100644
--- a/aiogram/contrib/fsm_storage/files.py
+++ b/aiogram/contrib/fsm_storage/files.py
@@ -20,7 +20,8 @@ class _FileStorage(MemoryStorage):
             pass
 
     async def close(self):
-        self.write(self.path)
+        if self.data:
+            self.write(self.path)
         await super(_FileStorage, self).close()
 
     def read(self, path: pathlib.Path):
Repository: aiogram/aiogram
Issue: Imposible to download file into directory

## Context

* Operating System: Arch Linux
* Python Version: 3.7.3
* aiogram version: 2.2
* aiohttp version: 3.5.4

## Expected Behavior

Able to download file into specified directory.

## Current Behavior

Got `IsADirectoryError` exception.

## Failure Information (for bugs)

Problem lay in line https://github.com/aiogram/aiogram/blob/dev-2.x/aiogram/types/mixins.py#L27:
```
os.path.join(destination, file.file_path)
```
which is noop in current context.

### Steps to Reproduce

1. Setup message handler:
```
async def new_photo(message: types.Message):
    await message.photo[0].download(destination='/path/to/existing/directory')
```
2. Send photo to bot.
3. Get tracelog with `IsADirectoryError` exception.

Changed files:
aiogram/types/mixins.py

diff --git a/aiogram/types/mixins.py b/aiogram/types/mixins.py
index f11a1760..13f8412f 100644
--- a/aiogram/types/mixins.py
+++ b/aiogram/types/mixins.py
@@ -24,7 +24,7 @@ class Downloadable:
         if destination is None:
             destination = file.file_path
         elif isinstance(destination, (str, pathlib.Path)) and os.path.isdir(destination):
-            os.path.join(destination, file.file_path)
+            destination = os.path.join(destination, file.file_path)
         else:
             is_path = False