forked from MIT-Emerging-Talent/ET6-practice-code-review
-
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.
Add to_uppercase module and tests with Ruff formatting
- Loading branch information
1 parent
11eb838
commit 9799df1
Showing
4 changed files
with
77 additions
and
87 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,40 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Unit tests for the to_uppercase function. | ||
Created on XX XX XX | ||
@author: Your Name | ||
""" | ||
|
||
import unittest | ||
from solutions.to_uppercase import to_uppercase | ||
|
||
|
||
class TestToUppercase(unittest.TestCase): | ||
"""Tests for the to_uppercase function.""" | ||
|
||
def test_valid_string(self): | ||
"""It should convert lowercase to uppercase.""" | ||
self.assertEqual(to_uppercase("hello"), "HELLO") | ||
|
||
def test_mixed_case_string(self): | ||
"""It should convert mixed case to uppercase.""" | ||
self.assertEqual(to_uppercase("Python"), "PYTHON") | ||
|
||
def test_alphanumeric_string(self): | ||
"""It should handle alphanumeric strings.""" | ||
self.assertEqual(to_uppercase("123abc"), "123ABC") | ||
|
||
def test_empty_string(self): | ||
"""It should return an empty string.""" | ||
self.assertEqual(to_uppercase(""), "") | ||
|
||
def test_non_string_input(self): | ||
"""It should raise TypeError for non-string inputs.""" | ||
with self.assertRaises(TypeError): | ||
to_uppercase(123) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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,37 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Module for converting strings to uppercase. | ||
Module contents: | ||
- to_uppercase: Converts a given string to uppercase. | ||
Created on XX XX XX | ||
@author: Your Name | ||
""" | ||
|
||
|
||
def to_uppercase(s: str) -> str: | ||
"""Converts a string to uppercase. | ||
Parameters: | ||
s (str): The string to be converted. | ||
Returns: | ||
str: The string with all characters in uppercase. | ||
Raises: | ||
TypeError: If the input is not a string. | ||
>>> to_uppercase("hello") | ||
'HELLO' | ||
>>> to_uppercase("Python") | ||
'PYTHON' | ||
>>> to_uppercase("123abc") | ||
'123ABC' | ||
""" | ||
if not isinstance(s, str): | ||
raise TypeError("Input must be a string.") | ||
return s.upper() |