Skip to content

Commit

Permalink
Remove accents in Emoji names (#20)
Browse files Browse the repository at this point in the history
Co-authored-by: Eduardo Soares <[email protected]>
  • Loading branch information
maxbrunet and eSoares authored Oct 18, 2021
1 parent c43814f commit c3a1820
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Switch from `setuptools` to `poetry` ([#11])
- Switch from Travis CI to Github Actions ([#13])
- Rename `Emoji.emoji` property to `Emoji.metadata` (#16)
- Rename `Emoji.emoji` property to `Emoji.metadata` ([#16])

### Fixed
- Remove accents in Emoji names instead of replacing characters by underscores ([#20])

### Removed
- Drop support for Python 3.5 ([#10])
Expand All @@ -36,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[0.2.0]: https://github.com/maxbrunet/mmemoji/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/maxbrunet/mmemoji/releases/tag/v0.1.0

[#20]: https://github.com/maxbrunet/mmemoji/issues/20
[#16]: https://github.com/maxbrunet/mmemoji/issues/16
[#13]: https://github.com/maxbrunet/mmemoji/issues/13
[#12]: https://github.com/maxbrunet/mmemoji/issues/12
Expand Down
14 changes: 13 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ mattermostdriver = ">=6.1.2"
requests = ""
tablib = ""
tabulate = ""
Unidecode = ""

[tool.poetry.dev-dependencies]
black = "==21.9b0"
Expand Down
3 changes: 3 additions & 0 deletions src/mmemoji/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import IO, Any, Dict, List, cast

from mattermostdriver.exceptions import ResourceNotFound
from unidecode import unidecode

from mmemoji.exceptions import EmojiAlreadyExists, EmojiNotFound

Expand Down Expand Up @@ -49,6 +50,8 @@ def sanitize_name(filepath: str) -> str:
"""
# Extract filename without extension
name = basename(filepath).split(".")[0]
# Transliterate Unicode to ASCII (remove accents)
name = unidecode(name)
# Remove parentheses
name = re.sub(r"[()[\]{}]", "", name)
# Replace forbidden characters by underscores
Expand Down
Binary file added tests/emojis/accentué.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions tests/test_emoji.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from mmemoji import Emoji


def test_emoji_sanitize_simple_name() -> None:
name = Emoji.sanitize_name("emoji_1")
assert name == "emoji_1"


def test_emoji_sanitize_name_with_parentheses() -> None:
name = Emoji.sanitize_name("{[(parentheses)]}")
assert name == "parentheses"


def test_emoji_sanitize_name_with_spaces() -> None:
name = Emoji.sanitize_name("spa a ace")
assert name == "spa_a_ace"


def test_emoji_sanitize_name_with_accents() -> None:
name = Emoji.sanitize_name("àéêöhelloĐıł")
assert name == "aeeohelloDil"
4 changes: 4 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"path": "tests/emojis/parentheses (spaced).png",
"sha256": "195645113194074832ac56af71de520f1e2e87e52e4c8268b675832b91bab003", # noqa: E501
},
"accentue": {
"path": "tests/emojis/accentué.png",
"sha256": "508c3f7dd47fdc0e879748cb0286e9de82d8945aab3a580c58a4a6682df6ab8f", # noqa: E501
},
}
USERS = {
"sysadmin": {
Expand Down

0 comments on commit c3a1820

Please sign in to comment.