Skip to content

Commit 022d918

Browse files
committed
TR updates
1 parent 58a21e9 commit 022d918

File tree

10 files changed

+81
-81
lines changed

10 files changed

+81
-81
lines changed

python-doctest/calculations/test_calculations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
def load_tests(loader, tests, ignore):
8-
tests.addTests(doctest.DocFileSuite("tests_file.txt"))
8+
tests.addTests(doctest.DocFileSuite("test_calculations.txt"))
99
tests.addTests(doctest.DocTestSuite(calculations))
1010
return tests
1111

File renamed without changes.

python-doctest/context.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# context.py
2-
31
total = 100
42

53

python-doctest/fizz_buzz.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
# The commented versions of fizz_buzz() below reflect the steps
2+
# followed to get to the final version at the end of the file.
3+
14
# Replace numbers that are divisible by 3 with "fizz"
2-
def fizz_buzz(numbers):
3-
"""Implement the Fizz buzz game.
5+
# def fizz_buzz(numbers):
6+
# """Implement the Fizz buzz game.
47

5-
>>> fizz_buzz([3, 6, 9, 12])
6-
['fizz', 'fizz', 'fizz', 'fizz']
7-
"""
8+
# >>> fizz_buzz([3, 6, 9, 12])
9+
# ['fizz', 'fizz', 'fizz', 'fizz']
10+
# """
811

912

1013
# # Replace numbers that are divisible by 3 with "fizz"
@@ -45,29 +48,29 @@ def fizz_buzz(numbers):
4548

4649

4750
# Replace numbers that are divisible by 3 and 5 with "fizz buzz"
48-
# def fizz_buzz(numbers):
49-
# """Implement the Fizz buzz game.
51+
def fizz_buzz(numbers):
52+
"""Implement the Fizz buzz game.
5053
51-
# >>> fizz_buzz([3, 6, 9, 12])
52-
# ['fizz', 'fizz', 'fizz', 'fizz']
54+
>>> fizz_buzz([3, 6, 9, 12])
55+
['fizz', 'fizz', 'fizz', 'fizz']
5356
54-
# >>> fizz_buzz([5, 10, 20, 25])
55-
# ['buzz', 'buzz', 'buzz', 'buzz']
57+
>>> fizz_buzz([5, 10, 20, 25])
58+
['buzz', 'buzz', 'buzz', 'buzz']
5659
57-
# >>> fizz_buzz([15, 30, 45])
58-
# ['fizz buzz', 'fizz buzz', 'fizz buzz']
60+
>>> fizz_buzz([15, 30, 45])
61+
['fizz buzz', 'fizz buzz', 'fizz buzz']
5962
60-
# >>> fizz_buzz([3, 6, 5, 10, 15, 30])
61-
# ['fizz', 'fizz', 'buzz', 'buzz', 'fizz buzz', 'fizz buzz']
62-
# """
63-
# result = []
64-
# for number in numbers:
65-
# if number % 15 == 0:
66-
# result.append("fizz buzz")
67-
# elif number % 3 == 0:
68-
# result.append("fizz")
69-
# elif number % 5 == 0:
70-
# result.append("buzz")
71-
# else:
72-
# result.append(number)
73-
# return result
63+
>>> fizz_buzz([3, 6, 5, 10, 15, 30])
64+
['fizz', 'fizz', 'buzz', 'buzz', 'fizz buzz', 'fizz buzz']
65+
"""
66+
result = []
67+
for number in numbers:
68+
if number % 15 == 0:
69+
result.append("fizz buzz")
70+
elif number % 3 == 0:
71+
result.append("fizz")
72+
elif number % 5 == 0:
73+
result.append("buzz")
74+
else:
75+
result.append(number)
76+
return result

python-doctest/greet.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
# def greet(name="World"):
2-
# """Print a greeting.
1+
def greet_with_bank_line(name="World"):
2+
"""Print a greeting.
33
4-
# Usage examples:
5-
# >>> greet("Pythonista")
6-
# Hello, Pythonista!
7-
# <BLANKLINE>
8-
# How have you been?
9-
# """
10-
# print(f"Hello, {name}!")
11-
# print()
12-
# print("How have you been?")
4+
Usage examples:
5+
>>> greet("Pythonista")
6+
Hello, Pythonista!
7+
<BLANKLINE>
8+
How have you been?
9+
"""
10+
print(f"Hello, {name}!")
11+
print()
12+
print("How have you been?")
1313

1414

15-
# def greet(name="World"):
16-
# r"""Print a greeting.
15+
def greet_with_raw_docstring(name="World"):
16+
r"""Print a greeting.
1717
18-
# Usage examples:
19-
# >>> greet("Pythonista")
20-
# /== Hello, Pythonista! ==\
21-
# \== How have you been? ==/
22-
# """
23-
# print(f"/== Hello, {name}! ==\\")
24-
# print("\\== How have you been? ==/")
18+
Usage examples:
19+
>>> greet("Pythonista")
20+
/== Hello, Pythonista! ==\
21+
\== How have you been? ==/
22+
"""
23+
print(f"/== Hello, {name}! ==\\")
24+
print("\\== How have you been? ==/")
2525

2626

27-
def greet(name="World"):
27+
def greet_with_scaped_backslash(name="World"):
2828
"""Print a greeting.
2929
3030
Usage examples:

python-doctest/identity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
def get_id(obj):
22
"""Return the identity of an object.
33
4+
This test always fails
45
>>> get_id(1) # doctest: +ELLIPSIS
56
...
67
"""
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# options.txt
2-
31
>>> 5 < 7
42
True
53

File renamed without changes.

python-doctest/run_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import doctest
22

3-
doctest.testfile("tests_file.txt", verbose=True)
3+
doctest.testfile("test_calculations.txt", verbose=True)

python-doctest/user.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
# class User:
2-
# def __init__(self, name, favorite_colors):
3-
# self.name = name
4-
# self._favorite_colors = set(favorite_colors)
1+
class User_One:
2+
def __init__(self, name, favorite_colors):
3+
self.name = name
4+
self._favorite_colors = set(favorite_colors)
55

6-
# @property
7-
# def favorite_colors(self):
8-
# """Return the user's favorite colors.
6+
@property
7+
def favorite_colors(self):
8+
"""Return the user's favorite colors.
99
10-
# Usage examples:
11-
# >>> john = User("John", {"#797EF6", "#4ADEDE", "#1AA7EC"})
12-
# >>> john.favorite_colors
13-
# {'#1AA7EC', '#4ADEDE', '#797EF6'}
14-
# """
15-
# return self._favorite_colors
10+
Usage examples:
11+
>>> john = User("John", {"#797EF6", "#4ADEDE", "#1AA7EC"})
12+
>>> john.favorite_colors
13+
{'#1AA7EC', '#4ADEDE', '#797EF6'}
14+
"""
15+
return self._favorite_colors
1616

1717

18-
# class User:
19-
# def __init__(self, name, favorite_colors):
20-
# self.name = name
21-
# self._favorite_colors = set(favorite_colors)
18+
class User_Two:
19+
def __init__(self, name, favorite_colors):
20+
self.name = name
21+
self._favorite_colors = set(favorite_colors)
2222

23-
# @property
24-
# def favorite_colors(self):
25-
# """Return the user's favorite colors.
23+
@property
24+
def favorite_colors(self):
25+
"""Return the user's favorite colors.
2626
27-
# Usage examples:
28-
# >>> john = User("John", {"#797EF6", "#4ADEDE", "#1AA7EC"})
29-
# >>> sorted(john.favorite_colors)
30-
# ['#1AA7EC', '#4ADEDE', '#797EF6']
31-
# """
32-
# return self._favorite_colors
27+
Usage examples:
28+
>>> john = User("John", {"#797EF6", "#4ADEDE", "#1AA7EC"})
29+
>>> sorted(john.favorite_colors)
30+
['#1AA7EC', '#4ADEDE', '#797EF6']
31+
"""
32+
return self._favorite_colors
3333

3434

35-
class User:
35+
class User_Three:
3636
def __init__(self, name, favorite_colors):
3737
"""Initialize instances of User.
3838

0 commit comments

Comments
 (0)