Created
December 1, 2017 16:57
-
-
Save Songbird0/5f9c0e569736883226839608c00f3362 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
# Std | |
import unittest | |
# Third party | |
# Internal | |
def remove_suffix(your_string: str, suffix_to_remove: str) -> str: | |
if your_string.endswith(suffix_to_remove): | |
suffix_index = your_string.rindex(suffix_to_remove) | |
return your_string[:suffix_index] | |
else: | |
raise Exception('Your string is not suffixed by "{}".'.format(suffix_to_remove)) | |
class SuffixRemoving(unittest.TestCase): | |
def setUp(self): | |
print('Nothing to do here!') | |
def test_suffix_correctly_removed(self): | |
file_name = 'foo/bar/baz/bang.py' | |
result = remove_suffix(file_name, '.py') | |
self.assertEqual(result, 'foo/bar/baz/bang', "result is equal to '{}'.".format(result)) | |
another_file_name = 'foo.py/bar.py/baz.py/bang.py' | |
result = remove_suffix(another_file_name, '.py') | |
self.assertEqual(result, 'foo.py/bar.py/baz.py/bang', "result is equal to '{}'.".format(result)) | |
if __name__ == '__main__': | |
unittest.main(exit=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment