|
| 1 | +import sys |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +if sys.version_info < (3, 9): |
| 6 | + from pandas.util._str_methods import ( |
| 7 | + removeprefix, |
| 8 | + removesuffix, |
| 9 | + ) |
| 10 | + |
| 11 | + @pytest.mark.parametrize( |
| 12 | + "string, prefix, expected", |
| 13 | + ( |
| 14 | + ("wildcat", "wild", "cat"), |
| 15 | + ("blackbird", "black", "bird"), |
| 16 | + ("housefly", "house", "fly"), |
| 17 | + ("ladybug", "lady", "bug"), |
| 18 | + ("rattlesnake", "rattle", "snake"), |
| 19 | + ("baboon", "badger", "baboon"), |
| 20 | + ("quetzal", "elk", "quetzal"), |
| 21 | + ), |
| 22 | + ) |
| 23 | + def test_remove_prefix(string, prefix, expected): |
| 24 | + result = removeprefix(string, prefix) |
| 25 | + assert result == expected |
| 26 | + |
| 27 | + @pytest.mark.parametrize( |
| 28 | + "string, suffix, expected", |
| 29 | + ( |
| 30 | + ("wildcat", "cat", "wild"), |
| 31 | + ("blackbird", "bird", "black"), |
| 32 | + ("housefly", "fly", "house"), |
| 33 | + ("ladybug", "bug", "lady"), |
| 34 | + ("rattlesnake", "snake", "rattle"), |
| 35 | + ("seahorse", "horse", "sea"), |
| 36 | + ("baboon", "badger", "baboon"), |
| 37 | + ("quetzal", "elk", "quetzal"), |
| 38 | + ), |
| 39 | + ) |
| 40 | + def test_remove_suffix(string, suffix, expected): |
| 41 | + result = removesuffix(string, suffix) |
| 42 | + assert result == expected |
| 43 | + |
| 44 | +else: |
| 45 | + # NOTE: remove this file when pyupgrade --py39-plus removes |
| 46 | + # the above block |
| 47 | + pass |
0 commit comments