Skip to content

Commit 4c7e68c

Browse files
authored
Edited the test error messages and touched up docs. (#3540)
[no important files changed]
1 parent b1fc9e8 commit 4c7e68c

File tree

6 files changed

+78
-23
lines changed

6 files changed

+78
-23
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"blurb": "The 'str' class provides many useful 'string-methods'. They can be used for cleaning, splitting, translating, or otherwise working with any 'str' object. Because strings are immutable, any functions or methods that operate on a 'str' will return a new instance or copy of the 'str' rather than modifying the original 'str' object.",
33
"authors": ["kimolivia"],
4-
"contributors": ["valentin-p", "bethanyg"]
4+
"contributors": ["valentin-p", "BethanyG"]
55
}

concepts/string-methods/about.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Some of the more commonly used `str` methods include:
1818

1919
Being _immutable_, a `str` object's value in memory cannot change; methods that appear to modify a string return a new copy or instance of that `str` object.
2020

21+
2122
[`<str>.endswith(<suffix>)`][str-endswith] returns `True` if the string ends with `<suffix>`, `False` otherwise.
2223

2324
```python

concepts/string-methods/links.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
[
22
{
33
"url": "https://docs.python.org/3/library/stdtypes.html#string-methods",
4-
"description": "string methods"
4+
"description": "Python Documentation: string methods"
55
},
66
{
77
"url": "https://docs.python.org/3/library/stdtypes.html#common-sequence-operations",
8-
"description": "common sequence operations"
8+
"description": "Python Documentation: common sequence operations"
99
},
1010
{
1111
"url": "https://realpython.com/python-strings/",
12-
"description": "strings and character data in Python"
12+
"description": "Real Python: strings and character data in Python"
1313
},
1414
{
1515
"url": "https://www.programiz.com/python-programming/string",
16-
"description": "more string operations and functions"
16+
"description": "Programiz: more string operations and functions"
1717
}
1818
]

exercises/concept/little-sisters-essay/.docs/hints.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## General
44

5-
- [Introduction to string methods in Python][string-method-docs]
5+
- [Python Documentation: String Methods][string-method-docs]
6+
- [Python Documentation Tutorial: Text][tutorial-strings]
67

78
## 1. Capitalize the title of the paper
89

@@ -20,8 +21,9 @@
2021

2122
- You can use [string methods][replace-method-docs] to replace words.
2223

23-
[string-method-docs]: https://docs.python.org/3/library/stdtypes.html#string-methods
24-
[title-method-docs]: https://docs.python.org/3/library/stdtypes.html#str.title
2524
[endswith-method-docs]: https://docs.python.org/3/library/stdtypes.html#str.endswith
26-
[strip-method-docs]: https://docs.python.org/3/library/stdtypes.html#str.strip
2725
[replace-method-docs]: https://docs.python.org/3/library/stdtypes.html#str.replace
26+
[string-method-docs]: https://docs.python.org/3/library/stdtypes.html#string-methods
27+
[strip-method-docs]: https://docs.python.org/3/library/stdtypes.html#str.strip
28+
[title-method-docs]: https://docs.python.org/3/library/stdtypes.html#str.title
29+
[tutorial-strings]: https://docs.python.org/3/tutorial/introduction.html#text

exercises/concept/little-sisters-essay/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
],
55
"contributors": [
66
"valentin-p",
7-
"bethanyg"
7+
"BethanyG"
88
],
99
"files": {
1010
"solution": [

exercises/concept/little-sisters-essay/string_methods_test.py

+65-13
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,89 @@ class LittleSistersEssayTest(unittest.TestCase):
1010

1111
@pytest.mark.task(taskno=1)
1212
def test_capitalize_word(self):
13-
self.assertEqual(capitalize_title("canopy"), "Canopy")
13+
14+
actual_result = capitalize_title("canopy")
15+
expected = "Canopy"
16+
error_message = (f'Called capitalize_title("canopy"). '
17+
f'The function returned "{actual_result}", '
18+
f'but the tests expected "{expected}" for the title.')
19+
20+
self.assertEqual(actual_result, expected, msg=error_message)
1421

1522
@pytest.mark.task(taskno=1)
1623
def test_capitalize_title(self):
17-
self.assertEqual(capitalize_title("fish are cold blooded"),
18-
"Fish Are Cold Blooded")
24+
25+
actual_result = capitalize_title("fish are cold blooded")
26+
expected = "Fish Are Cold Blooded"
27+
error_message = (f'Called capitalize_title("fish are cold blooded"). '
28+
f'The function returned "{actual_result}", '
29+
f'but the tests expected "{expected}" for the title.')
30+
31+
self.assertEqual(actual_result, expected, msg=error_message)
1932

2033
@pytest.mark.task(taskno=2)
2134
def test_sentence_ending(self):
22-
self.assertEqual(check_sentence_ending("Snails can sleep for 3 years."), True)
35+
36+
actual_result = check_sentence_ending("Snails can sleep for 3 years.")
37+
expected = True
38+
error_message = (f'Called check_sentence_ending("Snails can sleep for 3 years."). '
39+
f'The function returned {actual_result}, '
40+
f'but the tests expected {expected} for a period ending.')
41+
42+
self.assertEqual(actual_result, expected, msg=error_message)
2343

2444
@pytest.mark.task(taskno=2)
2545
def test_sentence_ending_without_period(self):
26-
self.assertEqual(check_sentence_ending("Fittonia are nice"), False)
46+
47+
actual_result = check_sentence_ending("Fittonia are nice")
48+
expected = False
49+
error_message = (f'Called check_sentence_ending("Fittonia are nice"). '
50+
f'The function returned {actual_result}, '
51+
f'but the tests expected {expected} for a period ending.')
52+
53+
self.assertEqual(actual_result, expected, msg=error_message)
2754

2855
@pytest.mark.task(taskno=3)
2956
def test_remove_extra_spaces_only_start(self):
30-
self.assertEqual(clean_up_spacing(" A rolling stone gathers no moss"),
31-
"A rolling stone gathers no moss")
57+
58+
actual_result = clean_up_spacing(" A rolling stone gathers no moss")
59+
expected = "A rolling stone gathers no moss"
60+
error_message = (f'Called clean_up_spacing(" A rolling stone gathers no moss"). '
61+
f'The function returned "{actual_result}", '
62+
f'but the tests expected "{expected}" as a cleaned string.')
63+
64+
self.assertEqual(actual_result, expected, msg=error_message)
3265

3366
@pytest.mark.task(taskno=3)
3467
def test_remove_extra_spaces(self):
35-
self.assertEqual(clean_up_spacing(" Elephants can't jump. "),
36-
"Elephants can't jump.")
68+
69+
actual_result = clean_up_spacing(" Elephants can't jump. ")
70+
expected = "Elephants can't jump."
71+
error_message = ("Called clean_up_spacing(\" Elephants can't jump. \")"
72+
f'The function returned "{actual_result}", '
73+
f'but the tests expected "{expected}" as a cleaned string.')
74+
75+
self.assertEqual(actual_result, expected, msg=error_message)
3776

3877
@pytest.mark.task(taskno=4)
3978
def test_replace_word_choice(self):
40-
self.assertEqual(replace_word_choice("Animals are cool.", "cool", "awesome"),
41-
"Animals are awesome.")
79+
80+
actual_result = replace_word_choice("Animals are cool.", "cool", "awesome")
81+
expected = "Animals are awesome."
82+
error_message = ('Called replace_word_choice("Animals are cool.", "cool", "awesome"). '
83+
f'The function returned "{actual_result}", '
84+
f'but the tests expected "{expected}" after the word replacement.')
85+
86+
self.assertEqual(actual_result, expected, msg=error_message)
4287

4388
@pytest.mark.task(taskno=4)
4489
def test_replace_word_not_exist(self):
45-
self.assertEqual(replace_word_choice("Animals are cool.", "small", "tiny"),
46-
"Animals are cool.")
90+
91+
actual_result = replace_word_choice("Animals are cool.", "small", "tiny")
92+
expected = "Animals are cool."
93+
error_message = ('Called replace_word_choice("Animals are cool.", "small", "tiny"). '
94+
f'The function returned "{actual_result}", '
95+
f'but the tests expected "{expected}", because the word '
96+
'to be replaced is not in the sentence.')
97+
98+
self.assertEqual(actual_result, expected, msg=error_message)

0 commit comments

Comments
 (0)