-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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,21 @@ | ||
"""Backport features of newer Python releases than our minimum target version. | ||
All functions should contain information about their standard library equivalent | ||
and the Python version in which it becomes available. | ||
These should be removed and replaced with standard library equivalents when | ||
we update our minimum target version.""" | ||
|
||
|
||
def removeprefix(text: str, prefix: str) -> str: | ||
"""Backport of `str.removeprefix` introduced in Python 3.9""" | ||
if text.startswith(prefix): | ||
return text[len(prefix) :] | ||
return text | ||
|
||
|
||
def removesuffix(text: str, suffix: str) -> str: | ||
"""Backport of `str.removesuffix` introduced in Python 3.9""" | ||
if text.endswith(suffix): | ||
return text[: -len(suffix)] | ||
return text |
Empty file.
This file contains 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,22 @@ | ||
from mentions.util.compatibility import removeprefix, removesuffix | ||
from tests.tests.util.testcase import SimpleTestCase | ||
|
||
|
||
class CompatibilityTests(SimpleTestCase): | ||
def test_str_removeprefix(self): | ||
func = removeprefix | ||
self.assertEqual(func("abcde", "ab"), "cde") | ||
self.assertEqual(func("1248", "1"), "248") | ||
|
||
self.assertEqual(func("abcde", "bc"), "abcde") | ||
self.assertEqual(func("abcde", "de"), "abcde") | ||
self.assertEqual(func("abcde", "abcdef"), "abcde") | ||
|
||
def test_str_removesuffix(self): | ||
func = removesuffix | ||
self.assertEqual(func("abcde", "de"), "abc") | ||
self.assertEqual(func("1248", "248"), "1") | ||
|
||
self.assertEqual(func("abcde", "ab"), "abcde") | ||
self.assertEqual(func("abcde", "abcd"), "abcde") | ||
self.assertEqual(func("abcde", "abcdef"), "abcde") |