diff --git a/koans/about_asserts.py b/koans/about_asserts.py index d17ed0cdf..901500c6e 100644 --- a/koans/about_asserts.py +++ b/koans/about_asserts.py @@ -3,8 +3,8 @@ from runner.koan import * -class AboutAsserts(Koan): +class AboutAsserts(Koan): def test_assert_truth(self): """ We shall contemplate truth by testing reality, via asserts. @@ -14,25 +14,25 @@ def test_assert_truth(self): # # http://bit.ly/about_asserts - self.assertTrue(False) # This should be True + self.assertTrue(True) # This should be True def test_assert_with_message(self): """ Enlightenment may be more easily achieved with appropriate messages. """ - self.assertTrue(False, "This should be True -- Please fix this") + self.assertTrue(True, "This should be True -- Please fix this") def test_fill_in_values(self): """ Sometimes we will ask you to fill in the values """ - self.assertEqual(__, 1 + 1) + self.assertEqual(2, 1 + 1) def test_assert_equality(self): """ To understand reality, we must compare our expectations against reality. """ - expected_value = __ + expected_value = 2 actual_value = 1 + 1 self.assertTrue(expected_value == actual_value) @@ -40,7 +40,7 @@ def test_a_better_way_of_asserting_equality(self): """ Some ways of asserting equality are better than others. """ - expected_value = __ + expected_value = 2 actual_value = 1 + 1 self.assertEqual(expected_value, actual_value) @@ -51,7 +51,7 @@ def test_that_unittest_asserts_work_the_same_way_as_python_asserts(self): """ # This throws an AssertionError exception - assert False + assert True def test_that_sometimes_we_need_to_know_the_class_type(self): """ @@ -70,9 +70,8 @@ def test_that_sometimes_we_need_to_know_the_class_type(self): # # See for yourself: - self.assertEqual(__, "navel".__class__) # It's str, not + self.assertEqual(str, "navel".__class__) # It's str, not # Need an illustration? More reading can be found here: # # https://github.com/gregmalcolm/python_koans/wiki/Class-Attribute - diff --git a/koans/about_control_statements.py b/koans/about_control_statements.py index 842c8d91f..9560c6340 100644 --- a/koans/about_control_statements.py +++ b/koans/about_control_statements.py @@ -3,29 +3,29 @@ from runner.koan import * -class AboutControlStatements(Koan): +class AboutControlStatements(Koan): def test_if_then_else_statements(self): if True: - result = 'true value' + result = "true value" else: - result = 'false value' - self.assertEqual(__, result) + result = "false value" + self.assertEqual("true value", result) def test_if_then_statements(self): - result = 'default value' + result = "default value" if True: - result = 'true value' - self.assertEqual(__, result) + result = "true value" + self.assertEqual("true value", result) def test_if_then_elif_else_statements(self): if False: - result = 'first value' + result = "first value" elif True: - result = 'true value' + result = "true value" else: - result = 'default value' - self.assertEqual(__, result) + result = "default value" + self.assertEqual("true value", result) def test_while_statement(self): i = 1 @@ -33,45 +33,47 @@ def test_while_statement(self): while i <= 10: result = result * i i += 1 - self.assertEqual(__, result) + self.assertEqual(1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10, result) def test_break_statement(self): i = 1 result = 1 while True: - if i > 10: break + if i > 10: + break result = result * i i += 1 - self.assertEqual(__, result) + self.assertEqual(1 * 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10, result) def test_continue_statement(self): i = 0 result = [] while i < 10: i += 1 - if (i % 2) == 0: continue + if (i % 2) == 0: + continue result.append(i) - self.assertEqual(__, result) + self.assertEqual([1, 3, 5, 7, 9], result) def test_for_statement(self): phrase = ["fish", "and", "chips"] result = [] for item in phrase: result.append(item.upper()) - self.assertEqual([__, __, __], result) + self.assertEqual(["FISH", "AND", "CHIPS"], result) def test_for_statement_with_tuples(self): round_table = [ ("Lancelot", "Blue"), ("Galahad", "I don't know!"), ("Robin", "Blue! I mean Green!"), - ("Arthur", "Is that an African Swallow or European Swallow?") + ("Arthur", "Is that an African Swallow or European Swallow?"), ] result = [] for knight, answer in round_table: result.append("Contestant: '" + knight + "' Answer: '" + answer + "'") - text = __ + text = "Contestant: 'Robin' Answer: 'Blue! I mean Green!'" self.assertRegex(result[2], text) diff --git a/koans/about_dictionaries.py b/koans/about_dictionaries.py index da1ed6bfe..830f1b398 100644 --- a/koans/about_dictionaries.py +++ b/koans/about_dictionaries.py @@ -7,51 +7,59 @@ from runner.koan import * + class AboutDictionaries(Koan): def test_creating_dictionaries(self): empty_dict = dict() self.assertEqual(dict, type(empty_dict)) self.assertDictEqual({}, empty_dict) - self.assertEqual(__, len(empty_dict)) + self.assertEqual(0, len(empty_dict)) def test_dictionary_literals(self): empty_dict = {} self.assertEqual(dict, type(empty_dict)) - babel_fish = { 'one': 'uno', 'two': 'dos' } - self.assertEqual(__, len(babel_fish)) + babel_fish = {"one": "uno", "two": "dos"} + self.assertEqual(2, len(babel_fish)) def test_accessing_dictionaries(self): - babel_fish = { 'one': 'uno', 'two': 'dos' } - self.assertEqual(__, babel_fish['one']) - self.assertEqual(__, babel_fish['two']) + babel_fish = {"one": "uno", "two": "dos"} + self.assertEqual("uno", babel_fish["one"]) + self.assertEqual("dos", babel_fish["two"]) def test_changing_dictionaries(self): - babel_fish = { 'one': 'uno', 'two': 'dos' } - babel_fish['one'] = 'eins' + babel_fish = {"one": "uno", "two": "dos"} + babel_fish["one"] = "eins" - expected = { 'two': 'dos', 'one': __ } + expected = {"two": "dos", "one": "eins"} self.assertDictEqual(expected, babel_fish) def test_dictionary_is_unordered(self): - dict1 = { 'one': 'uno', 'two': 'dos' } - dict2 = { 'two': 'dos', 'one': 'uno' } - - self.assertEqual(__, dict1 == dict2) + dict1 = {"one": "uno", "two": "dos"} + dict2 = {"two": "dos", "one": "uno"} + self.assertEqual(True, dict1 == dict2) def test_dictionary_keys_and_values(self): - babel_fish = {'one': 'uno', 'two': 'dos'} - self.assertEqual(__, len(babel_fish.keys())) - self.assertEqual(__, len(babel_fish.values())) - self.assertEqual(__, 'one' in babel_fish.keys()) - self.assertEqual(__, 'two' in babel_fish.values()) - self.assertEqual(__, 'uno' in babel_fish.keys()) - self.assertEqual(__, 'dos' in babel_fish.values()) + babel_fish = {"one": "uno", "two": "dos"} + self.assertEqual(2, len(babel_fish.keys())) + self.assertEqual(2, len(babel_fish.values())) + self.assertEqual(True, "one" in babel_fish.keys()) + self.assertEqual(False, "two" in babel_fish.values()) + self.assertEqual(False, "uno" in babel_fish.keys()) + self.assertEqual(True, "dos" in babel_fish.values()) def test_making_a_dictionary_from_a_sequence_of_keys(self): - cards = {}.fromkeys(('red warrior', 'green elf', 'blue valkyrie', 'yellow dwarf', 'confused looking zebra'), 42) - - self.assertEqual(__, len(cards)) - self.assertEqual(__, cards['green elf']) - self.assertEqual(__, cards['yellow dwarf']) + cards = {}.fromkeys( + ( + "red warrior", + "green elf", + "blue valkyrie", + "yellow dwarf", + "confused looking zebra", + ), + 42, + ) + self.assertEqual(5, len(cards)) + self.assertEqual(42, cards["green elf"]) + self.assertEqual(42, cards["yellow dwarf"]) diff --git a/koans/about_list_assignments.py b/koans/about_list_assignments.py index 8a8d48090..ae7442cbb 100644 --- a/koans/about_list_assignments.py +++ b/koans/about_list_assignments.py @@ -7,15 +7,16 @@ from runner.koan import * + class AboutListAssignments(Koan): def test_non_parallel_assignment(self): names = ["John", "Smith"] - self.assertEqual(__, names) + self.assertEqual(["John", "Smith"], names) def test_parallel_assignments(self): first_name, last_name = ["John", "Smith"] - self.assertEqual(__, first_name) - self.assertEqual(__, last_name) + self.assertEqual("John", first_name) + self.assertEqual("Smith", last_name) def test_parallel_assignments_with_extra_values(self): title, *first_names, last_name = ["Sir", "Ricky", "Bobby", "Worthington"] @@ -31,13 +32,12 @@ def test_parallel_assignments_with_fewer_values(self): def test_parallel_assignments_with_sublists(self): first_name, last_name = [["Willie", "Rae"], "Johnson"] - self.assertEqual(__, first_name) - self.assertEqual(__, last_name) + self.assertEqual(["Willie", "Rae"], first_name) + self.assertEqual("Johnson", last_name) def test_swapping_with_parallel_assignment(self): first_name = "Roy" last_name = "Rob" first_name, last_name = last_name, first_name - self.assertEqual(__, first_name) - self.assertEqual(__, last_name) - + self.assertEqual("Rob", first_name) + self.assertEqual("Roy", last_name) diff --git a/koans/about_lists.py b/koans/about_lists.py index 61cc3bb29..6f0a8e295 100644 --- a/koans/about_lists.py +++ b/koans/about_lists.py @@ -7,11 +7,12 @@ from runner.koan import * + class AboutLists(Koan): def test_creating_lists(self): empty_list = list() self.assertEqual(list, type(empty_list)) - self.assertEqual(__, len(empty_list)) + self.assertEqual(0, len(empty_list)) def test_list_literals(self): nums = list() @@ -21,70 +22,70 @@ def test_list_literals(self): self.assertEqual([1], nums) nums[1:] = [2] - self.assertListEqual([1, __], nums) + self.assertEqual([1, 2], nums) nums.append(333) - self.assertListEqual([1, 2, __], nums) + self.assertEqual([1, 2, 333], nums) def test_accessing_list_elements(self): - noms = ['peanut', 'butter', 'and', 'jelly'] + noms = ["peanut", "butter", "and", "jelly"] - self.assertEqual(__, noms[0]) - self.assertEqual(__, noms[3]) - self.assertEqual(__, noms[-1]) - self.assertEqual(__, noms[-3]) + self.assertEqual("peanut", noms[0]) + self.assertEqual("jelly", noms[3]) + self.assertEqual("jelly", noms[-1]) + self.assertEqual("butter", noms[-3]) def test_slicing_lists(self): - noms = ['peanut', 'butter', 'and', 'jelly'] + noms = ["peanut", "butter", "and", "jelly"] - self.assertEqual(__, noms[0:1]) - self.assertEqual(__, noms[0:2]) - self.assertEqual(__, noms[2:2]) - self.assertEqual(__, noms[2:20]) - self.assertEqual(__, noms[4:0]) - self.assertEqual(__, noms[4:100]) - self.assertEqual(__, noms[5:0]) + self.assertEqual(["peanut"], noms[0:1]) + self.assertEqual(["peanut", "butter"], noms[0:2]) + self.assertEqual([], noms[2:2]) + self.assertEqual(["and", "jelly"], noms[2:20]) + self.assertEqual([], noms[4:0]) + self.assertEqual([], noms[4:100]) + self.assertEqual([], noms[5:0]) def test_slicing_to_the_edge(self): - noms = ['peanut', 'butter', 'and', 'jelly'] + noms = ["peanut", "butter", "and", "jelly"] self.assertEqual(__, noms[2:]) self.assertEqual(__, noms[:2]) def test_lists_and_ranges(self): self.assertEqual(range, type(range(5))) - self.assertNotEqual([1, 2, 3, 4, 5], range(1,6)) - self.assertEqual(__, list(range(5))) - self.assertEqual(__, list(range(5, 9))) + self.assertNotEqual([1, 2, 3, 4, 5], range(1, 6)) + self.assertEqual([0, 1, 2, 3, 4], list(range(5))) + self.assertEqual([5, 6, 7, 8], list(range(5, 9))) def test_ranges_with_steps(self): - self.assertEqual(__, list(range(5, 3, -1))) - self.assertEqual(__, list(range(0, 8, 2))) - self.assertEqual(__, list(range(1, 8, 3))) - self.assertEqual(__, list(range(5, -7, -4))) - self.assertEqual(__, list(range(5, -8, -4))) + self.assertEqual([5, 4], list(range(5, 3, -1))) + self.assertEqual([0, 2, 4, 6], list(range(0, 8, 2))) + self.assertEqual([1, 4, 7], list(range(1, 8, 3))) + self.assertEqual([5, 1, -3], list(range(5, -7, -4))) + self.assertEqual([5, 1, -3, -7], list(range(5, -8, -4))) def test_insertions(self): - knight = ['you', 'shall', 'pass'] - knight.insert(2, 'not') - self.assertEqual(__, knight) + knight = ["you", "shall", "pass"] + knight.insert(2, "not") + self.assertEqual(["you", "shall", "not", "pass"], knight) - knight.insert(0, 'Arthur') - self.assertEqual(__, knight) + knight.insert(0, "Arthur") + self.assertEqual(["Arthur", "you", "shall", "not", "pass"], knight) def test_popping_lists(self): stack = [10, 20, 30, 40] - stack.append('last') + stack.append("last") - self.assertEqual(__, stack) + self.assertEqual([10, 20, 30, 40, "last"], stack) popped_value = stack.pop() - self.assertEqual(__, popped_value) - self.assertEqual(__, stack) + self.assertEqual("last", popped_value) + self.assertEqual([10, 20, 30, 40], stack) popped_value = stack.pop(1) - self.assertEqual(__, popped_value) - self.assertEqual(__, stack) + self.assertEqual(20, popped_value) + self.assertEqual([10, 30, 40], stack) # Notice that there is a "pop" but no "push" in python? @@ -96,14 +97,13 @@ def test_popping_lists(self): def test_making_queues(self): queue = [1, 2] - queue.append('last') + queue.append("last") - self.assertEqual(__, queue) + self.assertEqual([1, 2, "last"], queue) popped_value = queue.pop(0) - self.assertEqual(__, popped_value) - self.assertEqual(__, queue) + self.assertEqual(1, popped_value) + self.assertEqual([2, "last"], queue) # Note, popping from the left hand side of a list is # inefficient. Use collections.deque instead. - diff --git a/koans/about_methods.py b/koans/about_methods.py index 796a07ea5..24a470ce2 100644 --- a/koans/about_methods.py +++ b/koans/about_methods.py @@ -7,12 +7,14 @@ from runner.koan import * -def my_global_function(a,b): + +def my_global_function(a, b): return a + b + class AboutMethods(Koan): def test_calling_a_global_function(self): - self.assertEqual(__, my_global_function(2,3)) + self.assertEqual(5, my_global_function(2, 3)) # NOTE: Wrong number of arguments is not a SYNTAX error, but a # runtime error. @@ -24,8 +26,9 @@ def test_calling_functions_with_wrong_number_of_arguments(self): # Note, the text comparison works for Python 3.2 # It has changed in the past and may change in the future - self.assertRegex(msg, - r'my_global_function\(\) missing 2 required positional arguments') + self.assertRegex( + msg, r"my_global_function\(\) missing 2 required positional arguments" + ) try: my_global_function(1, 2, 3) @@ -33,7 +36,9 @@ def test_calling_functions_with_wrong_number_of_arguments(self): msg = e.args[0] # Note, watch out for parenthesis. They need slashes in front! - self.assertRegex(msg, __) + self.assertRegex( + msg, r"my_global_function\(\) takes exactly 2 arguments \(3 given\)" + ) # ------------------------------------------------------------------ @@ -41,18 +46,18 @@ def pointless_method(self, a, b): sum = a + b def test_which_does_not_return_anything(self): - self.assertEqual(__, self.pointless_method(1, 2)) + self.assertEqual(None, self.pointless_method(1, 2)) # Notice that methods accessed from class scope do not require # you to pass the first "self" argument? # ------------------------------------------------------------------ - def method_with_defaults(self, a, b='default_value'): + def method_with_defaults(self, a, b="default_value"): return [a, b] def test_calling_with_default_values(self): - self.assertEqual(__, self.method_with_defaults(1)) - self.assertEqual(__, self.method_with_defaults(1, 2)) + self.assertEqual([1, "default_value"], self.method_with_defaults(1)) + self.assertEqual([1, 2], self.method_with_defaults(1, 2)) # ------------------------------------------------------------------ @@ -60,9 +65,9 @@ def method_with_var_args(self, *args): return args def test_calling_with_variable_arguments(self): - self.assertEqual(__, self.method_with_var_args()) - self.assertEqual(('one',), self.method_with_var_args('one')) - self.assertEqual(__, self.method_with_var_args('one', 'two')) + self.assertEqual(tuple(), self.method_with_var_args()) + self.assertEqual(("one",), self.method_with_var_args("one")) + self.assertEqual(("one", "two"), self.method_with_var_args("one", "two")) # ------------------------------------------------------------------ @@ -73,13 +78,13 @@ def test_functions_without_self_arg_are_global_functions(self): def function_with_the_same_name(a, b): return a * b - self.assertEqual(__, function_with_the_same_name(3,4)) + self.assertEqual(12, function_with_the_same_name(3, 4)) def test_calling_methods_in_same_class_with_explicit_receiver(self): def function_with_the_same_name(a, b): return a * b - self.assertEqual(__, self.function_with_the_same_name(3,4)) + self.assertEqual(7, self.function_with_the_same_name(3, 4)) # ------------------------------------------------------------------ @@ -92,10 +97,10 @@ def another_method_with_the_same_name(self): return 42 def test_that_old_methods_are_hidden_by_redefinitions(self): - self.assertEqual(__, self.another_method_with_the_same_name()) + self.assertEqual(42, self.another_method_with_the_same_name()) def test_that_overlapped_method_is_still_there(self): - self.assertEqual(__, self.link_to_overlapped_method()) + self.assertEqual(10, self.link_to_overlapped_method()) # ------------------------------------------------------------------ @@ -103,21 +108,22 @@ def empty_method(self): pass def test_methods_that_do_nothing_need_to_use_pass_as_a_filler(self): - self.assertEqual(__, self.empty_method()) + self.assertEqual(None, self.empty_method()) def test_pass_does_nothing_at_all(self): "You" "shall" "not" pass - self.assertEqual(____, "Still got to this line" != None) + self.assertEqual(True, "Still got to this line" != None) # ------------------------------------------------------------------ - def one_line_method(self): return 'Madagascar' + def one_line_method(self): + return "Madagascar" def test_no_indentation_required_for_one_line_statement_bodies(self): - self.assertEqual(__, self.one_line_method()) + self.assertEqual("Madagascar", self.one_line_method()) # ------------------------------------------------------------------ @@ -126,7 +132,10 @@ def method_with_documentation(self): return "ok" def test_the_documentation_can_be_viewed_with_the_doc_method(self): - self.assertRegex(self.method_with_documentation.__doc__, __) + self.assertRegex( + self.method_with_documentation.__doc__, + "A string placed at the beginning of a function is used for documentation", + ) # ------------------------------------------------------------------ @@ -139,24 +148,27 @@ def _tail(self): return "wagging" def __password(self): - return 'password' # Genius! + return "password" # Genius! def test_calling_methods_in_other_objects(self): rover = self.Dog() - self.assertEqual(__, rover.name()) + self.assertEqual("Fido", rover.name()) def test_private_access_is_implied_but_not_enforced(self): rover = self.Dog() # This is a little rude, but legal - self.assertEqual(__, rover._tail()) + self.assertEqual("wagging", rover._tail()) - def test_attributes_with_double_underscore_prefixes_are_subject_to_name_mangling(self): + def test_attributes_with_double_underscore_prefixes_are_subject_to_name_mangling( + self, + ): rover = self.Dog() - with self.assertRaises(___): password = rover.__password() + with self.assertRaises(AttributeError): + password = rover.__password() # But this still is! - self.assertEqual(__, rover._Dog__password()) + self.assertEqual("password", rover._Dog__password()) # Name mangling exists to avoid name clash issues when subclassing. # It is not for providing effective access protection diff --git a/koans/about_none.py b/koans/about_none.py index 1731f0108..bad62a1c6 100644 --- a/koans/about_none.py +++ b/koans/about_none.py @@ -7,15 +7,15 @@ from runner.koan import * -class AboutNone(Koan): +class AboutNone(Koan): def test_none_is_an_object(self): "Unlike NULL in a lot of languages" - self.assertEqual(__, isinstance(None, object)) + self.assertEqual(True, isinstance(None, object)) def test_none_is_universal(self): "There is only one None" - self.assertEqual(____, None is None) + self.assertEqual(True, None is None) def test_what_exception_do_you_get_when_calling_nonexistent_methods(self): """ @@ -37,15 +37,18 @@ def test_what_exception_do_you_get_when_calling_nonexistent_methods(self): # # https://github.com/gregmalcolm/python_koans/wiki/Class-Attribute - self.assertEqual(__, ex2.__class__) + self.assertEqual(AttributeError, ex2.__class__) # What message was attached to the exception? # (HINT: replace __ with part of the error message.) - self.assertRegex(ex2.args[0], __) + self.assertRegex( + ex2.args[0], + "'NoneType' object has no attribute 'some_method_none_does_not_know_about'", + ) def test_none_is_distinct(self): """ None is distinct from other things which are False. """ - self.assertEqual(__, None is not 0) - self.assertEqual(__, None is not False) + self.assertEqual(True, None is not 0) + self.assertEqual(True, None is not False) diff --git a/koans/about_string_manipulation.py b/koans/about_string_manipulation.py index 5204f29ba..f8e11e09b 100644 --- a/koans/about_string_manipulation.py +++ b/koans/about_string_manipulation.py @@ -3,72 +3,73 @@ from runner.koan import * -class AboutStringManipulation(Koan): +class AboutStringManipulation(Koan): def test_use_format_to_interpolate_variables(self): - value1 = 'one' + value1 = "one" value2 = 2 string = "The values are {0} and {1}".format(value1, value2) - self.assertEqual(__, string) + self.assertEqual("The values are one and 2", string) def test_formatted_values_can_be_shown_in_any_order_or_be_repeated(self): - value1 = 'doh' - value2 = 'DOH' + value1 = "doh" + value2 = "DOH" string = "The values are {1}, {0}, {0} and {1}!".format(value1, value2) - self.assertEqual(__, string) + self.assertEqual("The values are DOH, doh, doh and DOH!", string) def test_any_python_expression_may_be_interpolated(self): - import math # import a standard python module with math functions + import math # import a standard python module with math functions decimal_places = 4 - string = "The square root of 5 is {0:.{1}f}".format(math.sqrt(5), - decimal_places) - self.assertEqual(__, string) + string = "The square root of 5 is {0:.{1}f}".format( + math.sqrt(5), decimal_places + ) + self.assertEqual("The square root of 5 is 2.2361", string) def test_you_can_get_a_substring_from_a_string(self): string = "Bacon, lettuce and tomato" - self.assertEqual(__, string[7:10]) + self.assertEqual("let", string[7:10]) def test_you_can_get_a_single_character_from_a_string(self): string = "Bacon, lettuce and tomato" - self.assertEqual(__, string[1]) + self.assertEqual("a", string[1]) def test_single_characters_can_be_represented_by_integers(self): - self.assertEqual(__, ord('a')) - self.assertEqual(__, ord('b') == (ord('a') + 1)) + self.assertEqual(97, ord("a")) + self.assertEqual(True, ord("b") == (ord("a") + 1)) def test_strings_can_be_split(self): string = "Sausage Egg Cheese" words = string.split() - self.assertListEqual([__, __, __], words) + self.assertListEqual(["Sausage", "Egg", "Cheese"], words) def test_strings_can_be_split_with_different_patterns(self): - import re #import python regular expression library + import re # import python regular expression library string = "the,rain;in,spain" - pattern = re.compile(',|;') + pattern = re.compile(",|;") words = pattern.split(string) - self.assertListEqual([__, __, __, __], words) + self.assertListEqual(["the", "rain", "in", "spain"], words) # Pattern is a Python regular expression pattern which matches ',' or ';' def test_raw_strings_do_not_interpret_escape_characters(self): - string = r'\n' - self.assertNotEqual('\n', string) - self.assertEqual(__, string) - self.assertEqual(__, len(string)) + string = r"\n" + self.assertNotEqual("\n", string) + self.assertEqual("\\n", string) + self.assertEqual(2, len(string)) # Useful in regular expressions, file paths, URLs, etc. def test_strings_can_be_joined(self): words = ["Now", "is", "the", "time"] - self.assertEqual(__, ' '.join(words)) + self.assertEqual("Now is the time", " ".join(words)) def test_strings_can_change_case(self): - self.assertEqual(__, 'guido'.capitalize()) - self.assertEqual(__, 'guido'.upper()) - self.assertEqual(__, 'TimBot'.lower()) - self.assertEqual(__, 'guido van rossum'.title()) - self.assertEqual(__, 'ToTaLlY aWeSoMe'.swapcase()) + self.assertEqual("Guido", "guido".capitalize()) + self.assertEqual("GUIDO", "guido".upper()) + self.assertEqual("timbot", "TimBot".lower()) + self.assertEqual("Guido Van Rossum", "guido van rossum".title()) + self.assertEqual("tOtAlLy AwEsOmE", "ToTaLlY aWeSoMe".swapcase()) diff --git a/koans/about_strings.py b/koans/about_strings.py index 25f5f59df..ec8461956 100644 --- a/koans/about_strings.py +++ b/koans/about_strings.py @@ -3,92 +3,92 @@ from runner.koan import * -class AboutStrings(Koan): +class AboutStrings(Koan): def test_double_quoted_strings_are_strings(self): string = "Hello, world." - self.assertEqual(__, isinstance(string, str)) + self.assertEqual(True, isinstance(string, str)) def test_single_quoted_strings_are_also_strings(self): - string = 'Goodbye, world.' - self.assertEqual(__, isinstance(string, str)) + string = "Goodbye, world." + self.assertEqual(True, isinstance(string, str)) def test_triple_quote_strings_are_also_strings(self): string = """Howdy, world!""" - self.assertEqual(__, isinstance(string, str)) + self.assertEqual(True, isinstance(string, str)) def test_triple_single_quotes_work_too(self): - string = '''Bonjour tout le monde!''' - self.assertEqual(__, isinstance(string, str)) + string = """Bonjour tout le monde!""" + self.assertEqual(True, isinstance(string, str)) def test_raw_strings_are_also_strings(self): string = r"Konnichi wa, world!" - self.assertEqual(__, isinstance(string, str)) + self.assertEqual(True, isinstance(string, str)) def test_use_single_quotes_to_create_string_with_double_quotes(self): string = 'He said, "Go Away."' - self.assertEqual(__, string) + self.assertEqual('He said, "Go Away."', string) def test_use_double_quotes_to_create_strings_with_single_quotes(self): string = "Don't" - self.assertEqual(__, string) + self.assertEqual("Don't", string) def test_use_backslash_for_escaping_quotes_in_strings(self): - a = "He said, \"Don't\"" + a = 'He said, "Don\'t"' b = 'He said, "Don\'t"' - self.assertEqual(__, (a == b)) + self.assertEqual(True, (a == b)) def test_use_backslash_at_the_end_of_a_line_to_continue_onto_the_next_line(self): string = "It was the best of times,\n\ It was the worst of times." - self.assertEqual(__, len(string)) + self.assertEqual(52, len(string)) def test_triple_quoted_strings_can_span_lines(self): string = """ Howdy, world! """ - self.assertEqual(__, len(string)) + self.assertEqual(15, len(string)) def test_triple_quoted_strings_need_less_escaping(self): - a = "Hello \"world\"." + a = 'Hello "world".' b = """Hello "world".""" - self.assertEqual(__, (a == b)) + self.assertEqual(True, (a == b)) def test_escaping_quotes_at_the_end_of_triple_quoted_string(self): string = """Hello "world\"""" - self.assertEqual(__, string) + self.assertEqual('Hello "world"', string) def test_plus_concatenates_strings(self): string = "Hello, " + "world" - self.assertEqual(__, string) + self.assertEqual("Hello, world", string) def test_adjacent_strings_are_concatenated_automatically(self): string = "Hello" ", " "world" - self.assertEqual(__, string) + self.assertEqual("Hello, world", string) def test_plus_will_not_modify_original_strings(self): hi = "Hello, " there = "world" string = hi + there - self.assertEqual(__, hi) - self.assertEqual(__, there) + self.assertEqual("Hello, ", hi) + self.assertEqual("world", there) def test_plus_equals_will_append_to_end_of_string(self): hi = "Hello, " there = "world" hi += there - self.assertEqual(__, hi) + self.assertEqual("Hello, world", hi) def test_plus_equals_also_leaves_original_string_unmodified(self): original = "Hello, " hi = original there = "world" hi += there - self.assertEqual(__, original) + self.assertEqual("Hello, ", original) def test_most_strings_interpret_escape_characters(self): string = "\n" - self.assertEqual('\n', string) + self.assertEqual("\n", string) self.assertEqual("""\n""", string) - self.assertEqual(__, len(string)) + self.assertEqual(1, len(string)) diff --git a/koans/about_true_and_false.py b/koans/about_true_and_false.py index 5f06a63db..9c5f57eaa 100644 --- a/koans/about_true_and_false.py +++ b/koans/about_true_and_false.py @@ -12,7 +12,7 @@ def truth_value(self, condition): return 'false stuff' def test_true_is_treated_as_true(self): - self.assertEqual(__, self.truth_value(True)) + self.assertEqual('true stuff', self.truth_value(True)) def test_false_is_treated_as_false(self): self.assertEqual(__, self.truth_value(False)) diff --git a/koans/about_tuples.py b/koans/about_tuples.py index 2d65ea8f1..0c2008865 100644 --- a/koans/about_tuples.py +++ b/koans/about_tuples.py @@ -3,10 +3,11 @@ from runner.koan import * + class AboutTuples(Koan): def test_creating_a_tuple(self): - count_of_three = (1, 2, 5) - self.assertEqual(__, count_of_three[2]) + count_of_three = (1, 2, 5) + self.assertEqual(5, count_of_three[2]) def test_tuples_are_immutable_so_item_assignment_is_not_possible(self): @@ -19,11 +20,12 @@ def test_tuples_are_immutable_so_item_assignment_is_not_possible(self): # Note, assertRegex() uses regular expression pattern matching, # so you don't have to copy the whole message. - self.assertRegex(msg, __) + self.assertRegex(msg, "'tuple' object does not support item assignment") def test_tuples_are_immutable_so_appending_is_not_possible(self): - count_of_three = (1, 2, 5) - with self.assertRaises(___): count_of_three.append("boom") + count_of_three = (1, 2, 5) + with self.assertRaises(AttributeError): + count_of_three.append("boom") # Tuples are less flexible than lists, but faster. @@ -34,34 +36,36 @@ def test_tuples_can_only_be_changed_through_replacement(self): list_count.append("boom") count_of_three = tuple(list_count) - self.assertEqual(__, count_of_three) + self.assertEqual((1, 2, 5, "boom"), count_of_three) def test_tuples_of_one_look_peculiar(self): - self.assertEqual(__, (1).__class__) - self.assertEqual(__, (1,).__class__) - self.assertEqual(__, ("I'm a tuple",).__class__) - self.assertEqual(__, ("Not a tuple").__class__) + self.assertEqual(int, (1).__class__) + self.assertEqual(tuple, (1,).__class__) + self.assertEqual(tuple, ("I'm a tuple",).__class__) + self.assertEqual(str, ("Not a tuple").__class__) def test_tuple_constructor_can_be_surprising(self): - self.assertEqual(__, tuple("Surprise!")) + self.assertEqual( + ("S", "u", "r", "p", "r", "i", "s", "e", "!"), tuple("Surprise!") + ) def test_creating_empty_tuples(self): - self.assertEqual(__ , ()) - self.assertEqual(__ , tuple()) #Sometimes less confusing + self.assertEqual(tuple(), ()) + self.assertEqual((), tuple()) # Sometimes less confusing def test_tuples_can_be_embedded(self): - lat = (37, 14, 6, 'N') - lon = (115, 48, 40, 'W') - place = ('Area 51', lat, lon) - self.assertEqual(__, place) + lat = (37, 14, 6, "N") + lon = (115, 48, 40, "W") + place = ("Area 51", lat, lon) + self.assertEqual(("Area 51", (37, 14, 6, "N"), (115, 48, 40, "W")), place) def test_tuples_are_good_for_representing_records(self): locations = [ - ("Illuminati HQ", (38, 52, 15.56, 'N'), (77, 3, 21.46, 'W')), - ("Stargate B", (41, 10, 43.92, 'N'), (1, 49, 34.29, 'W')), + ("Illuminati HQ", (38, 52, 15.56, "N"), (77, 3, 21.46, "W")), + ("Stargate B", (41, 10, 43.92, "N"), (1, 49, 34.29, "W")), ] - locations.append( ("Cthulu", (26, 40, 1, 'N'), (70, 45, 7, 'W')) ) + locations.append(("Cthulu", (26, 40, 1, "N"), (70, 45, 7, "W"))) - self.assertEqual(__, locations[2][0]) - self.assertEqual(__, locations[0][1][2]) + self.assertEqual("Cthulhu", locations[2][0]) + self.assertEqual(15.56, locations[0][1][2])