From 106e4476f0f83e58c3702f92ae53bfba537ebffa Mon Sep 17 00:00:00 2001 From: RJ Osborne Date: Sat, 22 Oct 2011 15:14:27 -0400 Subject: [PATCH 001/237] A bit better example for pop, proving by observation of the test result that the argument to pop is relative to the left of the list, not the end. --- python 2/koans/about_lists.py | 2 +- python 3/koans/about_lists.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python 2/koans/about_lists.py b/python 2/koans/about_lists.py index 94dfef4c3..ca998f3f6 100644 --- a/python 2/koans/about_lists.py +++ b/python 2/koans/about_lists.py @@ -71,7 +71,7 @@ def test_insertions(self): self.assertEqual(__, knight) def test_popping_lists(self): - stack = [10, 20, 30] + stack = [10, 20, 30, 40] stack.append('last') self.assertEqual(__, stack) diff --git a/python 3/koans/about_lists.py b/python 3/koans/about_lists.py index 474ecddc1..ae53fd153 100644 --- a/python 3/koans/about_lists.py +++ b/python 3/koans/about_lists.py @@ -72,7 +72,7 @@ def test_insertions(self): self.assertEqual(__, knight) def test_popping_lists(self): - stack = [10, 20, 30] + stack = [10, 20, 30, 40] stack.append('last') self.assertEqual(__, stack) From af143bfac366a136d6ad95c323c72a1ea229ba0e Mon Sep 17 00:00:00 2001 From: Lars Wiegman Date: Tue, 29 Nov 2011 12:05:47 +0100 Subject: [PATCH 002/237] Reformatted single-line functions to multi-line function to improve readability. --- python 2/koans/about_iteration.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/python 2/koans/about_iteration.py b/python 2/koans/about_iteration.py index b5a00a836..eb0aca2b9 100644 --- a/python 2/koans/about_iteration.py +++ b/python 2/koans/about_iteration.py @@ -40,7 +40,8 @@ def test_map_transforms_elements_of_a_list(self): self.assertEqual(__, mapped_seq) def test_filter_selects_certain_items_from_a_list(self): - def is_even(item): return (item % 2) == 0 + def is_even(item): + return (item % 2) == 0 seq = [1, 2, 3, 4, 5, 6] @@ -48,7 +49,8 @@ def is_even(item): return (item % 2) == 0 self.assertEqual(__, even_numbers) def test_just_return_first_item_found(self): - def is_big_name(item): return len(item) > 4 + def is_big_name(item): + return len(item) > 4 names = ["Jim", "Bill", "Clarence", "Doug", "Eli"] @@ -70,7 +72,7 @@ def add(self, accum, item): def multiply(self, accum, item): return accum * item - def test_reduce_will_blow_your_mind(self): + def test_reduce_will_blow_your_mind(self): result = reduce(self.add, [2, 3, 4]) self.assertEqual(__, result) @@ -82,7 +84,7 @@ def test_reduce_will_blow_your_mind(self): # ------------------------------------------------------------------ - def test_creating_lists_with_list_comprehensions(self): + def test_creating_lists_with_list_comprehensions(self): feast = ['lambs', 'sloths', 'orangutans', 'breakfast cereals', 'fruit bats'] comprehension = [delicacy.capitalize() for delicacy in feast] @@ -107,7 +109,8 @@ def test_all_iteration_methods_work_on_any_sequence_not_just_lists(self): # Files act like a collection of lines file = open("example_file.txt") - def make_upcase(line) : return line.strip().upper() + def make_upcase(line) : + return line.strip().upper() upcase_lines = map(make_upcase, file.readlines()) self.assertEqual(__, list(upcase_lines)) @@ -116,4 +119,5 @@ def make_upcase(line) : return line.strip().upper() finally: # Arg, this is ugly. # We will figure out how to fix this later. - if file: file.close() + if file: + file.close() From dac4856c2397f1c5e447c3d5514ced81f2174d67 Mon Sep 17 00:00:00 2001 From: Lars Wiegman Date: Tue, 29 Nov 2011 15:35:15 +0100 Subject: [PATCH 003/237] Reformatted single line functions for improved readability. --- python 3/koans/about_iteration.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/python 3/koans/about_iteration.py b/python 3/koans/about_iteration.py index 5d69651f7..d9d1e5ca2 100644 --- a/python 3/koans/about_iteration.py +++ b/python 3/koans/about_iteration.py @@ -53,7 +53,8 @@ def test_map_transforms_elements_of_a_list(self): # python 3. In python 2 map() would give you a list. def test_filter_selects_certain_items_from_a_list(self): - def is_even(item): return (item % 2) == 0 + def is_even(item): + return (item % 2) == 0 seq = [1, 2, 3, 4, 5, 6] even_numbers = list() @@ -64,7 +65,8 @@ def is_even(item): return (item % 2) == 0 self.assertEqual(__, even_numbers) def test_just_return_first_item_found(self): - def is_big_name(item): return len(item) > 4 + def is_big_name(item): + return len(item) > 4 names = ["Jim", "Bill", "Clarence", "Doug", "Eli"] name = None @@ -130,7 +132,8 @@ def test_all_iteration_methods_work_on_any_sequence_not_just_lists(self): # Files act like a collection of lines file = open("example_file.txt") - def make_upcase(line) : return line.strip().upper() + def make_upcase(line): + return line.strip().upper() upcase_lines = map(make_upcase, file.readlines()) self.assertEqual(__, list(upcase_lines)) @@ -139,4 +142,5 @@ def make_upcase(line) : return line.strip().upper() finally: # Arg, this is ugly. # We will figure out how to fix this later. - if file: file.close() + if file: + file.close() \ No newline at end of file From 08be471a32bee0fb2ca31e0fa9bda4d40553d92d Mon Sep 17 00:00:00 2001 From: Lars Wiegman Date: Tue, 29 Nov 2011 15:36:39 +0100 Subject: [PATCH 004/237] Improved formatting. --- python 2/koans/about_iteration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python 2/koans/about_iteration.py b/python 2/koans/about_iteration.py index eb0aca2b9..b24a9e7ba 100644 --- a/python 2/koans/about_iteration.py +++ b/python 2/koans/about_iteration.py @@ -109,7 +109,7 @@ def test_all_iteration_methods_work_on_any_sequence_not_just_lists(self): # Files act like a collection of lines file = open("example_file.txt") - def make_upcase(line) : + def make_upcase(line): return line.strip().upper() upcase_lines = map(make_upcase, file.readlines()) self.assertEqual(__, list(upcase_lines)) From 71dd0e579046849fd2c0640832cd18b2acce626a Mon Sep 17 00:00:00 2001 From: Lars Wiegman Date: Wed, 30 Nov 2011 12:15:49 +0100 Subject: [PATCH 005/237] Corrected example of package the koans hierarchy. --- python 2/koans/about_packages.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/python 2/koans/about_packages.py b/python 2/koans/about_packages.py index 245656dfa..a85f3c4c8 100644 --- a/python 2/koans/about_packages.py +++ b/python 2/koans/about_packages.py @@ -14,12 +14,11 @@ # contemplate_koans.py # koans/ # __init__.py -# __init__.py -# about_asserts.py -# about_attribute_access.py -# about_class_attributes.py -# about_classes.py -# ... +# about_asserts.py +# about_attribute_access.py +# about_class_attributes.py +# about_classes.py +# ... # a_package_folder/ # __init__.py # a_module.py From 270bbd6f2692d6803c34889664c2ae53bbfe7f12 Mon Sep 17 00:00:00 2001 From: Lars Wiegman Date: Wed, 30 Nov 2011 12:17:12 +0100 Subject: [PATCH 006/237] Corrected example of the koans package hierarchy. --- python 3/koans/about_packages.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/python 3/koans/about_packages.py b/python 3/koans/about_packages.py index 61f5c5fb5..e68a42d4c 100644 --- a/python 3/koans/about_packages.py +++ b/python 3/koans/about_packages.py @@ -14,12 +14,11 @@ # contemplate_koans.py # koans/ # __init__.py -# __init__.py -# about_asserts.py -# about_attribute_access.py -# about_class_attributes.py -# about_classes.py -# ... +# about_asserts.py +# about_attribute_access.py +# about_class_attributes.py +# about_classes.py +# ... # a_package_folder/ # __init__.py # a_module.py From afb69f5d885d5ff73c8e98f7a611852d4471c070 Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Thu, 1 Dec 2011 23:14:01 -0500 Subject: [PATCH 007/237] Fixed bad regex assert in Python 3 flavor of AboutGenerators --- python 3/koans/about_generators.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python 3/koans/about_generators.py b/python 3/koans/about_generators.py index e22b677c7..19790b62b 100644 --- a/python 3/koans/about_generators.py +++ b/python 3/koans/about_generators.py @@ -114,7 +114,9 @@ def test_before_sending_a_value_to_a_generator_next_must_be_called(self): try: generator.send(1+2) except TypeError as ex: - self.assertMatch(__, ex[0]) + ex2 = ex + + self.assertRegexpMatches(ex2.args[0], __) # ------------------------------------------------------------------ From d65e6904712416c663abd2a67dcf2d71153015c2 Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Fri, 10 Feb 2012 07:13:13 -0500 Subject: [PATCH 008/237] Merged generators fix from engored and pep8 fixes from sietsebb via bitbucket mirror --- python 2/koans/__init__.py | 2 +- python 2/koans/about_asserts.py | 15 +- python 2/koans/about_attribute_access.py | 128 ++++++++++-------- python 2/koans/about_class_attributes.py | 74 +++++----- python 2/koans/about_classes.py | 108 ++++++++------- python 2/koans/about_control_statements.py | 25 ++-- .../koans/about_decorating_with_classes.py | 23 ++-- .../koans/about_decorating_with_functions.py | 3 +- python 2/koans/about_deleting_objects.py | 12 +- python 2/koans/about_dice_project.py | 8 +- python 2/koans/about_dictionaries.py | 27 ++-- python 2/koans/about_exceptions.py | 1 + python 2/koans/about_extra_credit.py | 2 +- python 2/koans/about_generators.py | 25 ++-- python 2/koans/about_inheritance.py | 9 +- python 2/koans/about_iteration.py | 18 +-- python 2/koans/about_lambdas.py | 1 + python 2/koans/about_list_assignments.py | 1 + python 2/koans/about_lists.py | 3 +- python 2/koans/about_method_bindings.py | 13 +- python 2/koans/about_methods.py | 30 ++-- python 2/koans/about_modules.py | 23 ++-- python 2/koans/about_monkey_patching.py | 12 +- python 2/koans/about_multiple_inheritance.py | 62 ++++----- python 2/koans/about_new_style_classes.py | 8 +- python 2/koans/about_none.py | 11 +- python 2/koans/about_packages.py | 5 +- python 2/koans/about_proxy_object_project.py | 9 +- python 2/koans/about_regex.py | 112 +++++++++------ python 2/koans/about_scope.py | 8 +- python 2/koans/about_scoring_project.py | 38 +++--- python 2/koans/about_sets.py | 19 +-- python 2/koans/about_strings.py | 14 +- python 2/koans/about_triangle_project.py | 1 + python 2/koans/about_triangle_project2.py | 3 +- python 2/koans/about_true_and_false.py | 5 +- python 2/koans/about_tuples.py | 22 +-- python 2/koans/about_with_statements.py | 8 +- python 2/koans/another_local_module.py | 5 +- python 2/koans/jims.py | 1 + python 2/koans/joes.py | 1 + python 2/koans/local_module.py | 3 +- .../koans/local_module_with_all_defined.py | 5 +- python 2/koans/triangle.py | 4 +- python 3/koans/about_classes.py | 110 +++++++-------- 45 files changed, 554 insertions(+), 463 deletions(-) diff --git a/python 2/koans/__init__.py b/python 2/koans/__init__.py index 8d78ec0f1..a11870b25 100644 --- a/python 2/koans/__init__.py +++ b/python 2/koans/__init__.py @@ -1,4 +1,4 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# koans \ No newline at end of file +# koans diff --git a/python 2/koans/about_asserts.py b/python 2/koans/about_asserts.py index 3905498d3..1af8b4e8e 100644 --- a/python 2/koans/about_asserts.py +++ b/python 2/koans/about_asserts.py @@ -3,14 +3,15 @@ from runner.koan import * + class AboutAsserts(Koan): def test_assert_truth(self): """ We shall contemplate truth by testing reality, via asserts. """ - self.assertTrue(False) # This should be true - + self.assertTrue(False) # This should be true + def test_assert_with_message(self): """ Enlightenment may be more easily achieved with appropriate messages. @@ -25,7 +26,8 @@ def test_fill_in_values(self): def test_assert_equality(self): """ - To understand reality, we must compare our expectations against reality. + To understand reality, we must compare our expectations against + reality. """ expected_value = __ actual_value = 1 + 1 @@ -37,14 +39,13 @@ def test_a_better_way_of_asserting_equality(self): """ expected_value = __ actual_value = 1 + 1 - + self.assertEqual(expected_value, actual_value) - + def test_that_unittest_asserts_work_the_same_way_as_python_asserts(self): """ Knowing how things really work is half the battle """ - + # This throws an AssertionError exception assert False - diff --git a/python 2/koans/about_attribute_access.py b/python 2/koans/about_attribute_access.py index bcb293255..5e4fef063 100644 --- a/python 2/koans/about_attribute_access.py +++ b/python 2/koans/about_attribute_access.py @@ -7,20 +7,21 @@ from runner.koan import * + class AboutAttributeAccess(Koan): - + class TypicalObject(object): pass - + def test_calling_undefined_functions_normally_results_in_errors(self): typical = self.TypicalObject() - + try: typical.foobar() except Exception as exception: self.assertEqual(__, type(exception).__name__) self.assertMatch(__, exception[0]) - + def test_calling_getattribute_causes_an_attribute_error(self): typical = self.TypicalObject() @@ -28,109 +29,114 @@ def test_calling_getattribute_causes_an_attribute_error(self): typical.__getattribute__('foobar') except AttributeError as exception: self.assertMatch(__, exception[0]) - + # THINK ABOUT IT: # # If the method __getattribute__() causes the AttributeError, then # what would happen if we redefine __getattribute__()? - + # ------------------------------------------------------------------ - + class CatchAllAttributeReads(object): def __getattribute__(self, attr_name): - return "Someone called '" + attr_name + "' and it could not be found" - + return "Someone called '" + attr_name + \ + "' and it could not be found" + def test_all_attribute_reads_are_caught(self): catcher = self.CatchAllAttributeReads() - + self.assertMatch(__, catcher.foobar) def test_intercepting_return_values_can_disrupt_the_call_chain(self): catcher = self.CatchAllAttributeReads() - self.assertMatch(__, catcher.foobaz) # This is fine - + self.assertMatch(__, catcher.foobaz) # This is fine + try: catcher.foobaz(1) except TypeError as ex: self.assertMatch(__, ex[0]) - + # foobaz returns a string. What happens to the '(1)' part? # Try entering this into a python console to reproduce the issue: # # "foobaz"(1) - # - - def test_changes_to_the_getattribute_implementation_affects_getattr_function(self): + # + + def test_changing_getattribute_will_affect__the_getattr_function(self): catcher = self.CatchAllAttributeReads() - + self.assertMatch(__, getattr(catcher, 'any_attribute')) - + # ------------------------------------------------------------------ - + class WellBehavedFooCatcher(object): def __getattribute__(self, attr_name): if attr_name[:3] == "foo": return "Foo to you too" else: - return super(AboutAttributeAccess.WellBehavedFooCatcher, self). \ + return \ + super(AboutAttributeAccess.WellBehavedFooCatcher, self). \ __getattribute__(attr_name) - + def test_foo_attributes_are_caught(self): catcher = self.WellBehavedFooCatcher() - + self.assertEqual(__, catcher.foo_bar) self.assertEqual(__, catcher.foo_baz) - + def test_non_foo_messages_are_treated_normally(self): catcher = self.WellBehavedFooCatcher() - + try: catcher.normal_undefined_attribute except AttributeError as ex: self.assertMatch(__, ex[0]) # ------------------------------------------------------------------ - + global stack_depth - stack_depth = 0 + stack_depth = 0 class RecursiveCatcher(object): def __init__(self): global stack_depth - stack_depth = 0 + stack_depth = 0 self.no_of_getattribute_calls = 0 - + def __getattribute__(self, attr_name): #Uncomment for debugging info: - #print 'Debug __getattribute__(' + type(self).__name__ + "." + attr_name + ") dict=" + str(self.__dict__) - - global stack_depth # We need something that is outside the scope of this class + #print 'Debug __getattribute__(' + type(self).__name__ + \ + # "." + attr_name + ") dict=" + str(self.__dict__) + + # We need something that is outside the scope of this class: + global stack_depth stack_depth += 1 - if stack_depth<=10: # to prevent a stack overflow + if stack_depth <= 10: # to prevent a stack overflow self.no_of_getattribute_calls += 1 - # Oops! We just accessed an attribute (no_of_getattribute_calls) + # Oops! We just accessed an attribute: no_of_getattribute_calls # Guess what happens when self.no_of_getattribute_calls is - # accessed? + # accessed? # Using 'object' directly because using super() here will also # trigger a __getattribute__() call. - return object.__getattribute__(self, attr_name) - + return object.__getattribute__(self, attr_name) + def my_method(self): pass - + def test_getattribute_is_a_bit_overzealous_sometimes(self): catcher = self.RecursiveCatcher() catcher.my_method() global stack_depth self.assertEqual(__, stack_depth) - + # ------------------------------------------------------------------ class MinimalCatcher(object): - class DuffObject(object): pass + class DuffObject(object): + pass def __init__(self): self.no_of_getattr_calls = 0 @@ -138,7 +144,7 @@ def __init__(self): def __getattr__(self, attr_name): self.no_of_getattr_calls += 1 return self.DuffObject - + def my_method(self): pass @@ -147,62 +153,64 @@ def test_getattr_ignores_known_attributes(self): catcher.my_method() self.assertEqual(__, catcher.no_of_getattr_calls) - + def test_getattr_only_catches_unknown_attributes(self): catcher = self.MinimalCatcher() catcher.purple_flamingos() catcher.free_pie() - + self.assertEqual(__, type(catcher.give_me_duff_or_give_me_death()).__name__) - + self.assertEqual(__, catcher.no_of_getattr_calls) - + # ------------------------------------------------------------------ class PossessiveSetter(object): def __setattr__(self, attr_name, value): - new_attr_name = attr_name - + new_attr_name = attr_name + if attr_name[-5:] == 'comic': new_attr_name = "my_" + new_attr_name elif attr_name[-3:] == 'pie': - new_attr_name = "a_" + new_attr_name + new_attr_name = "a_" + new_attr_name - object.__setattr__(self, new_attr_name, value) + object.__setattr__(self, new_attr_name, value) def test_setattr_intercepts_attribute_assignments(self): fanboy = self.PossessiveSetter() - + fanboy.comic = 'The Laminator, issue #1' fanboy.pie = 'blueberry' - - self.assertEqual(__, fanboy.a_pie) + + self.assertEqual(__, fanboy.a_pie) prefix = '__' - self.assertEqual("The Laminator, issue #1", getattr(fanboy, prefix + '_comic')) + self.assertEqual( + "The Laminator, issue #1", + getattr(fanboy, prefix + '_comic')) # ------------------------------------------------------------------ - class ScarySetter(object): + class ScarySetter(object): def __init__(self): self.num_of_coconuts = 9 self._num_of_private_coconuts = 2 - + def __setattr__(self, attr_name, value): - new_attr_name = attr_name - + new_attr_name = attr_name + if attr_name[0] != '_': new_attr_name = "altered_" + new_attr_name - + object.__setattr__(self, new_attr_name, value) - + def test_it_modifies_external_attribute_as_expected(self): setter = self.ScarySetter() setter.e = "mc hammer" - + self.assertEqual(__, setter.altered_e) - + def test_it_mangles_some_internal_attributes(self): setter = self.ScarySetter() diff --git a/python 2/koans/about_class_attributes.py b/python 2/koans/about_class_attributes.py index dac8f59f4..d48211054 100644 --- a/python 2/koans/about_class_attributes.py +++ b/python 2/koans/about_class_attributes.py @@ -7,44 +7,45 @@ from runner.koan import * + class AboutClassAttributes(Koan): class Dog(object): pass - + def test_new_style_class_objects_are_objects(self): # Note: Old style class instances are not objects but they are being # phased out it Python 3. - + fido = self.Dog() self.assertEqual(__, isinstance(fido, object)) def test_classes_are_types(self): - self.assertEqual(__, self.Dog.__class__ == type) - + self.assertEqual(__, self.Dog.__class__ == type) + def test_classes_are_objects_too(self): self.assertEqual(__, issubclass(self.Dog, object)) - + def test_objects_have_methods(self): fido = self.Dog() self.assertEqual(__, len(dir(fido))) - + def test_classes_have_methods(self): self.assertEqual(__, len(dir(self.Dog))) def test_creating_objects_without_defining_a_class(self): - singularity = object() + singularity = object() self.assertEqual(__, len(dir(singularity))) def test_defining_attributes_on_individual_objects(self): fido = self.Dog() fido.legs = 4 - + self.assertEqual(__, fido.legs) - + def test_defining_functions_on_individual_objects(self): fido = self.Dog() - fido.wag = lambda : 'fidos wag' - + fido.wag = lambda: 'fidos wag' + self.assertEqual(__, fido.wag()) def test_other_objects_are_not_affected_by_these_singleton_functions(self): @@ -52,16 +53,16 @@ def test_other_objects_are_not_affected_by_these_singleton_functions(self): rover = self.Dog() def wag(): - return 'fidos wag' + return 'fidos wag' fido.wag = wag - + try: rover.wag() except Exception as ex: self.assertMatch(__, ex[0]) - + # ------------------------------------------------------------------ - + class Dog2(object): def wag(self): return 'instance wag' @@ -75,14 +76,14 @@ def growl(self): @staticmethod def bark(): return "staticmethod bark, arg: None" - + @classmethod def growl(cls): - return "classmethod growl, arg: cls=" + cls.__name__ - - def test_since_classes_are_objects_you_can_define_singleton_methods_on_them_too(self): + return "classmethod growl, arg: cls=" + cls.__name__ + + def test_like_all_objects_classes_can_have_singleton_methods(self): self.assertMatch(__, self.Dog2.growl()) - + def test_classmethods_are_not_independent_of_instance_methods(self): fido = self.Dog2() self.assertMatch(__, fido.growl()) @@ -94,9 +95,9 @@ def test_staticmethods_are_unbound_functions_housed_in_a_class(self): def test_staticmethods_also_overshadow_instance_methods(self): fido = self.Dog2() self.assertMatch(__, fido.bark()) - + # ------------------------------------------------------------------ - + class Dog3(object): def __init__(self): self._name = None @@ -106,40 +107,41 @@ def get_name_from_instance(self): def set_name_from_instance(self, name): self._name = name - - @classmethod + + @classmethod def get_name(cls): return cls._name - @classmethod + @classmethod def set_name(cls, name): cls._name = name - + name = property(get_name, set_name) - name_from_instance = property(get_name_from_instance, set_name_from_instance) - + name_from_instance = property( + get_name_from_instance, set_name_from_instance) + def test_classmethods_can_not_be_used_as_properties(self): fido = self.Dog3() try: fido.name = "Fido" except Exception as ex: self.assertMatch(__, ex[0]) - + def test_classes_and_instances_do_not_share_instance_attributes(self): fido = self.Dog3() fido.set_name_from_instance("Fido") fido.set_name("Rover") self.assertEqual(__, fido.get_name_from_instance()) self.assertEqual(__, self.Dog3.get_name()) - + def test_classes_and_instances_do_share_class_attributes(self): fido = self.Dog3() fido.set_name("Fido") self.assertEqual(__, fido.get_name()) self.assertEqual(__, self.Dog3.get_name()) - + # ------------------------------------------------------------------ - + class Dog4(object): def a_class_method(cls): return 'dogs class method' @@ -149,15 +151,15 @@ def a_static_method(): a_class_method = classmethod(a_class_method) a_static_method = staticmethod(a_static_method) - + def test_you_can_define_class_methods_without_using_a_decorator(self): self.assertEqual(__, self.Dog4.a_class_method()) def test_you_can_define_static_methods_without_using_a_decorator(self): self.assertEqual(__, self.Dog4.a_static_method()) - + # ------------------------------------------------------------------ - - def test_heres_an_easy_way_to_explicitly_call_class_methods_from_instance_methods(self): + + def test_you_can_explicitly_call_class_methods_from_instance_methods(self): fido = self.Dog4() self.assertEqual(__, fido.__class__.a_class_method()) diff --git a/python 2/koans/about_classes.py b/python 2/koans/about_classes.py index d23b43f00..564554bba 100644 --- a/python 2/koans/about_classes.py +++ b/python 2/koans/about_classes.py @@ -3,76 +3,76 @@ from runner.koan import * + class AboutClasses(Koan): class Dog(object): "Dogs need regular walkies. Never, ever let them drive." - - def test_instances_of_classes_can_be_created_adding_parenthesis(self): + + def test_instances_of_classes_can_be_created_adding_parentheses(self): fido = self.Dog() self.assertEqual(__, type(fido).__name__) - + def test_classes_have_docstrings(self): self.assertMatch(__, self.Dog.__doc__) - + # ------------------------------------------------------------------ - - class Dog2(object): - def __init__(self): + + class Dog2(object): + def __init__(self): self._name = 'Paul' - + def set_name(self, a_name): self._name = a_name - + def test_init_method_is_the_constructor(self): dog = self.Dog2() self.assertEqual(__, dog._name) - - def test_private_attributes_are_not_really_private(self): + + def test_private_attributes_are_not_really_private(self): dog = self.Dog2() dog.set_name("Fido") self.assertEqual(__, dog._name) # The _ prefix in _name implies private ownership, but nothing is truly # private in Python. - + def test_you_can_also_access_the_value_out_using_getattr_and_dict(self): fido = self.Dog2() fido.set_name("Fido") - + self.assertEqual(__, getattr(fido, "_name")) # getattr(), setattr() and delattr() are a way of accessing attributes # by method rather than through assignment operators - + self.assertEqual(__, fido.__dict__["_name"]) # Yes, this works here, but don't rely on the __dict__ object! Some # class implementations use optimization which result in __dict__ not # showing everything. - + # ------------------------------------------------------------------ - + class Dog3(object): - def __init__(self): + def __init__(self): self._name = None def set_name(self, a_name): self._name = a_name - + def get_name(self): return self._name - + name = property(get_name, set_name) - - + def test_that_name_can_be_read_as_a_property(self): fido = self.Dog3() fido.set_name("Fido") - - self.assertEqual(__, fido.get_name()) # access as method - self.assertEqual(__, fido.name) # access as property - + + self.assertEqual(__, fido.get_name()) # access as method + self.assertEqual(__, fido.name) # access as property + # ------------------------------------------------------------------ - + class Dog4(object): - def __init__(self): + def __init__(self): self._name = None @property @@ -82,78 +82,76 @@ def name(self): @name.setter def name(self, a_name): self._name = a_name - + def test_creating_properties_with_decorators_is_slightly_easier(self): fido = self.Dog4() - + fido.name = "Fido" self.assertEqual(__, fido.name) - + # ------------------------------------------------------------------ - + class Dog5(object): - def __init__(self, initial_name): + def __init__(self, initial_name): self._name = initial_name @property def name(self): return self._name - + def test_init_provides_initial_values_for_instance_variables(self): - fido = self.Dog5("Fido") + fido = self.Dog5("Fido") self.assertEqual(__, fido.name) - + def test_args_must_match_init(self): - self.assertRaises(___, self.Dog5) # Evaluates self.Dog5() - + self.assertRaises(___, self.Dog5) # Evaluates self.Dog5() + # THINK ABOUT IT: # Why is this so? - + def test_different_objects_have_difference_instance_variables(self): fido = self.Dog5("Fido") rover = self.Dog5("Rover") - + self.assertEqual(____, rover.name == fido.name) - + # ------------------------------------------------------------------ - + class Dog6(object): def __init__(self, initial_name): self._name = initial_name - + def get_self(self): return self - + def __str__(self): return __ - + def __repr__(self): return "" - def test_inside_a_method_self_refers_to_the_containing_object(self): fido = self.Dog6("Fido") - - self.assertEqual(__, fido.get_self()) # Not a string! - + + self.assertEqual(__, fido.get_self()) # Not a string! + def test_str_provides_a_string_version_of_the_object(self): fido = self.Dog6("Fido") self.assertEqual("Fido", str(fido)) - + def test_str_is_used_explicitly_in_string_interpolation(self): fido = self.Dog6("Fido") self.assertEqual(__, "My dog is " + str(fido)) - + def test_repr_provides_a_more_complete_string_version(self): fido = self.Dog6("Fido") self.assertEqual(__, repr(fido)) - + def test_all_objects_support_str_and_repr(self): - seq = [1,2,3] - + seq = [1, 2, 3] + self.assertEqual(__, str(seq)) self.assertEqual(__, repr(seq)) - + self.assertEqual(__, str("STRING")) self.assertEqual(__, repr("STRING")) - diff --git a/python 2/koans/about_control_statements.py b/python 2/koans/about_control_statements.py index 7b3d30c9a..921f0bf7f 100644 --- a/python 2/koans/about_control_statements.py +++ b/python 2/koans/about_control_statements.py @@ -3,6 +3,7 @@ from runner.koan import * + class AboutControlStatements(Koan): def test_if_then_else_statements(self): @@ -17,7 +18,7 @@ def test_if_then_statements(self): if True: result = 'true value' self.assertEqual(__, result) - + def test_while_statement(self): i = 1 result = 1 @@ -25,7 +26,7 @@ def test_while_statement(self): result = result * i i += 1 self.assertEqual(__, result) - + def test_break_statement(self): i = 1 result = 1 @@ -34,39 +35,39 @@ def test_break_statement(self): result = result * i i += 1 self.assertEqual(__, result) - + def test_continue_statement(self): i = 0 result = [] while i < 10: i += 1 if (i % 2) == 0: continue - result.append(i) + result.append(i) self.assertEqual(__, result) - + def test_for_statement(self): phrase = ["fish", "and", "chips"] result = [] for item in phrase: result.append(item.upper()) self.assertEqual([__, __, __], result) - + def test_for_statement_with_tuples(self): round_table = [ - ("Lancelot", "Blue"), + ("Lancelot", "Blue"), ("Galahad", "I don't know!"), ("Robin", "Blue! I mean Green!"), ("Arthur", "Is that an African Swallow or Amazonian Swallow?") ] result = [] for knight, answer in round_table: - result.append("Contestant: '" + knight + "' Answer: '" + answer + "'") - + result.append("Contestant: '" + knight + \ + "' Answer: '" + answer + "'") + text = __ - + self.assertMatch(text, result[2]) - + self.assertNoMatch(text, result[0]) self.assertNoMatch(text, result[1]) self.assertNoMatch(text, result[3]) - \ No newline at end of file diff --git a/python 2/koans/about_decorating_with_classes.py b/python 2/koans/about_decorating_with_classes.py index 9617cf01e..bcbc29bc6 100644 --- a/python 2/koans/about_decorating_with_classes.py +++ b/python 2/koans/about_decorating_with_classes.py @@ -4,10 +4,11 @@ from runner.koan import * import functools - + + class AboutDecoratingWithClasses(Koan): def maximum(self, a, b): - if a>b: + if a > b: return a else: return b @@ -18,9 +19,9 @@ def test_partial_that_wrappers_no_args(self): the partial. """ max = functools.partial(self.maximum) - - self.assertEqual(__, max(7,23)) - self.assertEqual(__, max(10,-10)) + + self.assertEqual(__, max(7, 23)) + self.assertEqual(__, max(10, -10)) def test_partial_that_wrappers_first_arg(self): max0 = functools.partial(self.maximum, 0) @@ -28,7 +29,7 @@ def test_partial_that_wrappers_first_arg(self): self.assertEqual(__, max0(-4)) self.assertEqual(__, max0(5)) - def test_partial_that_wrappers_all_args(self): + def test_partial_that_wrappers_all_args(self): always99 = functools.partial(self.maximum, 99, 20) always20 = functools.partial(self.maximum, 9, 20) @@ -50,7 +51,7 @@ def __get__(self, obj, cls=None): return self else: # Decorating a bound method - return functools.partial(self, obj) + return functools.partial(self, obj) @doubleit def foo(self): @@ -70,7 +71,7 @@ def test_decorator_with_no_arguments(self): # ------------------------------------------------------------------ def sound_check(self): - #Note: no decorator + #Note: no decorator return "Testing..." def test_what_a_decorator_is_doing_to_a_function(self): @@ -98,10 +99,11 @@ def decorated_function(*args): @documenter("Increments a value by one. Kind of.") def count_badly(self, num): num += 1 - if num==3: - return 5 + if num == 3: + return 5 else: num + @documenter("Does nothing") def idler(self, num): "Idler" @@ -125,4 +127,3 @@ def homer(self): def test_we_can_chain_decorators(self): self.assertEqual(__, self.homer()) self.assertEqual(__, self.homer.__doc__) - \ No newline at end of file diff --git a/python 2/koans/about_decorating_with_functions.py b/python 2/koans/about_decorating_with_functions.py index 69cd02d93..c38a87faa 100644 --- a/python 2/koans/about_decorating_with_functions.py +++ b/python 2/koans/about_decorating_with_functions.py @@ -15,7 +15,7 @@ def mediocre_song(self): def test_decorators_can_modify_a_function(self): self.assertMatch(__, self.mediocre_song()) - self.assertEqual(__, self.mediocre_song.wow_factor) + self.assertEqual(__, self.mediocre_song.wow_factor) # ------------------------------------------------------------------ @@ -30,4 +30,3 @@ def render_tag(self, name): def test_decorators_can_change_a_function_output(self): self.assertEqual(__, self.render_tag('llama')) - diff --git a/python 2/koans/about_deleting_objects.py b/python 2/koans/about_deleting_objects.py index c47583051..ac1da15b8 100644 --- a/python 2/koans/about_deleting_objects.py +++ b/python 2/koans/about_deleting_objects.py @@ -3,6 +3,7 @@ from runner.koan import * + class AboutDeletingObjects(Koan): def test_del_can_remove_slices(self): lottery_nums = [4, 8, 15, 16, 23, 42] @@ -17,10 +18,10 @@ def test_del_can_remove_entire_lists(self): try: win = lottery_nums except Exception as e: - pass + pass self.assertMatch(__, e[0]) - # ==================================================================== + # -------------------------------------------------------------------- class ClosingSale(object): def __init__(self): @@ -54,7 +55,7 @@ def test_del_can_remove_attributes(self): self.assertMatch(__, err_msg1) self.assertMatch(__, err_msg2) - # ==================================================================== + # -------------------------------------------------------------------- class ClintEastwood(object): def __init__(self): @@ -83,8 +84,7 @@ def test_del_works_with_properties(self): del cowboy.name self.assertEqual(__, cowboy.name) - - # ==================================================================== + # -------------------------------------------------------------------- class Prisoner(object): def __init__(self): @@ -110,7 +110,7 @@ def test_another_way_to_make_a_deletable_property(self): del citizen.name self.assertEqual(__, citizen.name) - # ==================================================================== + # -------------------------------------------------------------------- class MoreOrganisedClosingSale(ClosingSale): def __init__(self): diff --git a/python 2/koans/about_dice_project.py b/python 2/koans/about_dice_project.py index f16deed7b..830f4c8df 100644 --- a/python 2/koans/about_dice_project.py +++ b/python 2/koans/about_dice_project.py @@ -5,11 +5,12 @@ import random + class DiceSet(object): def __init__(self): self._values = None - @property + @property def values(self): return self._values @@ -18,6 +19,7 @@ def roll(self, n): # Tip: random.randint(min, max) can be used to generate random numbers pass + class AboutDiceProject(Koan): def test_can_create_a_dice_set(self): dice = DiceSet() @@ -30,7 +32,9 @@ def test_rolling_the_dice_returns_a_set_of_integers_between_1_and_6(self): self.assertTrue(isinstance(dice.values, list), "should be a list") self.assertEqual(5, len(dice.values)) for value in dice.values: - self.assertTrue(value >= 1 and value <= 6, "value " + str(value) + " must be between 1 and 6") + self.assertTrue( + value >= 1 and value <= 6, + "value " + str(value) + " must be between 1 and 6") def test_dice_values_do_not_change_unless_explicitly_rolled(self): dice = DiceSet() diff --git a/python 2/koans/about_dictionaries.py b/python 2/koans/about_dictionaries.py index 37a21716f..25c13062a 100644 --- a/python 2/koans/about_dictionaries.py +++ b/python 2/koans/about_dictionaries.py @@ -7,6 +7,7 @@ from runner.koan import * + class AboutDictionaries(Koan): def test_creating_dictionaries(self): empty_dict = dict() @@ -15,45 +16,47 @@ def test_creating_dictionaries(self): self.assertEqual(__, len(empty_dict)) def test_dictionary_literals(self): - babel_fish = { 'one': "uno", 'two': "dos" } + babel_fish = {'one': "uno", 'two': "dos"} self.assertEqual(__, len(babel_fish)) def test_accessing_dictionaries(self): - babel_fish = { 'one': "uno", 'two': "dos" } + babel_fish = {'one': "uno", 'two': "dos"} self.assertEqual(__, babel_fish['one']) self.assertEqual(__, babel_fish['two']) def test_changing_dictionaries(self): - babel_fish = { 'one': "uno", 'two': "dos" } + babel_fish = {'one': "uno", 'two': "dos"} babel_fish['one'] = "eins" - expected = { 'two': "dos", 'one': __ } + expected = {'two': "dos", 'one': __} self.assertEqual(expected, babel_fish) def test_dictionary_is_unordered(self): - dict1 = { 'one': "uno", 'two': "dos" } - dict2 = { 'two': "dos", 'one': "uno" } + dict1 = {'one': "uno", 'two': "dos"} + dict2 = {'two': "dos", 'one': "uno"} self.assertEqual(____, dict1 == dict2) def test_dictionary_keys(self): - babel_fish = { 'one': "uno", 'two': "dos" } + babel_fish = {'one': "uno", 'two': "dos"} self.assertEqual(__, len(babel_fish.keys())) - self.assertEqual(__, 'one' in babel_fish) - self.assertEqual(__, 'two' in babel_fish) + self.assertEqual(__, 'one' in babel_fish) + self.assertEqual(__, 'two' in babel_fish) self.assertEqual(list, babel_fish.keys().__class__) def test_dictionary_values(self): - babel_fish = { 'one': "uno", 'two': "dos" } + babel_fish = {'one': "uno", 'two': "dos"} self.assertEqual(__, len(babel_fish.values())) self.assertEqual(__, 'uno' in babel_fish.values()) self.assertEqual(__, 'dos' in babel_fish.values()) self.assertEqual(list, babel_fish.values().__class__) 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) + 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"]) - diff --git a/python 2/koans/about_exceptions.py b/python 2/koans/about_exceptions.py index 22d94a7c6..c8bae3b44 100644 --- a/python 2/koans/about_exceptions.py +++ b/python 2/koans/about_exceptions.py @@ -3,6 +3,7 @@ from runner.koan import * + class AboutExceptions(Koan): class MySpecialError(RuntimeError): diff --git a/python 2/koans/about_extra_credit.py b/python 2/koans/about_extra_credit.py index 54baef4ea..f37732154 100644 --- a/python 2/koans/about_extra_credit.py +++ b/python 2/koans/about_extra_credit.py @@ -12,9 +12,9 @@ from runner.koan import * + class AboutExtraCredit(Koan): # Write tests here. If you need extra test classes add them to the # test suite in runner/path_to_enlightenment.py def test_extra_credit_task(self): pass - \ No newline at end of file diff --git a/python 2/koans/about_generators.py b/python 2/koans/about_generators.py index 9cc11212a..1b10ad90c 100644 --- a/python 2/koans/about_generators.py +++ b/python 2/koans/about_generators.py @@ -10,28 +10,31 @@ from runner.koan import * + class AboutGenerators(Koan): def test_generating_values_on_the_fly(self): result = list() - bacon_generator = (n + ' bacon' for n in ['crunchy','veggie','danish']) + bacon_generator = (n + ' bacon' for \ + n in ['crunchy', 'veggie', 'danish']) for bacon in bacon_generator: result.append(bacon) self.assertEqual(__, result) def test_generators_are_different_to_list_comprehensions(self): - num_list = [x*2 for x in range(1,3)] - num_generator = (x*2 for x in range(1,3)) + num_list = [x * 2 for x in range(1, 3)] + num_generator = (x * 2 for x in range(1, 3)) self.assertEqual(2, num_list[0]) # A generator has to be iterated through. - self.assertRaises(___, num_generator, [0]) # Evaluates num_generator[0] + self.assertRaises(___, num_generator[0]) # Evaluates num_generator[0] self.assertEqual(__, list(num_generator)[0]) # This works though - # Both list comprehensions and generators can be iterated though. However, a generator - # function is only called on the first iteration. The values are generated on the fly - # instead of stored. + # Both list comprehensions and generators can be iterated + # though. However, a generator function is only called on the + # first iteration. The values are generated on the fly instead + # of stored. # # Generators are more memory friendly, but less versatile @@ -71,7 +74,7 @@ def square_me(self, seq): yield x * x def test_generator_method_with_parameter(self): - result = self.square_me(range(2,5)) + result = self.square_me(range(2, 5)) self.assertEqual(__, list(result)) # ------------------------------------------------------------------ @@ -84,7 +87,7 @@ def sum_it(self, seq): yield value def test_generator_keeps_track_of_local_variables(self): - result = self.sum_it(range(2,5)) + result = self.sum_it(range(2, 5)) self.assertEqual(__, list(result)) # ------------------------------------------------------------------ @@ -109,7 +112,7 @@ def test_before_sending_a_value_to_a_generator_next_must_be_called(self): generator = self.generator_with_coroutine() try: - generator.send(1+2) + generator.send(1 + 2) except TypeError as ex: self.assertMatch(__, ex[0]) @@ -137,5 +140,3 @@ def test_send_none_is_equivelant_to_next(self): next(generator) # 'next(generator)' is exactly equivelant to 'generator.send(None)' self.assertEqual(__, generator.send(None)) - - diff --git a/python 2/koans/about_inheritance.py b/python 2/koans/about_inheritance.py index bebb0f93f..774f865f9 100644 --- a/python 2/koans/about_inheritance.py +++ b/python 2/koans/about_inheritance.py @@ -3,9 +3,10 @@ from runner.koan import * + class AboutInheritance(Koan): class Dog(object): - def __init__(self, name): + def __init__(self, name): self._name = name @property @@ -72,11 +73,11 @@ def test_super_works_across_methods(self): # --------------------------------------------------------- class Pug(Dog): - def __init__(self, name): + def __init__(self, name): pass class Greyhound(Dog): - def __init__(self, name): + def __init__(self, name): super(AboutInheritance.Greyhound, self).__init__(name) def test_base_init_does_not_get_called_automatically(self): @@ -88,4 +89,4 @@ def test_base_init_does_not_get_called_automatically(self): def test_base_init_has_to_be_called_explicitly(self): boxer = self.Greyhound("Boxer") - self.assertEqual(__, boxer.name) \ No newline at end of file + self.assertEqual(__, boxer.name) diff --git a/python 2/koans/about_iteration.py b/python 2/koans/about_iteration.py index b24a9e7ba..af4598a50 100644 --- a/python 2/koans/about_iteration.py +++ b/python 2/koans/about_iteration.py @@ -3,20 +3,21 @@ from runner.koan import * + class AboutIteration(Koan): def test_iterators_are_a_type(self): - it = iter(range(1,6)) + it = iter(range(1, 6)) fib = 0 for num in it: fib += num - self.assertEqual(__ , fib) + self.assertEqual(__, fib) def test_iterating_with_next(self): - stages = iter(['alpha','beta','gamma']) + stages = iter(['alpha', 'beta', 'gamma']) try: self.assertEqual(__, next(stages)) @@ -73,10 +74,10 @@ def multiply(self, accum, item): return accum * item def test_reduce_will_blow_your_mind(self): - result = reduce(self.add, [2, 3, 4]) + result = reduce(self.add, [2, 3, 4]) self.assertEqual(__, result) - result2 = reduce(self.multiply, [2, 3, 4], 1) + result2 = reduce(self.multiply, [2, 3, 4], 1) self.assertEqual(__, result2) # Extra Credit: @@ -85,7 +86,8 @@ def test_reduce_will_blow_your_mind(self): # ------------------------------------------------------------------ def test_creating_lists_with_list_comprehensions(self): - feast = ['lambs', 'sloths', 'orangutans', 'breakfast cereals', 'fruit bats'] + feast = ['lambs', 'sloths', 'orangutans', 'breakfast cereals', + 'fruit bats'] comprehension = [delicacy.capitalize() for delicacy in feast] @@ -93,7 +95,7 @@ def test_creating_lists_with_list_comprehensions(self): self.assertEqual(__, comprehension[2]) def test_use_pass_for_iterations_with_no_body(self): - for num in range(1,5): + for num in range(1, 5): pass self.assertEqual(__, num) @@ -102,7 +104,7 @@ def test_use_pass_for_iterations_with_no_body(self): def test_all_iteration_methods_work_on_any_sequence_not_just_lists(self): # Ranges are an iteratable sequence - result = map(self.add_ten, range(1,4)) + result = map(self.add_ten, range(1, 4)) self.assertEqual(__, list(result)) try: diff --git a/python 2/koans/about_lambdas.py b/python 2/koans/about_lambdas.py index 2268e6c65..a6f5611e6 100644 --- a/python 2/koans/about_lambdas.py +++ b/python 2/koans/about_lambdas.py @@ -7,6 +7,7 @@ from runner.koan import * + class AboutLambdas(Koan): def test_lambdas_can_be_assigned_to_variables_and_called_explicitly(self): add_one = lambda n: n + 1 diff --git a/python 2/koans/about_list_assignments.py b/python 2/koans/about_list_assignments.py index d7e2e8998..812a862ec 100644 --- a/python 2/koans/about_list_assignments.py +++ b/python 2/koans/about_list_assignments.py @@ -7,6 +7,7 @@ from runner.koan import * + class AboutListAssignments(Koan): def test_non_parallel_assignment(self): names = ["John", "Smith"] diff --git a/python 2/koans/about_lists.py b/python 2/koans/about_lists.py index ca998f3f6..6a0a7847e 100644 --- a/python 2/koans/about_lists.py +++ b/python 2/koans/about_lists.py @@ -7,6 +7,7 @@ from runner.koan import * + class AboutLists(Koan): def test_creating_lists(self): empty_list = list() @@ -68,7 +69,7 @@ def test_insertions(self): self.assertEqual(__, knight) knight.insert(0, 'Arthur') - self.assertEqual(__, knight) + self.assertEqual(__, knight) def test_popping_lists(self): stack = [10, 20, 30, 40] diff --git a/python 2/koans/about_method_bindings.py b/python 2/koans/about_method_bindings.py index 8762ff1ee..b82872bb0 100644 --- a/python 2/koans/about_method_bindings.py +++ b/python 2/koans/about_method_bindings.py @@ -3,18 +3,22 @@ from runner.koan import * + def function(): return "pineapple" + def function2(): return "tractor" + class Class(object): def method(self): - return "parrot" + return "parrot" + class AboutMethodBindings(Koan): - def test_methods_are_bound_to_an_object(self): + def test_methods_are_bound_to_an_object(self): obj = Class() self.assertEqual(__, obj.method.im_self == obj) @@ -56,7 +60,7 @@ def test_inner_functions_are_unbound(self): try: cls = function2.get_fruit.im_self except AttributeError as ex: - self.assertMatch(__, ex[0]) + self.assertMatch(__, ex[0]) # ------------------------------------------------------------------ @@ -88,8 +92,7 @@ def __set__(self, obj, val): color = SuperColor() - def test_set_descriptor_changes_behavior_of_attribute_assignment_changes(self): + def test_set_descriptor_changes_behavior_of_attribute_assignment(self): self.assertEqual(None, self.color.choice) self.color = 'purple' self.assertEqual(__, self.color.choice) - diff --git a/python 2/koans/about_methods.py b/python 2/koans/about_methods.py index 08c133286..7279d8c2a 100644 --- a/python 2/koans/about_methods.py +++ b/python 2/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_an_global_function(self): - self.assertEqual(__, my_global_function(2,3)) + self.assertEqual(__, my_global_function(2, 3)) # NOTE: Wrong number of arguments is not a SYNTAX error, but a # runtime error. @@ -22,15 +24,15 @@ def test_calling_functions_with_wrong_number_of_arguments(self): except Exception as exception: self.assertEqual(__, type(exception).__name__) self.assertMatch( - r'my_global_function\(\) takes exactly 2 arguments \(0 given\)' - , exception[0]) + r'my_global_function\(\) takes exactly 2 arguments \(0 given\)', + exception[0]) try: my_global_function(1, 2, 3) except Exception as e: # Note, watch out for parenthesis. They need slashes in front! - self.assertMatch(__, e[0]) + self.assertMatch(__, e[0]) # ------------------------------------------------------------------ @@ -58,7 +60,7 @@ def method_with_var_args(self, *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(('one', ), self.method_with_var_args('one')) self.assertEqual(__, self.method_with_var_args('one', 'two')) # ------------------------------------------------------------------ @@ -70,13 +72,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(__, 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(__, self.function_with_the_same_name(3, 4)) # ------------------------------------------------------------------ @@ -111,7 +113,8 @@ def test_pass_does_nothing_at_all(self): # ------------------------------------------------------------------ - 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()) @@ -136,7 +139,7 @@ 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() @@ -148,11 +151,13 @@ def test_private_access_is_implied_but_not_enforced(self): # This is a little rude, but legal self.assertEqual(__, rover._tail()) - def test_attributes_with_double_underscore_prefixes_are_subject_to_name_mangling(self): + def test_double_underscore_attribute_prefixes_cause_name_mangling(self): + """Attributes names that start with a double underscore get + mangled when an instance is created.""" rover = self.Dog() try: #This may not be possible... - password = rover.__password() + password = rover.__password() except Exception as ex: self.assertEqual(__, type(ex).__name__) @@ -161,4 +166,3 @@ def test_attributes_with_double_underscore_prefixes_are_subject_to_name_mangling # Name mangling exists to avoid name clash issues when subclassing. # It is not for providing effective access protection - diff --git a/python 2/koans/about_modules.py b/python 2/koans/about_modules.py index 37aad480a..a375229a7 100644 --- a/python 2/koans/about_modules.py +++ b/python 2/koans/about_modules.py @@ -11,9 +11,10 @@ from another_local_module import * from local_module_with_all_defined import * + class AboutModules(Koan): def test_importing_other_python_scripts_as_modules(self): - import local_module # local_module.py + import local_module # local_module.py duck = local_module.Duck() self.assertEqual(__, duck.name) @@ -21,7 +22,7 @@ def test_importing_other_python_scripts_as_modules(self): def test_importing_attributes_from_classes_using_from_keyword(self): from local_module import Duck - duck = Duck() # no module qualifier needed this time + duck = Duck() # no module qualifier needed this time self.assertEqual(__, duck.name) def test_we_can_import_multiple_items_at_once(self): @@ -33,10 +34,11 @@ def test_we_can_import_multiple_items_at_once(self): self.assertEqual(__, joes_dog.identify()) def test_importing_all_module_attributes_at_once(self): - # NOTE Using this module level import declared at the top of this script: - # from other_local_module import * - # - # Import wildcard cannot be used from within classes or functions + """ + importing all attributes at once is done like so: + from another_local_module import * + The import wildcard cannot be used from within classes or functions. + """ goose = Goose() hamster = Hamster() @@ -51,18 +53,17 @@ def test_modules_hide_attributes_prefixed_by_underscores(self): self.assertMatch(__, ex[0]) def test_private_attributes_are_still_accessible_in_modules(self): - from local_module import Duck # local_module.py + from local_module import Duck # local_module.py duck = Duck() self.assertEqual(__, duck._password) # module level attribute hiding doesn't affect class attributes # (unless the class itself is hidden). - def test_a_module_can_choose_which_attributes_are_available_to_wildcards(self): - # NOTE Using this module level import declared at the top of this script: - # from local_module_with_all_defined import * + def test_a_modules_XallX_statement_limits_what_wildcards_will_match(self): + """Examine results of from local_module_with_all_defined import *""" - # 'Goat' is on the __ALL__ list + # 'Goat' is on the __all__ list goat = Goat() self.assertEqual(__, goat.name) diff --git a/python 2/koans/about_monkey_patching.py b/python 2/koans/about_monkey_patching.py index c88f85bf4..d5aec7c12 100644 --- a/python 2/koans/about_monkey_patching.py +++ b/python 2/koans/about_monkey_patching.py @@ -7,6 +7,7 @@ from runner.koan import * + class AboutMonkeyPatching(Koan): class Dog(object): def bark(self): @@ -18,9 +19,11 @@ def test_as_defined_dogs_do_bark(self): # ------------------------------------------------------------------ - # Add a new method to an existing class. + # Add a new method to an existing class. def test_after_patching_dogs_can_both_wag_and_bark(self): - def wag(self): return "HAPPY" + def wag(self): + return "HAPPY" + self.Dog.wag = wag fido = self.Dog() @@ -37,12 +40,11 @@ def test_most_built_in_classes_cannot_be_monkey_patched(self): # ------------------------------------------------------------------ - class MyInt(int): pass + class MyInt(int): + pass def test_subclasses_of_built_in_classes_can_be_be_monkey_patched(self): self.MyInt.is_even = lambda self: (self % 2) == 0 self.assertEqual(____, self.MyInt(1).is_even()) self.assertEqual(____, self.MyInt(2).is_even()) - - \ No newline at end of file diff --git a/python 2/koans/about_multiple_inheritance.py b/python 2/koans/about_multiple_inheritance.py index 3b99a20bd..b204c85c5 100644 --- a/python 2/koans/about_multiple_inheritance.py +++ b/python 2/koans/about_multiple_inheritance.py @@ -7,6 +7,7 @@ from runner.koan import * + class AboutMultipleInheritance(Koan): class Nameable(object): def __init__(self): @@ -14,20 +15,20 @@ def __init__(self): def set_name(self, new_name): self._name = new_name - + def here(self): return "In Nameable class" - - class Animal(object): + + class Animal(object): def legs(self): return 4 def can_climb_walls(self): return False - + def here(self): return "In Animal class" - + class Pig(Animal): def __init__(self): super(AboutMultipleInheritance.Animal, self).__init__() @@ -36,13 +37,13 @@ def __init__(self): @property def name(self): return self._name - + def speak(self): return "OINK" - + def color(self): - return 'pink' - + return 'pink' + def here(self): return "In Pig class" @@ -68,23 +69,23 @@ def __init__(self): super(AboutMultipleInheritance.Pig, self).__init__() super(AboutMultipleInheritance.Nameable, self).__init__() self._name = "Jeff" - + def speak(self): return "This looks like a job for Spiderpig!" - + def here(self): return "In Spiderpig class" - - # - # Hierarchy: + + # + # Hierarchy: # Animal - # / \ - # Pig Spider Nameable + # / \ + # Pig Spider Nameable # \ | / # Spiderpig - # + # # ------------------------------------------------------------------ - + def test_normal_methods_are_available_in_the_object(self): jeff = self.Spiderpig() self.assertMatch(__, jeff.speak()) @@ -96,14 +97,14 @@ def test_base_class_methods_are_also_available_in_the_object(self): except: self.fail("This should not happen") self.assertEqual(____, jeff.can_climb_walls()) - + def test_base_class_methods_can_affect_instance_variables_in_the_object(self): jeff = self.Spiderpig() self.assertEqual(__, jeff.name) - + jeff.set_name("Rover") self.assertEqual(__, jeff.name) - + def test_left_hand_side_inheritance_tends_to_be_higher_priority(self): jeff = self.Spiderpig() self.assertEqual(__, jeff.color()) @@ -117,25 +118,24 @@ def test_we_can_inspect_the_method_resolution_order(self): # MRO = Method Resolution Order # mro = type(self.Spiderpig()).__mro__ - self.assertEqual('Spiderpig', mro[0].__name__) - self.assertEqual('Pig', mro[1].__name__) - self.assertEqual(__, mro[2].__name__) - self.assertEqual(__, mro[3].__name__) - self.assertEqual(__, mro[4].__name__) - self.assertEqual(__, mro[5].__name__) + self.assertEqual('Spiderpig', mro[0].__name__) + self.assertEqual('Pig', mro[1].__name__) + self.assertEqual(__, mro[2].__name__) + self.assertEqual(__, mro[3].__name__) + self.assertEqual(__, mro[4].__name__) + self.assertEqual(__, mro[5].__name__) def test_confirm_the_mro_controls_the_calling_order(self): jeff = self.Spiderpig() self.assertMatch('Spiderpig', jeff.here()) - - next = super(AboutMultipleInheritance.Spiderpig, jeff) + + next = super(AboutMultipleInheritance.Spiderpig, jeff) self.assertMatch('Pig', next.here()) next = super(AboutMultipleInheritance.Pig, jeff) self.assertMatch(__, next.here()) - + # Hang on a minute?!? That last class name might be a super class of # the 'jeff' object, but its hardly a superclass of Pig, is it? # # To avoid confusion it may help to think of super() as next_mro(). - diff --git a/python 2/koans/about_new_style_classes.py b/python 2/koans/about_new_style_classes.py index 9ecd47b97..173acb686 100644 --- a/python 2/koans/about_new_style_classes.py +++ b/python 2/koans/about_new_style_classes.py @@ -3,6 +3,7 @@ from runner.koan import * + class AboutNewStyleClasses(Koan): class OldStyleClass: "An old style class" @@ -26,7 +27,8 @@ def test_new_style_classes_have_more_attributes(self): self.assertEqual(__, self.OldStyleClass.__module__) self.assertEqual(__, len(dir(self.NewStyleClass))) - # To examine the available attributes, run 'dir()' + # To examine the available attributes, run + # 'dir()' # from a python console # ------------------------------------------------------------------ @@ -44,7 +46,9 @@ def test_old_style_classes_have_type_but_no_class_attribute(self): def test_new_style_classes_have_same_class_as_type(self): new_style = self.NewStyleClass() self.assertEqual(__, type(self.NewStyleClass).__name__) - self.assertEqual(__, type(self.NewStyleClass) == self.NewStyleClass.__class__) + self.assertEqual( + __, + type(self.NewStyleClass) == self.NewStyleClass.__class__) # ------------------------------------------------------------------ diff --git a/python 2/koans/about_none.py b/python 2/koans/about_none.py index f8418f775..beeab8274 100644 --- a/python 2/koans/about_none.py +++ b/python 2/koans/about_none.py @@ -7,6 +7,7 @@ from runner.koan import * + class AboutNone(Koan): def test_none_is_an_object(self): @@ -17,14 +18,16 @@ def test_none_is_universal(self): "There is only one None" self.assertEqual(__, None is None) - def test_what_exception_do_you_get_when_calling_nonexistent_methods_on_None(self): + def test_what_exception_do_you_get_when_calling_nonexistent_methods(self): """ What is the Exception that is thrown when you call a method that does not exist? - Hint: launch python command console and try the code in the block below. + Hint: launch python command console and try the code in the + block below. - Don't worry about what 'try' and 'except' do, we'll talk about this later + Don't worry about what 'try' and 'except' do, we'll talk about + this later """ try: None.some_method_none_does_not_know_about() @@ -42,5 +45,3 @@ def test_none_is_distinct(self): """ self.assertEqual(____, None is not 0) self.assertEqual(____, None is not False) - - diff --git a/python 2/koans/about_packages.py b/python 2/koans/about_packages.py index a85f3c4c8..30d618c49 100644 --- a/python 2/koans/about_packages.py +++ b/python 2/koans/about_packages.py @@ -18,11 +18,12 @@ # about_attribute_access.py # about_class_attributes.py # about_classes.py -# ... +# ... # a_package_folder/ # __init__.py # a_module.py + class AboutPackages(Koan): def test_subfolders_can_form_part_of_a_module_package(self): # Import ./a_package_folder/a_module.py @@ -60,7 +61,7 @@ def test_use_absolute_imports_to_import_upper_level_modules(self): # almost impossible. So always leave the starting python script in # a folder which can reach everything else. - def test_import_a_module_in_a_subfolder_folder_using_an_absolute_path(self): + def test_import_a_module_in_a_subfolder_using_an_absolute_path(self): # Import contemplate_koans.py/koans/a_package_folder/a_module.py from koans.a_package_folder.a_module import Duck diff --git a/python 2/koans/about_proxy_object_project.py b/python 2/koans/about_proxy_object_project.py index 7a8ca80ae..27b89363f 100644 --- a/python 2/koans/about_proxy_object_project.py +++ b/python 2/koans/about_proxy_object_project.py @@ -18,6 +18,7 @@ from runner.koan import * + class Proxy(object): def __init__(self, target_object): # WRITE CODE HERE @@ -25,7 +26,8 @@ def __init__(self, target_object): #initialize '_obj' attribute last. Trust me on this! self._obj = target_object - # WRITE CODE HERE + # WRITE CODE HERE + # The proxy object should pass the following Koan: # @@ -64,7 +66,6 @@ def test_proxy_handles_invalid_messages(self): self.assertEqual(AttributeError, type(ex)) - def test_proxy_reports_methods_have_been_called(self): tv = Proxy(Television()) @@ -97,6 +98,7 @@ def test_proxy_can_record_more_than_just_tv_objects(self): self.assertEqual(["Py", "Ohio", "2010"], result) self.assertEqual(['upper', 'split'], proxy.messages()) + # ==================================================================== # The following code is to support the testing of the Proxy class. No # changes should be necessary to anything below this comment. @@ -113,7 +115,7 @@ def channel(self): @channel.setter def channel(self, value): - self._channel = value + self._channel = value def power(self): if self._power == 'on': @@ -124,6 +126,7 @@ def power(self): def is_on(self): return self._power == 'on' + # Tests for the Television class. All of theses tests should pass. class TelevisionTest(Koan): def test_it_turns_on(self): diff --git a/python 2/koans/about_regex.py b/python 2/koans/about_regex.py index 13db11a82..95678d2eb 100755 --- a/python 2/koans/about_regex.py +++ b/python 2/koans/about_regex.py @@ -2,11 +2,15 @@ # -*- coding: utf-8 -*- from runner.koan import * + import re + + class AboutRegex(Koan): """ - These koans are based on the Ben's book: Regular Expressions in 10 minutes. - I found this books very useful so I decided to write a koans in order to practice everything I had learned from it. + These koans are based on Ben's book: Regular Expressions in 10 + minutes. I found this book very useful, so I decided to write + a koan file in order to practice everything it taught me. http://www.forta.com/books/0672325667/ """ @@ -14,47 +18,60 @@ def test_matching_literal_text(self): """ Lesson 1 Matching Literal String """ - string = "Hello, my name is Felix and this koans are based on the Ben's book: Regular Expressions in 10 minutes." + string = "Hello, my name is Felix and these koans are based " + \ + "on Ben's book: Regular Expressions in 10 minutes." m = re.search(__, string) - self.assertTrue(m and m.group(0) and m.group(0)== 'Felix', "I want my name") + self.assertTrue( + m and m.group(0) and + m.group(0) == 'Felix', + "I want my name") def test_matching_literal_text_how_many(self): """ - Lesson 1 How many matches? - - The default behaviour of most regular extression engines is to return just the first match. - In python you have the next options: - - match() --> Determine if the RE matches at the beginning of the string. - search() --> Scan through a string, looking for any location where this RE matches. - findall() --> Find all substrings where the RE matches, and returns them as a list. - finditer() --> Find all substrings where the RE matches, and returns them as an iterator. - + Lesson 1 -- How many matches? + + The default behaviour of most regular extression engines is + to return just the first match. In python you have the + following options: + + match() --> Determine if the RE matches at the + beginning of the string. + search() --> Scan through a string, looking for any + location where this RE matches. + findall() --> Find all substrings where the RE + matches, and return them as a list. + finditer() --> Find all substrings where the RE + matches, and return them as an iterator. """ - string = "Hello, my name is Felix and this koans are based on the Ben's book: Regular Expressions in 10 minutes. Repeat My name is Felix" - m = re.match('Felix', string) #TIP: Maybe match it's not the best option + string = ("Hello, my name is Felix and these koans are based " + + "on Ben's book: Regular Expressions in 10 minutes. " + + "Repeat My name is Felix") + m = re.match('Felix', string) # TIP: match may not be the best option - # I want to know how many times appears my name + # I want to know how many times my name appears self.assertEqual(m, __) def test_matching_literal_text_not_case_sensitivity(self): """ - Lesson 1 Matching Literal String non case sensitivity. - Most regex implementations also support matches that are not case sensitive. In python you can use re.IGNORECASE, in - Javascript you can specify the optional i flag. - In Ben's book you can see more languages. + Lesson 1 -- Matching Literal String non case sensitivity. + Most regex implementations also support matches that are not + case sensitive. In python you can use re.IGNORECASE, in + Javascript you can specify the optional i flag. In Ben's + book you can see more languages. """ - string = "Hello, my name is Felix or felix and this koans is based on the Ben's book: Regular Expressions in 10 minutes." + string = "Hello, my name is Felix or felix and this koan " + \ + "is based on Ben's book: Regular Expressions in 10 minutes." self.assertEqual(re.findall("felix", string, 20), __) self.assertEqual(re.findall("felix", string, 10), __) - + def test_matching_any_character(self): """ - Lesson 1 Matching any character + Lesson 1: Matching any character - . matches any character, alphabetic characters, digits and . + `.` matches any character: alphabetic characters, digits, + and punctuation. """ string = "pecks.xlx\n" \ + "orders1.xls\n" \ @@ -63,17 +80,19 @@ def test_matching_any_character(self): + "na2.xls\n" \ + "sa1.xls" - # TIP: remember the name of this lesson - - change_this_search_string = 'a..xlx' # <-- I want to find all uses of myArray - self.assertEquals(len(re.findall(change_this_search_string, string)),3) + # I want to find all uses of myArray + change_this_search_string = 'a..xlx' + self.assertEquals( + len(re.findall(change_this_search_string, string)), + 3) def test_matching_set_character(self): """ - Lesson 2 Matching sets of characters + Lesson 2 -- Matching sets of characters - A set of characters is defined using the metacharacters [ and ]. Everything between them is part of the set and - any one of the set members must match (but not all). + A set of characters is defined using the metacharacters + `[` and `]`. Everything between them is part of the set, and + any single one of the set members will match. """ string = "sales.xlx\n" \ + "sales1.xls\n" \ @@ -83,17 +102,22 @@ def test_matching_set_character(self): + "na1.xls\n" \ + "na2.xls\n" \ + "sa1.xls\n" \ - + "ca1.xls" - # I want to find all files for North America(na) or South America(sa), but not (ca) - # TIP you can use the pattern .a. which matches in above test but in this case matches more than you want + + "ca1.xls" + # I want to find all files for North America(na) or South + # America(sa), but not (ca) TIP you can use the pattern .a. + # which matches in above test but in this case matches more than + # you want change_this_search_string = '[nsc]a[2-9].xls' - self.assertEquals(len(re.findall(change_this_search_string, string)),3) + self.assertEquals( + len(re.findall(change_this_search_string, string)), + 3) def test_anything_but_matching(self): """ - Lesson 2 Using character set ranges - Occsionally, you'll want a list of characters that you don't want to match. - Character sets can be negated using the ^ metacharacter. + Lesson 2 -- Using character set ranges + Occasionally, you'll have a list of characters that you don't + want to match. Character sets can be negated using the ^ + metacharacter. """ string = "sales.xlx\n" \ @@ -107,10 +131,10 @@ def test_anything_but_matching(self): + "na1.xls\n" \ + "na2.xls\n" \ + "sa1.xls\n" \ - + "ca1.xls" + + "ca1.xls" - # I want to find the name sam + # I want to find the name 'sam' change_this_search_string = '[^nc]am' - self.assertEquals(re.findall(change_this_search_string, string), ['sam.xls']) - - + self.assertEquals( + re.findall(change_this_search_string, string), + ['sam.xls']) diff --git a/python 2/koans/about_scope.py b/python 2/koans/about_scope.py index 9fd7501e3..f290e6319 100644 --- a/python 2/koans/about_scope.py +++ b/python 2/koans/about_scope.py @@ -3,10 +3,11 @@ from runner.koan import * -import jims +import jims import joes -counter = 0 # Global +counter = 0 # Global + class AboutScope(Koan): # @@ -19,7 +20,7 @@ def test_dog_is_not_available_in_the_current_scope(self): try: fido = Dog() except Exception as ex: - self.assertMatch(__, ex[0]) + self.assertMatch(__, ex[0]) def test_you_can_reference_nested_classes_using_the_scope_operator(self): fido = jims.Dog() @@ -89,4 +90,3 @@ def test_incrementing_with_global_counter(self): def test_global_attributes_can_be_created_in_the_middle_of_a_class(self): self.assertEqual(__, deadly_bingo[5]) - \ No newline at end of file diff --git a/python 2/koans/about_scoring_project.py b/python 2/koans/about_scoring_project.py index 393af55b5..8b2503e37 100644 --- a/python 2/koans/about_scoring_project.py +++ b/python 2/koans/about_scoring_project.py @@ -3,6 +3,7 @@ from runner.koan import * + # Greed is a dice game where you roll up to five dice to accumulate # points. The following "score" function will be used calculate the # score of a single roll of the dice. @@ -10,7 +11,7 @@ # A greed roll is scored as follows: # # * A set of three ones is 1000 points -# +# # * A set of three numbers (other than ones) is worth 100 times the # number. (e.g. three fives is 500 points). # @@ -23,10 +24,10 @@ # # Examples: # -# score([1,1,1,5,1]) => 1150 points -# score([2,3,4,6,2]) => 0 points -# score([3,4,5,3,3]) => 350 points -# score([1,5,1,2,4]) => 250 points +# score([1, 1, 1, 5, 1]) => 1150 points +# score([2, 3, 4, 6, 2]) => 0 points +# score([3, 4, 5, 3, 3]) => 350 points +# score([1, 5, 1, 2, 4]) => 250 points # # More scoring examples are given in the tests below: # @@ -36,6 +37,7 @@ def score(dice): # You need to write this method pass + class AboutScoringProject(Koan): def test_score_of_an_empty_list_is_zero(self): self.assertEqual(0, score([])) @@ -47,26 +49,26 @@ def test_score_of_a_single_roll_of_1_is_100(self): self.assertEqual(100, score([1])) def test_score_of_multiple_1s_and_5s_is_the_sum_of_individual_scores(self): - self.assertEqual(300, score([1,5,5,1])) + self.assertEqual(300, score([1, 5, 5, 1])) def test_score_of_single_2s_3s_4s_and_6s_are_zero(self): - self.assertEqual(0, score([2,3,4,6])) + self.assertEqual(0, score([2, 3, 4, 6])) def test_score_of_a_triple_1_is_1000(self): - self.assertEqual(1000, score([1,1,1])) + self.assertEqual(1000, score([1, 1, 1])) def test_score_of_other_triples_is_100x(self): - self.assertEqual(200, score([2,2,2])) - self.assertEqual(300, score([3,3,3])) - self.assertEqual(400, score([4,4,4])) - self.assertEqual(500, score([5,5,5])) - self.assertEqual(600, score([6,6,6])) + self.assertEqual(200, score([2, 2, 2])) + self.assertEqual(300, score([3, 3, 3])) + self.assertEqual(400, score([4, 4, 4])) + self.assertEqual(500, score([5, 5, 5])) + self.assertEqual(600, score([6, 6, 6])) def test_score_of_mixed_is_sum(self): - self.assertEqual(250, score([2,5,2,2,3])) - self.assertEqual(550, score([5,5,5,5])) - self.assertEqual(1150, score([1,1,1,5,1])) + self.assertEqual(250, score([2, 5, 2, 2, 3])) + self.assertEqual(550, score([5, 5, 5, 5])) + self.assertEqual(1150, score([1, 1, 1, 5, 1])) def test_ones_not_left_out(self): - self.assertEqual(300, score([1,2,2,2])) - self.assertEqual(350, score([1,5,2,2,2])) \ No newline at end of file + self.assertEqual(300, score([1, 2, 2, 2])) + self.assertEqual(350, score([1, 5, 2, 2, 2])) diff --git a/python 2/koans/about_sets.py b/python 2/koans/about_sets.py index cf207b031..277cd1c46 100644 --- a/python 2/koans/about_sets.py +++ b/python 2/koans/about_sets.py @@ -3,9 +3,11 @@ from runner.koan import * + class AboutSets(Koan): def test_sets_make_keep_lists_unique(self): - highlanders = ['MacLeod', 'Ramirez', 'MacLeod', 'Matunas', 'MacLeod', 'Malcolm', 'MacLeod'] + highlanders = ['MacLeod', 'Ramirez', 'MacLeod', 'Matunas', + 'MacLeod', 'Malcolm', 'MacLeod'] there_can_only_be_only_one = set(highlanders) @@ -17,7 +19,6 @@ def test_sets_are_unordered(self): def test_convert_the_set_into_a_list_to_sort_it(self): self.assertEqual(__, sorted(set('13245'))) - # ------------------------------------------------------------------ def chars_in(self, a_set): @@ -27,19 +28,19 @@ def test_set_have_arithmetic_operators(self): good_guy = set('macleod') bad_guy = set('mutunas') - self.assertEqual(__, self.chars_in( good_guy - bad_guy) ) - self.assertEqual(__, self.chars_in( good_guy | bad_guy )) - self.assertEqual(__, self.chars_in( good_guy & bad_guy )) - self.assertEqual(__, self.chars_in( good_guy ^ bad_guy )) + self.assertEqual(__, self.chars_in(good_guy - bad_guy)) + self.assertEqual(__, self.chars_in(good_guy | bad_guy)) + self.assertEqual(__, self.chars_in(good_guy & bad_guy)) + self.assertEqual(__, self.chars_in(good_guy ^ bad_guy)) # ------------------------------------------------------------------ def test_we_can_query_set_membership(self): - self.assertEqual(__, 127 in set([127, 0, 0, 1]) ) - self.assertEqual(__, 'cow' not in set('apocalypse now') ) + self.assertEqual(__, 127 in set([127, 0, 0, 1])) + self.assertEqual(__, 'cow' not in set('apocalypse now')) def test_we_can_compare_subsets(self): self.assertEqual(__, set('cake') <= set('cherry cake')) - self.assertEqual(__, set('cake').issubset(set('cherry cake')) ) + self.assertEqual(__, set('cake').issubset(set('cherry cake'))) self.assertEqual(__, set('cake') > set('pie')) diff --git a/python 2/koans/about_strings.py b/python 2/koans/about_strings.py index 8b6ed0def..d978c5c10 100644 --- a/python 2/koans/about_strings.py +++ b/python 2/koans/about_strings.py @@ -3,6 +3,7 @@ from runner.koan import * + class AboutStrings(Koan): def test_double_quoted_strings_are_strings(self): @@ -55,7 +56,7 @@ def test_triple_quoted_strings_need_less_escaping(self): b = """Hello "world".""" self.assertEqual(__, (a == b)) - def but_you_still_have_to_be_careful_at_the_end_of_a_triple_quoted_string(self): + def but_quotes_at_the_end_of_a_triple_quoted_string_are_still_tricky(self): string = """Hello "world\"""" def test_plus_concatenates_strings(self): @@ -105,7 +106,7 @@ def test_formatted_values_con_be_shown_in_any_order_or_be_repeated(self): self.assertEqual(__, 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), \ @@ -121,7 +122,7 @@ def test_you_can_get_a_single_character_from_a_string(self): self.assertEqual(__, string[1]) def test_single_characters_can_be_represented_by_integers(self): - self.assertEqual(__, ord('a')) + self.assertEqual(__, ord('a')) self.assertEqual(__, ord('b') == (ord('a') + 1)) def test_strings_can_be_split(self): @@ -130,7 +131,7 @@ def test_strings_can_be_split(self): self.assertEqual([__, __, __], 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(',|;') @@ -139,7 +140,8 @@ def test_strings_can_be_split_with_different_patterns(self): self.assertEqual([__, __, __, __], words) - # Pattern is a Python regular expression pattern which matches ',' or ';' + # `pattern` is a Python regular expression pattern which matches + # ',' or ';' def test_raw_strings_do_not_interpret_escape_characters(self): string = r'\n' @@ -147,7 +149,7 @@ def test_raw_strings_do_not_interpret_escape_characters(self): self.assertEqual(__, string) self.assertEqual(__, len(string)) - # Useful in regular expressions, file paths, URLs, etc. + # Useful in regular expressions, file paths, URLs, etc. def test_strings_can_be_joined(self): words = ["Now", "is", "the", "time"] diff --git a/python 2/koans/about_triangle_project.py b/python 2/koans/about_triangle_project.py index 6c254768f..6f3abc909 100644 --- a/python 2/koans/about_triangle_project.py +++ b/python 2/koans/about_triangle_project.py @@ -6,6 +6,7 @@ # You need to write the triangle method in the file 'triangle.py' from triangle import * + class AboutTriangleProject(Koan): def test_equilateral_triangles_have_equal_sides(self): self.assertEqual('equilateral', triangle(2, 2, 2)) diff --git a/python 2/koans/about_triangle_project2.py b/python 2/koans/about_triangle_project2.py index ffff4ac00..0afe0724b 100644 --- a/python 2/koans/about_triangle_project2.py +++ b/python 2/koans/about_triangle_project2.py @@ -6,6 +6,7 @@ # You need to finish implementing triangle() in the file 'triangle.py' from triangle import * + class AboutTriangleProject2(Koan): # The first assignment did not talk about how to handle errors. # Let's handle that part now. @@ -15,4 +16,4 @@ def test_illegal_triangles_throw_exceptions(self): self.assertRaises(TriangleError, triangle, 3, 4, -5) self.assertRaises(TriangleError, triangle, 1, 1, 3) - self.assertRaises(TriangleError, triangle, 2, 4, 2) + self.assertRaises(TriangleError, triangle, 2, 4, 2) diff --git a/python 2/koans/about_true_and_false.py b/python 2/koans/about_true_and_false.py index 9b6639641..e29823cb6 100644 --- a/python 2/koans/about_true_and_false.py +++ b/python 2/koans/about_true_and_false.py @@ -3,6 +3,7 @@ from runner.koan import * + class AboutTrueAndFalse(Koan): def truth_value(self, condition): if condition: @@ -34,5 +35,7 @@ def test_blank_strings_are_treated_as_false(self): def test_everything_else_is_treated_as_true(self): self.assertEqual(__, self.truth_value(1)) self.assertEqual(__, self.truth_value(1,)) - self.assertEqual(__, self.truth_value("Python is named after Monty Python")) + self.assertEqual( + __, + self.truth_value("Python is named after Monty Python")) self.assertEqual(__, self.truth_value(' ')) diff --git a/python 2/koans/about_tuples.py b/python 2/koans/about_tuples.py index ae5e614e2..5773c0ad6 100644 --- a/python 2/koans/about_tuples.py +++ b/python 2/koans/about_tuples.py @@ -3,33 +3,34 @@ from runner.koan import * + class AboutTuples(Koan): def test_creating_a_tuple(self): - count_of_three = (1, 2, 5) + count_of_three = (1, 2, 5) self.assertEqual(__, count_of_three[2]) def test_tuples_are_immutable_so_item_assignment_is_not_possible(self): - count_of_three = (1, 2, 5) + count_of_three = (1, 2, 5) try: count_of_three[2] = "three" except TypeError as ex: self.assertMatch(__, ex[0]) def test_tuples_are_immutable_so_appending_is_not_possible(self): - count_of_three = (1, 2, 5) + count_of_three = (1, 2, 5) try: count_of_three.append("boom") except Exception as ex: self.assertEqual(AttributeError, type(ex)) # Note, assertMatch() uses regular expression pattern matching, - # so you don't have to copy the whole message. + # so you don't have to copy the whole message. self.assertMatch(__, ex[0]) # Tuples are less flexible than lists, but faster. def test_tuples_can_only_be_changed_through_replacement(self): - count_of_three = (1, 2, 5) + count_of_three = (1, 2, 5) list_count = list(count_of_three) list_count.append("boom") @@ -46,8 +47,8 @@ def test_tuple_constructor_can_be_surprising(self): self.assertEqual(__, tuple("Surprise!")) def test_creating_empty_tuples(self): - self.assertEqual(__ , ()) - self.assertEqual(__ , tuple()) #Sometimes less confusing + self.assertEqual(__, ()) + self.assertEqual(__, tuple()) # Sometimes less confusing def test_tuples_can_be_embedded(self): lat = (37, 14, 6, 'N') @@ -61,10 +62,9 @@ def test_tuples_are_good_for_representing_records(self): ("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( + ("Cthulhu", (26, 40, 1, 'N'), (70, 45, 7, 'W')) + ) self.assertEqual(__, locations[2][0]) self.assertEqual(__, locations[0][1][2]) - - - diff --git a/python 2/koans/about_with_statements.py b/python 2/koans/about_with_statements.py index bb4db2ddf..df0c5e3cc 100644 --- a/python 2/koans/about_with_statements.py +++ b/python 2/koans/about_with_statements.py @@ -7,7 +7,8 @@ from runner.koan import * -import re # For regular expression string comparisons +import re # For regular expression string comparisons + class AboutWithStatements(Koan): def count_lines(self, file_name): @@ -30,7 +31,8 @@ def find_line(self, file_name): try: for line in file.readlines(): match = re.search('e', line) - if match: return line + if match: + return line finally: if file: file.close() @@ -100,7 +102,7 @@ def count_lines3(self, file_name): with open(file_name) as file: count = 0 for line in file.readlines(): - count += 1 + count += 1 return count def test_open_already_has_its_own_built_in_context_manager(self): diff --git a/python 2/koans/another_local_module.py b/python 2/koans/another_local_module.py index c7358947b..2b2abf2d4 100644 --- a/python 2/koans/another_local_module.py +++ b/python 2/koans/another_local_module.py @@ -1,17 +1,20 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- + class Goose(object): @property def name(self): return "Mr Stabby" + class Hamster(object): @property def name(self): return "Phil" + class _SecretSquirrel(object): @property def name(self): - return "Mr Anonymous" \ No newline at end of file + return "Mr Anonymous" diff --git a/python 2/koans/jims.py b/python 2/koans/jims.py index 06a6f0d13..761882f13 100644 --- a/python 2/koans/jims.py +++ b/python 2/koans/jims.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- + class Dog(object): def identify(self): return "jims dog" diff --git a/python 2/koans/joes.py b/python 2/koans/joes.py index 491de31ff..7cab94866 100644 --- a/python 2/koans/joes.py +++ b/python 2/koans/joes.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- + class Dog(object): def identify(self): return "joes dog" diff --git a/python 2/koans/local_module.py b/python 2/koans/local_module.py index 1d9195800..762a55a5e 100644 --- a/python 2/koans/local_module.py +++ b/python 2/koans/local_module.py @@ -1,9 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- + class Duck(object): def __init__(self): - self._password = 'password' # Genius! + self._password = 'password' # Genius! @property def name(self): diff --git a/python 2/koans/local_module_with_all_defined.py b/python 2/koans/local_module_with_all_defined.py index 6ac36b2a2..90488cd60 100644 --- a/python 2/koans/local_module_with_all_defined.py +++ b/python 2/koans/local_module_with_all_defined.py @@ -2,20 +2,23 @@ # -*- coding: utf-8 -*- __all__ = ( - 'Goat', + 'Goat', '_Velociraptor' ) + class Goat(object): @property def name(self): return "George" + class _Velociraptor(object): @property def name(self): return "Cuddles" + class SecretDuck(object): @property def name(self): diff --git a/python 2/koans/triangle.py b/python 2/koans/triangle.py index b71c2dd77..8f3faeed3 100644 --- a/python 2/koans/triangle.py +++ b/python 2/koans/triangle.py @@ -3,7 +3,8 @@ # Triangle Project Code. -# Triangle analyzes the lengths of the sides of a triangle + +# triangle(a, b, c) analyzes the lengths of the sides of a triangle # (represented by a, b and c) and returns the type of triangle. # # It returns: @@ -20,6 +21,7 @@ def triangle(a, b, c): # DELETE 'PASS' AND WRITE THIS CODE pass + # Error class used in part 2. No need to change this code. class TriangleError(StandardError): pass diff --git a/python 3/koans/about_classes.py b/python 3/koans/about_classes.py index fdc67e17a..2adbd5801 100644 --- a/python 3/koans/about_classes.py +++ b/python 3/koans/about_classes.py @@ -3,79 +3,79 @@ from runner.koan import * + class AboutClasses(Koan): class Dog: "Dogs need regular walkies. Never, ever let them drive." - - def test_instances_of_classes_can_be_created_adding_parenthesis(self): + + def test_instances_of_classes_can_be_created_adding_parentheses(self): fido = self.Dog() self.assertEqual(__, type(fido).__name__) - + def test_classes_have_docstrings(self): self.assertRegexpMatches(self.Dog.__doc__, __) - + # ------------------------------------------------------------------ - - class Dog2: - def __init__(self): + + class Dog2: + def __init__(self): self._name = 'Paul' - + def set_name(self, a_name): self._name = a_name - + def test_init_method_is_the_constructor(self): dog = self.Dog2() self.assertEqual(__, dog._name) - - def test_private_attributes_are_not_really_private(self): + + def test_private_attributes_are_not_really_private(self): dog = self.Dog2() dog.set_name("Fido") self.assertEqual(__, dog._name) # The _ prefix in _name implies private ownership, but nothing is truly # private in Python. - + def test_you_can_also_access_the_value_out_using_getattr_and_dict(self): fido = self.Dog2() fido.set_name("Fido") - + self.assertEqual(__, getattr(fido, "_name")) # getattr(), setattr() and delattr() are a way of accessing attributes # by method rather than through assignment operators - + self.assertEqual(__, fido.__dict__["_name"]) # Yes, this works here, but don't rely on the __dict__ object! Some # class implementations use optimization which result in __dict__ not # showing everything. - + # ------------------------------------------------------------------ - + class Dog3: - def __init__(self): + def __init__(self): self._name = None def set_name(self, a_name): self._name = a_name - + def get_name(self): return self._name - + name = property(get_name, set_name) - - + def test_that_name_can_be_read_as_a_property(self): fido = self.Dog3() fido.set_name("Fido") - + # access as method self.assertEqual(__, fido.get_name()) - + # access as property self.assertEqual(__, fido.name) - + # ------------------------------------------------------------------ - + class Dog4: - def __init__(self): + def __init__(self): self._name = None @property @@ -85,79 +85,79 @@ def name(self): @name.setter def name(self, a_name): self._name = a_name - + def test_creating_properties_with_decorators_is_slightly_easier(self): fido = self.Dog4() - + fido.name = "Fido" self.assertEqual(__, fido.name) - + # ------------------------------------------------------------------ - + class Dog5: - def __init__(self, initial_name): + def __init__(self, initial_name): self._name = initial_name @property def name(self): return self._name - + def test_init_provides_initial_values_for_instance_variables(self): - fido = self.Dog5("Fido") + fido = self.Dog5("Fido") self.assertEqual(__, fido.name) - + def test_args_must_match_init(self): - with self.assertRaises(___): self.Dog5() - + with self.assertRaises(___): + self.Dog5() + # THINK ABOUT IT: # Why is this so? - + def test_different_objects_have_difference_instance_variables(self): fido = self.Dog5("Fido") rover = self.Dog5("Rover") - + self.assertEqual(__, rover.name == fido.name) - + # ------------------------------------------------------------------ - + class Dog6: def __init__(self, initial_name): self._name = initial_name - + def get_self(self): return self - + def __str__(self): return __ - + def __repr__(self): return "" def test_inside_a_method_self_refers_to_the_containing_object(self): fido = self.Dog6("Fido") - - self.assertEqual(__, fido.get_self()) # Not a string! - + + self.assertEqual(__, fido.get_self()) # Not a string! + def test_str_provides_a_string_version_of_the_object(self): fido = self.Dog6("Fido") - + self.assertEqual("Fido", str(fido)) - + def test_str_is_used_explicitly_in_string_interpolation(self): fido = self.Dog6("Fido") - + self.assertEqual(__, "My dog is " + str(fido)) - + def test_repr_provides_a_more_complete_string_version(self): fido = self.Dog6("Fido") self.assertEqual(__, repr(fido)) - + def test_all_objects_support_str_and_repr(self): - seq = [1,2,3] - + seq = [1, 2, 3] + self.assertEqual(__, str(seq)) self.assertEqual(__, repr(seq)) - + self.assertEqual(__, str("STRING")) self.assertEqual(__, repr("STRING")) - From 0042d792ebc691db3023c576f52efaa28bf4a3bb Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Sat, 17 Mar 2012 13:11:54 -0400 Subject: [PATCH 009/237] Merge from bitbucket mirror: 'gpiancastelli - Fix for issue #21 and some other tweaks' --- .../koans/about_decorating_with_classes.py | 2 +- python 2/koans/about_iteration.py | 29 ++++++------ python 2/koans/about_with_statements.py | 44 +++++++++++-------- .../koans/about_decorating_with_classes.py | 4 +- python 3/koans/about_iteration.py | 27 ++++++------ python 3/koans/about_with_statements.py | 35 +++++++++------ 6 files changed, 78 insertions(+), 63 deletions(-) diff --git a/python 2/koans/about_decorating_with_classes.py b/python 2/koans/about_decorating_with_classes.py index bcbc29bc6..c892b31ac 100644 --- a/python 2/koans/about_decorating_with_classes.py +++ b/python 2/koans/about_decorating_with_classes.py @@ -102,7 +102,7 @@ def count_badly(self, num): if num == 3: return 5 else: - num + return num @documenter("Does nothing") def idler(self, num): diff --git a/python 2/koans/about_iteration.py b/python 2/koans/about_iteration.py index af4598a50..79604a696 100644 --- a/python 2/koans/about_iteration.py +++ b/python 2/koans/about_iteration.py @@ -108,18 +108,17 @@ def test_all_iteration_methods_work_on_any_sequence_not_just_lists(self): self.assertEqual(__, list(result)) try: - # Files act like a collection of lines - file = open("example_file.txt") - - def make_upcase(line): - return line.strip().upper() - upcase_lines = map(make_upcase, file.readlines()) - self.assertEqual(__, list(upcase_lines)) - - # NOTE: You can create your own collections that work with each, - # map, select, etc. - finally: - # Arg, this is ugly. - # We will figure out how to fix this later. - if file: - file.close() + f = open("example_file.txt") + + try: + def make_upcase(line): + return line.strip().upper() + upcase_lines = map(make_upcase, f.readlines()) + self.assertEqual(__, list(upcase_lines)) + finally: + # Arg, this is ugly. + # We will figure out how to fix this later. + f.close() + except IOError: + # should never happen + self.fail() diff --git a/python 2/koans/about_with_statements.py b/python 2/koans/about_with_statements.py index df0c5e3cc..562ba128a 100644 --- a/python 2/koans/about_with_statements.py +++ b/python 2/koans/about_with_statements.py @@ -12,14 +12,18 @@ class AboutWithStatements(Koan): def count_lines(self, file_name): - file = open(file_name) try: - count = 0 - for line in file.readlines(): - count += 1 - return count - finally: - if file: file.close() + f = open(file_name) + try: + count = 0 + for line in f.readlines(): + count += 1 + return count + finally: + f.close() + except IOError: + # should never happen + self.fail() def test_counting_lines(self): self.assertEqual(__, self.count_lines("example_file.txt")) @@ -27,14 +31,18 @@ def test_counting_lines(self): # ------------------------------------------------------------------ def find_line(self, file_name): - file = open(file_name) try: - for line in file.readlines(): - match = re.search('e', line) - if match: - return line - finally: - if file: file.close() + f = open(file_name) + try: + for line in f.readlines(): + match = re.search('e', line) + if match: + return line + finally: + f.close() + except IOError: + # should never happen + self.fail() def test_finding_lines(self): self.assertEqual(__, self.find_line("example_file.txt")) @@ -77,9 +85,9 @@ def __exit__(self, cls, value, tb): # Now we write: def count_lines2(self, file_name): - with self.FileContextManager(file_name) as file: + with self.FileContextManager(file_name) as f: count = 0 - for line in file.readlines(): + for line in f.readlines(): count += 1 return count @@ -99,9 +107,9 @@ def test_finding_lines2(self): # ------------------------------------------------------------------ def count_lines3(self, file_name): - with open(file_name) as file: + with open(file_name) as f: count = 0 - for line in file.readlines(): + for line in f.readlines(): count += 1 return count diff --git a/python 3/koans/about_decorating_with_classes.py b/python 3/koans/about_decorating_with_classes.py index 358488c4c..3466bc1d4 100644 --- a/python 3/koans/about_decorating_with_classes.py +++ b/python 3/koans/about_decorating_with_classes.py @@ -101,7 +101,7 @@ def count_badly(self, num): if num==3: return 5 else: - num + return num @documenter("Does nothing") def idler(self, num): "Idler" @@ -125,4 +125,4 @@ def homer(self): def test_we_can_chain_decorators(self): self.assertEqual(__, self.homer()) self.assertEqual(__, self.homer.__doc__) - \ No newline at end of file + diff --git a/python 3/koans/about_iteration.py b/python 3/koans/about_iteration.py index d9d1e5ca2..40cc751f4 100644 --- a/python 3/koans/about_iteration.py +++ b/python 3/koans/about_iteration.py @@ -129,18 +129,17 @@ def test_all_iteration_methods_work_on_any_sequence_not_just_lists(self): self.assertEqual(__, list(result)) try: - # Files act like a collection of lines file = open("example_file.txt") - - def make_upcase(line): - return line.strip().upper() - upcase_lines = map(make_upcase, file.readlines()) - self.assertEqual(__, list(upcase_lines)) - - # NOTE: You can create your own collections that work with each, - # map, select, etc. - finally: - # Arg, this is ugly. - # We will figure out how to fix this later. - if file: - file.close() \ No newline at end of file + + try: + def make_upcase(line): + return line.strip().upper() + upcase_lines = map(make_upcase, file.readlines()) + self.assertEqual(__, list(upcase_lines)) + finally: + # Arg, this is ugly. + # We will figure out how to fix this later. + file.close() + except IOError: + # should never happen + self.fail() diff --git a/python 3/koans/about_with_statements.py b/python 3/koans/about_with_statements.py index 66f0a912e..9dd0a5f49 100644 --- a/python 3/koans/about_with_statements.py +++ b/python 3/koans/about_with_statements.py @@ -11,14 +11,18 @@ class AboutWithStatements(Koan): def count_lines(self, file_name): - file = open(file_name) try: - count = 0 - for line in file.readlines(): - count += 1 - return count - finally: - if file: file.close() + file = open(file_name) + try: + count = 0 + for line in file.readlines(): + count += 1 + return count + finally: + file.close() + except IOError: + # should never happen + self.fail() def test_counting_lines(self): self.assertEqual(__, self.count_lines("example_file.txt")) @@ -26,13 +30,18 @@ def test_counting_lines(self): # ------------------------------------------------------------------ def find_line(self, file_name): - file = open(file_name) try: - for line in file.readlines(): - match = re.search('e', line) - if match: return line - finally: - if file: file.close() + file = open(file_name) + try: + for line in file.readlines(): + match = re.search('e', line) + if match: + return line + finally: + file.close() + except IOError: + # should never happen + self.fail() def test_finding_lines(self): self.assertEqual(__, self.find_line("example_file.txt")) From 79ca184af5d64d7051851635707d55253f91efc1 Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Sat, 17 Mar 2012 15:21:50 -0400 Subject: [PATCH 010/237] Merge from bitbucket mirror: 'gpiancastelli - Fix for issue #21 and some other tweaks' --- .../koans/about_decorating_with_classes.py | 2 +- python 2/koans/about_iteration.py | 29 ++++++------ python 2/koans/about_with_statements.py | 44 +++++++++++-------- .../koans/about_decorating_with_classes.py | 4 +- python 3/koans/about_iteration.py | 27 ++++++------ python 3/koans/about_with_statements.py | 35 +++++++++------ 6 files changed, 78 insertions(+), 63 deletions(-) diff --git a/python 2/koans/about_decorating_with_classes.py b/python 2/koans/about_decorating_with_classes.py index bcbc29bc6..c892b31ac 100644 --- a/python 2/koans/about_decorating_with_classes.py +++ b/python 2/koans/about_decorating_with_classes.py @@ -102,7 +102,7 @@ def count_badly(self, num): if num == 3: return 5 else: - num + return num @documenter("Does nothing") def idler(self, num): diff --git a/python 2/koans/about_iteration.py b/python 2/koans/about_iteration.py index af4598a50..79604a696 100644 --- a/python 2/koans/about_iteration.py +++ b/python 2/koans/about_iteration.py @@ -108,18 +108,17 @@ def test_all_iteration_methods_work_on_any_sequence_not_just_lists(self): self.assertEqual(__, list(result)) try: - # Files act like a collection of lines - file = open("example_file.txt") - - def make_upcase(line): - return line.strip().upper() - upcase_lines = map(make_upcase, file.readlines()) - self.assertEqual(__, list(upcase_lines)) - - # NOTE: You can create your own collections that work with each, - # map, select, etc. - finally: - # Arg, this is ugly. - # We will figure out how to fix this later. - if file: - file.close() + f = open("example_file.txt") + + try: + def make_upcase(line): + return line.strip().upper() + upcase_lines = map(make_upcase, f.readlines()) + self.assertEqual(__, list(upcase_lines)) + finally: + # Arg, this is ugly. + # We will figure out how to fix this later. + f.close() + except IOError: + # should never happen + self.fail() diff --git a/python 2/koans/about_with_statements.py b/python 2/koans/about_with_statements.py index df0c5e3cc..562ba128a 100644 --- a/python 2/koans/about_with_statements.py +++ b/python 2/koans/about_with_statements.py @@ -12,14 +12,18 @@ class AboutWithStatements(Koan): def count_lines(self, file_name): - file = open(file_name) try: - count = 0 - for line in file.readlines(): - count += 1 - return count - finally: - if file: file.close() + f = open(file_name) + try: + count = 0 + for line in f.readlines(): + count += 1 + return count + finally: + f.close() + except IOError: + # should never happen + self.fail() def test_counting_lines(self): self.assertEqual(__, self.count_lines("example_file.txt")) @@ -27,14 +31,18 @@ def test_counting_lines(self): # ------------------------------------------------------------------ def find_line(self, file_name): - file = open(file_name) try: - for line in file.readlines(): - match = re.search('e', line) - if match: - return line - finally: - if file: file.close() + f = open(file_name) + try: + for line in f.readlines(): + match = re.search('e', line) + if match: + return line + finally: + f.close() + except IOError: + # should never happen + self.fail() def test_finding_lines(self): self.assertEqual(__, self.find_line("example_file.txt")) @@ -77,9 +85,9 @@ def __exit__(self, cls, value, tb): # Now we write: def count_lines2(self, file_name): - with self.FileContextManager(file_name) as file: + with self.FileContextManager(file_name) as f: count = 0 - for line in file.readlines(): + for line in f.readlines(): count += 1 return count @@ -99,9 +107,9 @@ def test_finding_lines2(self): # ------------------------------------------------------------------ def count_lines3(self, file_name): - with open(file_name) as file: + with open(file_name) as f: count = 0 - for line in file.readlines(): + for line in f.readlines(): count += 1 return count diff --git a/python 3/koans/about_decorating_with_classes.py b/python 3/koans/about_decorating_with_classes.py index 358488c4c..3466bc1d4 100644 --- a/python 3/koans/about_decorating_with_classes.py +++ b/python 3/koans/about_decorating_with_classes.py @@ -101,7 +101,7 @@ def count_badly(self, num): if num==3: return 5 else: - num + return num @documenter("Does nothing") def idler(self, num): "Idler" @@ -125,4 +125,4 @@ def homer(self): def test_we_can_chain_decorators(self): self.assertEqual(__, self.homer()) self.assertEqual(__, self.homer.__doc__) - \ No newline at end of file + diff --git a/python 3/koans/about_iteration.py b/python 3/koans/about_iteration.py index d9d1e5ca2..40cc751f4 100644 --- a/python 3/koans/about_iteration.py +++ b/python 3/koans/about_iteration.py @@ -129,18 +129,17 @@ def test_all_iteration_methods_work_on_any_sequence_not_just_lists(self): self.assertEqual(__, list(result)) try: - # Files act like a collection of lines file = open("example_file.txt") - - def make_upcase(line): - return line.strip().upper() - upcase_lines = map(make_upcase, file.readlines()) - self.assertEqual(__, list(upcase_lines)) - - # NOTE: You can create your own collections that work with each, - # map, select, etc. - finally: - # Arg, this is ugly. - # We will figure out how to fix this later. - if file: - file.close() \ No newline at end of file + + try: + def make_upcase(line): + return line.strip().upper() + upcase_lines = map(make_upcase, file.readlines()) + self.assertEqual(__, list(upcase_lines)) + finally: + # Arg, this is ugly. + # We will figure out how to fix this later. + file.close() + except IOError: + # should never happen + self.fail() diff --git a/python 3/koans/about_with_statements.py b/python 3/koans/about_with_statements.py index 66f0a912e..9dd0a5f49 100644 --- a/python 3/koans/about_with_statements.py +++ b/python 3/koans/about_with_statements.py @@ -11,14 +11,18 @@ class AboutWithStatements(Koan): def count_lines(self, file_name): - file = open(file_name) try: - count = 0 - for line in file.readlines(): - count += 1 - return count - finally: - if file: file.close() + file = open(file_name) + try: + count = 0 + for line in file.readlines(): + count += 1 + return count + finally: + file.close() + except IOError: + # should never happen + self.fail() def test_counting_lines(self): self.assertEqual(__, self.count_lines("example_file.txt")) @@ -26,13 +30,18 @@ def test_counting_lines(self): # ------------------------------------------------------------------ def find_line(self, file_name): - file = open(file_name) try: - for line in file.readlines(): - match = re.search('e', line) - if match: return line - finally: - if file: file.close() + file = open(file_name) + try: + for line in file.readlines(): + match = re.search('e', line) + if match: + return line + finally: + file.close() + except IOError: + # should never happen + self.fail() def test_finding_lines(self): self.assertEqual(__, self.find_line("example_file.txt")) From 269873ac6def07461b31ccd247d23f545dbf2f5f Mon Sep 17 00:00:00 2001 From: Steve Bedford Date: Mon, 7 May 2012 23:34:01 -0400 Subject: [PATCH 011/237] Demonstrate empty dictionary literals --- python 2/koans/about_dictionaries.py | 2 ++ python 3/koans/about_dictionaries.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/python 2/koans/about_dictionaries.py b/python 2/koans/about_dictionaries.py index 25c13062a..e2ba91637 100644 --- a/python 2/koans/about_dictionaries.py +++ b/python 2/koans/about_dictionaries.py @@ -16,6 +16,8 @@ def test_creating_dictionaries(self): self.assertEqual(__, 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)) diff --git a/python 3/koans/about_dictionaries.py b/python 3/koans/about_dictionaries.py index 41e26c5fc..01995e168 100644 --- a/python 3/koans/about_dictionaries.py +++ b/python 3/koans/about_dictionaries.py @@ -15,6 +15,8 @@ def test_creating_dictionaries(self): self.assertEqual(__, 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)) From 979e43acf96c8f5e3927c9dcda3503ed727212ad Mon Sep 17 00:00:00 2001 From: DhilipSiva Date: Thu, 5 Jul 2012 19:50:06 +0530 Subject: [PATCH 012/237] Rename .txt to .rst for better rendering --- README.txt => README.rst | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.txt => README.rst (100%) diff --git a/README.txt b/README.rst similarity index 100% rename from README.txt rename to README.rst From 75cdfc6f5c65f4e9cbb361bd2c4dd5cc14af869b Mon Sep 17 00:00:00 2001 From: Sergio Ezequiel Gutierrez Alvarez Date: Wed, 18 Jul 2012 02:10:41 -0500 Subject: [PATCH 013/237] Corrected message example of method exception --- python 3/koans/about_methods.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python 3/koans/about_methods.py b/python 3/koans/about_methods.py index eb4c56cf3..643d83425 100644 --- a/python 3/koans/about_methods.py +++ b/python 3/koans/about_methods.py @@ -23,7 +23,7 @@ def test_calling_functions_with_wrong_number_of_arguments(self): msg = exception.args[0] self.assertRegexpMatches(msg, - r'my_global_function\(\) takes exactly 2 positional ' + + r'my_global_function\(\) takes exactly 2 ' + r'arguments \(0 given\)') try: From 67cf9f5ec30e4d11bceb39efebdaed085a17fff3 Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Fri, 27 Jul 2012 07:55:06 -0400 Subject: [PATCH 014/237] Fixed a typo. Thanks to tmagrino for pointing it out --- python 3/koans/about_lists.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python 3/koans/about_lists.py b/python 3/koans/about_lists.py index ae53fd153..19f939d1b 100644 --- a/python 3/koans/about_lists.py +++ b/python 3/koans/about_lists.py @@ -106,5 +106,5 @@ def test_making_queues(self): # Note, for Python 2 popping from the left hand side of a list is # inefficient. Use collections.deque instead. - # This is not as issue for Python 3 through + # This is not an issue for Python 3 through From bebd92ae68b8bf7f1bd563c2738f8ac23eff3f11 Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Fri, 27 Jul 2012 21:45:48 -0400 Subject: [PATCH 015/237] Got rid of a confusing Generator test --- python 2/koans/about_generators.py | 3 +-- python 3/koans/about_generators.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/python 2/koans/about_generators.py b/python 2/koans/about_generators.py index 1b10ad90c..cb32a50ec 100644 --- a/python 2/koans/about_generators.py +++ b/python 2/koans/about_generators.py @@ -28,8 +28,7 @@ def test_generators_are_different_to_list_comprehensions(self): self.assertEqual(2, num_list[0]) # A generator has to be iterated through. - self.assertRaises(___, num_generator[0]) # Evaluates num_generator[0] - self.assertEqual(__, list(num_generator)[0]) # This works though + self.assertEqual(__, list(num_generator)[0]) # Both list comprehensions and generators can be iterated # though. However, a generator function is only called on the diff --git a/python 3/koans/about_generators.py b/python 3/koans/about_generators.py index 19790b62b..244ea1e6b 100644 --- a/python 3/koans/about_generators.py +++ b/python 3/koans/about_generators.py @@ -30,7 +30,7 @@ def test_generators_are_different_to_list_comprehensions(self): # A generator has to be iterated through. with self.assertRaises(___): num = num_generator[0] - self.assertEqual(__, list(num_generator)[0]) # This works though + self.assertEqual(__, list(num_generator)[0]) # Both list comprehensions and generators can be iterated though. However, a generator # function is only called on the first iteration. The values are generated on the fly From 5c4ba919e52cbe5d2a00cd86f14cf3adedbe2f34 Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Fri, 27 Jul 2012 21:56:17 -0400 Subject: [PATCH 016/237] Removed the space from 'python 2' and 'python 3' folders --- README.rst | 10 +++++----- {python 2 => python2}/_runner_tests.py | 0 {python 2 => python2}/contemplate_koans.py | 0 {python 2 => python2}/example_file.txt | 0 {python 2 => python2}/koans/GREEDS_RULES.txt | 0 {python 2 => python2}/koans/__init__.py | 0 .../koans/a_normal_folder/a_module.py | 0 .../koans/a_package_folder/__init__.py | 0 .../koans/a_package_folder/a_module.py | 0 {python 2 => python2}/koans/about_asserts.py | 0 {python 2 => python2}/koans/about_attribute_access.py | 0 {python 2 => python2}/koans/about_class_attributes.py | 0 {python 2 => python2}/koans/about_classes.py | 0 .../koans/about_control_statements.py | 0 .../koans/about_decorating_with_classes.py | 0 .../koans/about_decorating_with_functions.py | 0 {python 2 => python2}/koans/about_deleting_objects.py | 0 {python 2 => python2}/koans/about_dice_project.py | 0 {python 2 => python2}/koans/about_dictionaries.py | 0 {python 2 => python2}/koans/about_exceptions.py | 0 {python 2 => python2}/koans/about_extra_credit.py | 0 {python 2 => python2}/koans/about_generators.py | 0 {python 2 => python2}/koans/about_inheritance.py | 0 {python 2 => python2}/koans/about_iteration.py | 0 {python 2 => python2}/koans/about_lambdas.py | 0 {python 2 => python2}/koans/about_list_assignments.py | 0 {python 2 => python2}/koans/about_lists.py | 0 {python 2 => python2}/koans/about_method_bindings.py | 0 {python 2 => python2}/koans/about_methods.py | 0 {python 2 => python2}/koans/about_modules.py | 0 {python 2 => python2}/koans/about_monkey_patching.py | 0 .../koans/about_multiple_inheritance.py | 0 {python 2 => python2}/koans/about_new_style_classes.py | 0 {python 2 => python2}/koans/about_none.py | 0 {python 2 => python2}/koans/about_packages.py | 0 .../koans/about_proxy_object_project.py | 0 {python 2 => python2}/koans/about_regex.py | 0 {python 2 => python2}/koans/about_scope.py | 0 {python 2 => python2}/koans/about_scoring_project.py | 0 {python 2 => python2}/koans/about_sets.py | 0 {python 2 => python2}/koans/about_strings.py | 0 {python 2 => python2}/koans/about_triangle_project.py | 0 {python 2 => python2}/koans/about_triangle_project2.py | 0 {python 2 => python2}/koans/about_true_and_false.py | 0 {python 2 => python2}/koans/about_tuples.py | 0 {python 2 => python2}/koans/about_with_statements.py | 0 {python 2 => python2}/koans/another_local_module.py | 0 {python 2 => python2}/koans/jims.py | 0 {python 2 => python2}/koans/joes.py | 0 {python 2 => python2}/koans/local_module.py | 0 .../koans/local_module_with_all_defined.py | 0 {python 2 => python2}/koans/triangle.py | 0 {python 2 => python2}/libs/__init__.py | 0 {python 2 => python2}/libs/colorama/LICENSE-colorama | 0 {python 2 => python2}/libs/colorama/__init__.py | 0 {python 2 => python2}/libs/colorama/ansi.py | 0 {python 2 => python2}/libs/colorama/ansitowin32.py | 0 {python 2 => python2}/libs/colorama/initialise.py | 0 {python 2 => python2}/libs/colorama/win32.py | 0 {python 2 => python2}/libs/colorama/winterm.py | 0 {python 2 => python2}/libs/mock.py | 0 {python 2 => python2}/run.bat | 0 {python 2 => python2}/run.sh | 0 {python 2 => python2}/runner/__init__.py | 0 {python 2 => python2}/runner/helper.py | 0 {python 2 => python2}/runner/koan.py | 0 {python 2 => python2}/runner/mockable_test_result.py | 0 {python 2 => python2}/runner/mountain.py | 0 {python 2 => python2}/runner/path_to_enlightenment.py | 0 {python 2 => python2}/runner/runner_tests/__init__.py | 0 .../runner/runner_tests/test_helper.py | 0 .../runner/runner_tests/test_mountain.py | 0 .../runner/runner_tests/test_sensei.py | 0 {python 2 => python2}/runner/sensei.py | 0 {python 2 => python2}/runner/writeln_decorator.py | 0 {python 3 => python3}/_runner_tests.py | 0 {python 3 => python3}/contemplate_koans.py | 0 {python 3 => python3}/example_file.txt | 0 {python 3 => python3}/koans/GREEDS_RULES.txt | 0 {python 3 => python3}/koans/__init__.py | 0 .../koans/a_normal_folder/a_module.py | 0 .../koans/a_package_folder/__init__.py | 0 .../koans/a_package_folder/a_module.py | 0 {python 3 => python3}/koans/about_asserts.py | 0 {python 3 => python3}/koans/about_attribute_access.py | 0 {python 3 => python3}/koans/about_class_attributes.py | 0 {python 3 => python3}/koans/about_classes.py | 0 .../koans/about_control_statements.py | 0 .../koans/about_decorating_with_classes.py | 0 .../koans/about_decorating_with_functions.py | 0 {python 3 => python3}/koans/about_deleting_objects.py | 0 {python 3 => python3}/koans/about_dice_project.py | 0 {python 3 => python3}/koans/about_dictionaries.py | 0 {python 3 => python3}/koans/about_exceptions.py | 0 {python 3 => python3}/koans/about_extra_credit.py | 0 {python 3 => python3}/koans/about_generators.py | 0 {python 3 => python3}/koans/about_inheritance.py | 0 {python 3 => python3}/koans/about_iteration.py | 0 {python 3 => python3}/koans/about_lambdas.py | 0 {python 3 => python3}/koans/about_list_assignments.py | 0 {python 3 => python3}/koans/about_lists.py | 0 {python 3 => python3}/koans/about_method_bindings.py | 0 {python 3 => python3}/koans/about_methods.py | 0 {python 3 => python3}/koans/about_modules.py | 0 {python 3 => python3}/koans/about_monkey_patching.py | 0 .../koans/about_multiple_inheritance.py | 0 {python 3 => python3}/koans/about_none.py | 0 {python 3 => python3}/koans/about_packages.py | 0 .../koans/about_proxy_object_project.py | 0 {python 3 => python3}/koans/about_regex.py | 0 {python 3 => python3}/koans/about_scope.py | 0 {python 3 => python3}/koans/about_scoring_project.py | 0 {python 3 => python3}/koans/about_sets.py | 0 {python 3 => python3}/koans/about_strings.py | 0 {python 3 => python3}/koans/about_triangle_project.py | 0 {python 3 => python3}/koans/about_triangle_project2.py | 0 {python 3 => python3}/koans/about_true_and_false.py | 0 {python 3 => python3}/koans/about_tuples.py | 0 {python 3 => python3}/koans/about_with_statements.py | 0 {python 3 => python3}/koans/another_local_module.py | 0 {python 3 => python3}/koans/jims.py | 0 {python 3 => python3}/koans/joes.py | 0 {python 3 => python3}/koans/local_module.py | 0 .../koans/local_module_with_all_defined.py | 0 {python 3 => python3}/koans/triangle.py | 0 {python 3 => python3}/libs/__init__.py | 0 {python 3 => python3}/libs/colorama/LICENSE-colorama | 0 {python 3 => python3}/libs/colorama/__init__.py | 0 {python 3 => python3}/libs/colorama/ansi.py | 0 {python 3 => python3}/libs/colorama/ansitowin32.py | 0 {python 3 => python3}/libs/colorama/initialise.py | 0 {python 3 => python3}/libs/colorama/win32.py | 0 {python 3 => python3}/libs/colorama/winterm.py | 0 {python 3 => python3}/libs/mock.py | 0 {python 3 => python3}/run.bat | 0 {python 3 => python3}/run.sh | 0 {python 3 => python3}/runner/__init__.py | 0 {python 3 => python3}/runner/helper.py | 0 {python 3 => python3}/runner/koan.py | 0 {python 3 => python3}/runner/mockable_test_result.py | 0 {python 3 => python3}/runner/mountain.py | 0 {python 3 => python3}/runner/path_to_enlightenment.py | 0 {python 3 => python3}/runner/runner_tests/__init__.py | 0 .../runner/runner_tests/test_helper.py | 0 .../runner/runner_tests/test_mountain.py | 0 .../runner/runner_tests/test_sensei.py | 0 {python 3 => python3}/runner/sensei.py | 0 {python 3 => python3}/runner/writeln_decorator.py | 0 148 files changed, 5 insertions(+), 5 deletions(-) rename {python 2 => python2}/_runner_tests.py (100%) rename {python 2 => python2}/contemplate_koans.py (100%) rename {python 2 => python2}/example_file.txt (100%) rename {python 2 => python2}/koans/GREEDS_RULES.txt (100%) rename {python 2 => python2}/koans/__init__.py (100%) rename {python 2 => python2}/koans/a_normal_folder/a_module.py (100%) rename {python 2 => python2}/koans/a_package_folder/__init__.py (100%) rename {python 2 => python2}/koans/a_package_folder/a_module.py (100%) rename {python 2 => python2}/koans/about_asserts.py (100%) rename {python 2 => python2}/koans/about_attribute_access.py (100%) rename {python 2 => python2}/koans/about_class_attributes.py (100%) rename {python 2 => python2}/koans/about_classes.py (100%) rename {python 2 => python2}/koans/about_control_statements.py (100%) rename {python 2 => python2}/koans/about_decorating_with_classes.py (100%) rename {python 2 => python2}/koans/about_decorating_with_functions.py (100%) rename {python 2 => python2}/koans/about_deleting_objects.py (100%) rename {python 2 => python2}/koans/about_dice_project.py (100%) rename {python 2 => python2}/koans/about_dictionaries.py (100%) rename {python 2 => python2}/koans/about_exceptions.py (100%) rename {python 2 => python2}/koans/about_extra_credit.py (100%) rename {python 2 => python2}/koans/about_generators.py (100%) rename {python 2 => python2}/koans/about_inheritance.py (100%) rename {python 2 => python2}/koans/about_iteration.py (100%) rename {python 2 => python2}/koans/about_lambdas.py (100%) rename {python 2 => python2}/koans/about_list_assignments.py (100%) rename {python 2 => python2}/koans/about_lists.py (100%) rename {python 2 => python2}/koans/about_method_bindings.py (100%) rename {python 2 => python2}/koans/about_methods.py (100%) rename {python 2 => python2}/koans/about_modules.py (100%) rename {python 2 => python2}/koans/about_monkey_patching.py (100%) rename {python 2 => python2}/koans/about_multiple_inheritance.py (100%) rename {python 2 => python2}/koans/about_new_style_classes.py (100%) rename {python 2 => python2}/koans/about_none.py (100%) rename {python 2 => python2}/koans/about_packages.py (100%) rename {python 2 => python2}/koans/about_proxy_object_project.py (100%) rename {python 2 => python2}/koans/about_regex.py (100%) rename {python 2 => python2}/koans/about_scope.py (100%) rename {python 2 => python2}/koans/about_scoring_project.py (100%) rename {python 2 => python2}/koans/about_sets.py (100%) rename {python 2 => python2}/koans/about_strings.py (100%) rename {python 2 => python2}/koans/about_triangle_project.py (100%) rename {python 2 => python2}/koans/about_triangle_project2.py (100%) rename {python 2 => python2}/koans/about_true_and_false.py (100%) rename {python 2 => python2}/koans/about_tuples.py (100%) rename {python 2 => python2}/koans/about_with_statements.py (100%) rename {python 2 => python2}/koans/another_local_module.py (100%) rename {python 2 => python2}/koans/jims.py (100%) rename {python 2 => python2}/koans/joes.py (100%) rename {python 2 => python2}/koans/local_module.py (100%) rename {python 2 => python2}/koans/local_module_with_all_defined.py (100%) rename {python 2 => python2}/koans/triangle.py (100%) rename {python 2 => python2}/libs/__init__.py (100%) rename {python 2 => python2}/libs/colorama/LICENSE-colorama (100%) rename {python 2 => python2}/libs/colorama/__init__.py (100%) rename {python 2 => python2}/libs/colorama/ansi.py (100%) rename {python 2 => python2}/libs/colorama/ansitowin32.py (100%) rename {python 2 => python2}/libs/colorama/initialise.py (100%) rename {python 2 => python2}/libs/colorama/win32.py (100%) rename {python 2 => python2}/libs/colorama/winterm.py (100%) rename {python 2 => python2}/libs/mock.py (100%) rename {python 2 => python2}/run.bat (100%) rename {python 2 => python2}/run.sh (100%) rename {python 2 => python2}/runner/__init__.py (100%) rename {python 2 => python2}/runner/helper.py (100%) rename {python 2 => python2}/runner/koan.py (100%) rename {python 2 => python2}/runner/mockable_test_result.py (100%) rename {python 2 => python2}/runner/mountain.py (100%) rename {python 2 => python2}/runner/path_to_enlightenment.py (100%) rename {python 2 => python2}/runner/runner_tests/__init__.py (100%) rename {python 2 => python2}/runner/runner_tests/test_helper.py (100%) rename {python 2 => python2}/runner/runner_tests/test_mountain.py (100%) rename {python 2 => python2}/runner/runner_tests/test_sensei.py (100%) rename {python 2 => python2}/runner/sensei.py (100%) rename {python 2 => python2}/runner/writeln_decorator.py (100%) rename {python 3 => python3}/_runner_tests.py (100%) rename {python 3 => python3}/contemplate_koans.py (100%) rename {python 3 => python3}/example_file.txt (100%) rename {python 3 => python3}/koans/GREEDS_RULES.txt (100%) rename {python 3 => python3}/koans/__init__.py (100%) rename {python 3 => python3}/koans/a_normal_folder/a_module.py (100%) rename {python 3 => python3}/koans/a_package_folder/__init__.py (100%) rename {python 3 => python3}/koans/a_package_folder/a_module.py (100%) rename {python 3 => python3}/koans/about_asserts.py (100%) rename {python 3 => python3}/koans/about_attribute_access.py (100%) rename {python 3 => python3}/koans/about_class_attributes.py (100%) rename {python 3 => python3}/koans/about_classes.py (100%) rename {python 3 => python3}/koans/about_control_statements.py (100%) rename {python 3 => python3}/koans/about_decorating_with_classes.py (100%) rename {python 3 => python3}/koans/about_decorating_with_functions.py (100%) rename {python 3 => python3}/koans/about_deleting_objects.py (100%) rename {python 3 => python3}/koans/about_dice_project.py (100%) rename {python 3 => python3}/koans/about_dictionaries.py (100%) rename {python 3 => python3}/koans/about_exceptions.py (100%) rename {python 3 => python3}/koans/about_extra_credit.py (100%) rename {python 3 => python3}/koans/about_generators.py (100%) rename {python 3 => python3}/koans/about_inheritance.py (100%) rename {python 3 => python3}/koans/about_iteration.py (100%) rename {python 3 => python3}/koans/about_lambdas.py (100%) rename {python 3 => python3}/koans/about_list_assignments.py (100%) rename {python 3 => python3}/koans/about_lists.py (100%) rename {python 3 => python3}/koans/about_method_bindings.py (100%) rename {python 3 => python3}/koans/about_methods.py (100%) rename {python 3 => python3}/koans/about_modules.py (100%) rename {python 3 => python3}/koans/about_monkey_patching.py (100%) rename {python 3 => python3}/koans/about_multiple_inheritance.py (100%) rename {python 3 => python3}/koans/about_none.py (100%) rename {python 3 => python3}/koans/about_packages.py (100%) rename {python 3 => python3}/koans/about_proxy_object_project.py (100%) rename {python 3 => python3}/koans/about_regex.py (100%) rename {python 3 => python3}/koans/about_scope.py (100%) rename {python 3 => python3}/koans/about_scoring_project.py (100%) rename {python 3 => python3}/koans/about_sets.py (100%) rename {python 3 => python3}/koans/about_strings.py (100%) rename {python 3 => python3}/koans/about_triangle_project.py (100%) rename {python 3 => python3}/koans/about_triangle_project2.py (100%) rename {python 3 => python3}/koans/about_true_and_false.py (100%) rename {python 3 => python3}/koans/about_tuples.py (100%) rename {python 3 => python3}/koans/about_with_statements.py (100%) rename {python 3 => python3}/koans/another_local_module.py (100%) rename {python 3 => python3}/koans/jims.py (100%) rename {python 3 => python3}/koans/joes.py (100%) rename {python 3 => python3}/koans/local_module.py (100%) rename {python 3 => python3}/koans/local_module_with_all_defined.py (100%) rename {python 3 => python3}/koans/triangle.py (100%) rename {python 3 => python3}/libs/__init__.py (100%) rename {python 3 => python3}/libs/colorama/LICENSE-colorama (100%) rename {python 3 => python3}/libs/colorama/__init__.py (100%) rename {python 3 => python3}/libs/colorama/ansi.py (100%) rename {python 3 => python3}/libs/colorama/ansitowin32.py (100%) rename {python 3 => python3}/libs/colorama/initialise.py (100%) rename {python 3 => python3}/libs/colorama/win32.py (100%) rename {python 3 => python3}/libs/colorama/winterm.py (100%) rename {python 3 => python3}/libs/mock.py (100%) rename {python 3 => python3}/run.bat (100%) rename {python 3 => python3}/run.sh (100%) rename {python 3 => python3}/runner/__init__.py (100%) rename {python 3 => python3}/runner/helper.py (100%) rename {python 3 => python3}/runner/koan.py (100%) rename {python 3 => python3}/runner/mockable_test_result.py (100%) rename {python 3 => python3}/runner/mountain.py (100%) rename {python 3 => python3}/runner/path_to_enlightenment.py (100%) rename {python 3 => python3}/runner/runner_tests/__init__.py (100%) rename {python 3 => python3}/runner/runner_tests/test_helper.py (100%) rename {python 3 => python3}/runner/runner_tests/test_mountain.py (100%) rename {python 3 => python3}/runner/runner_tests/test_sensei.py (100%) rename {python 3 => python3}/runner/sensei.py (100%) rename {python 3 => python3}/runner/writeln_decorator.py (100%) diff --git a/README.rst b/README.rst index cac80571f..6c92e2dcf 100644 --- a/README.rst +++ b/README.rst @@ -64,8 +64,8 @@ or In my case I'm using Python 3 with windows, so I fire up my command shell (cmd.exe) and run this: - C:\>cd "c:\hg\python_koans\python 3" - C:\hg\python_koans\python 3_1>python contemplate_koans.py + C:\>cd "c:\hg\python_koans\python3" + C:\hg\python_koans\python3>python contemplate_koans.py Thinking AboutAsserts test_assert_truth has damaged your karma. @@ -74,13 +74,13 @@ In my case I'm using Python 3 with windows, so I fire up my command shell (cmd.e AssertionError: False is not True Please meditate on the following code: - File "C:\hg\python_koans\python 3\koans\about_asserts.py", line 12, in test_ + File "C:\hg\python_koans\python3\koans\about_asserts.py", line 12, in test_ assert_truth self.assertTrue(False) # This should be true Beautiful is better than ugly. - C:\hg\python_koans\python 3> + C:\hg\python_koans\python3> Apparently a test failed: @@ -99,7 +99,7 @@ Sooner or later you will likely encounter tests where you are not sure what the This is where the Python Command Line can come in handy. in this case I can fire up the command line, recreate the scenario and run queries: - C:\hg\python_koans\python 3>python + C:\hg\python_koans\python3>python Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. diff --git a/python 2/_runner_tests.py b/python2/_runner_tests.py similarity index 100% rename from python 2/_runner_tests.py rename to python2/_runner_tests.py diff --git a/python 2/contemplate_koans.py b/python2/contemplate_koans.py similarity index 100% rename from python 2/contemplate_koans.py rename to python2/contemplate_koans.py diff --git a/python 2/example_file.txt b/python2/example_file.txt similarity index 100% rename from python 2/example_file.txt rename to python2/example_file.txt diff --git a/python 2/koans/GREEDS_RULES.txt b/python2/koans/GREEDS_RULES.txt similarity index 100% rename from python 2/koans/GREEDS_RULES.txt rename to python2/koans/GREEDS_RULES.txt diff --git a/python 2/koans/__init__.py b/python2/koans/__init__.py similarity index 100% rename from python 2/koans/__init__.py rename to python2/koans/__init__.py diff --git a/python 2/koans/a_normal_folder/a_module.py b/python2/koans/a_normal_folder/a_module.py similarity index 100% rename from python 2/koans/a_normal_folder/a_module.py rename to python2/koans/a_normal_folder/a_module.py diff --git a/python 2/koans/a_package_folder/__init__.py b/python2/koans/a_package_folder/__init__.py similarity index 100% rename from python 2/koans/a_package_folder/__init__.py rename to python2/koans/a_package_folder/__init__.py diff --git a/python 2/koans/a_package_folder/a_module.py b/python2/koans/a_package_folder/a_module.py similarity index 100% rename from python 2/koans/a_package_folder/a_module.py rename to python2/koans/a_package_folder/a_module.py diff --git a/python 2/koans/about_asserts.py b/python2/koans/about_asserts.py similarity index 100% rename from python 2/koans/about_asserts.py rename to python2/koans/about_asserts.py diff --git a/python 2/koans/about_attribute_access.py b/python2/koans/about_attribute_access.py similarity index 100% rename from python 2/koans/about_attribute_access.py rename to python2/koans/about_attribute_access.py diff --git a/python 2/koans/about_class_attributes.py b/python2/koans/about_class_attributes.py similarity index 100% rename from python 2/koans/about_class_attributes.py rename to python2/koans/about_class_attributes.py diff --git a/python 2/koans/about_classes.py b/python2/koans/about_classes.py similarity index 100% rename from python 2/koans/about_classes.py rename to python2/koans/about_classes.py diff --git a/python 2/koans/about_control_statements.py b/python2/koans/about_control_statements.py similarity index 100% rename from python 2/koans/about_control_statements.py rename to python2/koans/about_control_statements.py diff --git a/python 2/koans/about_decorating_with_classes.py b/python2/koans/about_decorating_with_classes.py similarity index 100% rename from python 2/koans/about_decorating_with_classes.py rename to python2/koans/about_decorating_with_classes.py diff --git a/python 2/koans/about_decorating_with_functions.py b/python2/koans/about_decorating_with_functions.py similarity index 100% rename from python 2/koans/about_decorating_with_functions.py rename to python2/koans/about_decorating_with_functions.py diff --git a/python 2/koans/about_deleting_objects.py b/python2/koans/about_deleting_objects.py similarity index 100% rename from python 2/koans/about_deleting_objects.py rename to python2/koans/about_deleting_objects.py diff --git a/python 2/koans/about_dice_project.py b/python2/koans/about_dice_project.py similarity index 100% rename from python 2/koans/about_dice_project.py rename to python2/koans/about_dice_project.py diff --git a/python 2/koans/about_dictionaries.py b/python2/koans/about_dictionaries.py similarity index 100% rename from python 2/koans/about_dictionaries.py rename to python2/koans/about_dictionaries.py diff --git a/python 2/koans/about_exceptions.py b/python2/koans/about_exceptions.py similarity index 100% rename from python 2/koans/about_exceptions.py rename to python2/koans/about_exceptions.py diff --git a/python 2/koans/about_extra_credit.py b/python2/koans/about_extra_credit.py similarity index 100% rename from python 2/koans/about_extra_credit.py rename to python2/koans/about_extra_credit.py diff --git a/python 2/koans/about_generators.py b/python2/koans/about_generators.py similarity index 100% rename from python 2/koans/about_generators.py rename to python2/koans/about_generators.py diff --git a/python 2/koans/about_inheritance.py b/python2/koans/about_inheritance.py similarity index 100% rename from python 2/koans/about_inheritance.py rename to python2/koans/about_inheritance.py diff --git a/python 2/koans/about_iteration.py b/python2/koans/about_iteration.py similarity index 100% rename from python 2/koans/about_iteration.py rename to python2/koans/about_iteration.py diff --git a/python 2/koans/about_lambdas.py b/python2/koans/about_lambdas.py similarity index 100% rename from python 2/koans/about_lambdas.py rename to python2/koans/about_lambdas.py diff --git a/python 2/koans/about_list_assignments.py b/python2/koans/about_list_assignments.py similarity index 100% rename from python 2/koans/about_list_assignments.py rename to python2/koans/about_list_assignments.py diff --git a/python 2/koans/about_lists.py b/python2/koans/about_lists.py similarity index 100% rename from python 2/koans/about_lists.py rename to python2/koans/about_lists.py diff --git a/python 2/koans/about_method_bindings.py b/python2/koans/about_method_bindings.py similarity index 100% rename from python 2/koans/about_method_bindings.py rename to python2/koans/about_method_bindings.py diff --git a/python 2/koans/about_methods.py b/python2/koans/about_methods.py similarity index 100% rename from python 2/koans/about_methods.py rename to python2/koans/about_methods.py diff --git a/python 2/koans/about_modules.py b/python2/koans/about_modules.py similarity index 100% rename from python 2/koans/about_modules.py rename to python2/koans/about_modules.py diff --git a/python 2/koans/about_monkey_patching.py b/python2/koans/about_monkey_patching.py similarity index 100% rename from python 2/koans/about_monkey_patching.py rename to python2/koans/about_monkey_patching.py diff --git a/python 2/koans/about_multiple_inheritance.py b/python2/koans/about_multiple_inheritance.py similarity index 100% rename from python 2/koans/about_multiple_inheritance.py rename to python2/koans/about_multiple_inheritance.py diff --git a/python 2/koans/about_new_style_classes.py b/python2/koans/about_new_style_classes.py similarity index 100% rename from python 2/koans/about_new_style_classes.py rename to python2/koans/about_new_style_classes.py diff --git a/python 2/koans/about_none.py b/python2/koans/about_none.py similarity index 100% rename from python 2/koans/about_none.py rename to python2/koans/about_none.py diff --git a/python 2/koans/about_packages.py b/python2/koans/about_packages.py similarity index 100% rename from python 2/koans/about_packages.py rename to python2/koans/about_packages.py diff --git a/python 2/koans/about_proxy_object_project.py b/python2/koans/about_proxy_object_project.py similarity index 100% rename from python 2/koans/about_proxy_object_project.py rename to python2/koans/about_proxy_object_project.py diff --git a/python 2/koans/about_regex.py b/python2/koans/about_regex.py similarity index 100% rename from python 2/koans/about_regex.py rename to python2/koans/about_regex.py diff --git a/python 2/koans/about_scope.py b/python2/koans/about_scope.py similarity index 100% rename from python 2/koans/about_scope.py rename to python2/koans/about_scope.py diff --git a/python 2/koans/about_scoring_project.py b/python2/koans/about_scoring_project.py similarity index 100% rename from python 2/koans/about_scoring_project.py rename to python2/koans/about_scoring_project.py diff --git a/python 2/koans/about_sets.py b/python2/koans/about_sets.py similarity index 100% rename from python 2/koans/about_sets.py rename to python2/koans/about_sets.py diff --git a/python 2/koans/about_strings.py b/python2/koans/about_strings.py similarity index 100% rename from python 2/koans/about_strings.py rename to python2/koans/about_strings.py diff --git a/python 2/koans/about_triangle_project.py b/python2/koans/about_triangle_project.py similarity index 100% rename from python 2/koans/about_triangle_project.py rename to python2/koans/about_triangle_project.py diff --git a/python 2/koans/about_triangle_project2.py b/python2/koans/about_triangle_project2.py similarity index 100% rename from python 2/koans/about_triangle_project2.py rename to python2/koans/about_triangle_project2.py diff --git a/python 2/koans/about_true_and_false.py b/python2/koans/about_true_and_false.py similarity index 100% rename from python 2/koans/about_true_and_false.py rename to python2/koans/about_true_and_false.py diff --git a/python 2/koans/about_tuples.py b/python2/koans/about_tuples.py similarity index 100% rename from python 2/koans/about_tuples.py rename to python2/koans/about_tuples.py diff --git a/python 2/koans/about_with_statements.py b/python2/koans/about_with_statements.py similarity index 100% rename from python 2/koans/about_with_statements.py rename to python2/koans/about_with_statements.py diff --git a/python 2/koans/another_local_module.py b/python2/koans/another_local_module.py similarity index 100% rename from python 2/koans/another_local_module.py rename to python2/koans/another_local_module.py diff --git a/python 2/koans/jims.py b/python2/koans/jims.py similarity index 100% rename from python 2/koans/jims.py rename to python2/koans/jims.py diff --git a/python 2/koans/joes.py b/python2/koans/joes.py similarity index 100% rename from python 2/koans/joes.py rename to python2/koans/joes.py diff --git a/python 2/koans/local_module.py b/python2/koans/local_module.py similarity index 100% rename from python 2/koans/local_module.py rename to python2/koans/local_module.py diff --git a/python 2/koans/local_module_with_all_defined.py b/python2/koans/local_module_with_all_defined.py similarity index 100% rename from python 2/koans/local_module_with_all_defined.py rename to python2/koans/local_module_with_all_defined.py diff --git a/python 2/koans/triangle.py b/python2/koans/triangle.py similarity index 100% rename from python 2/koans/triangle.py rename to python2/koans/triangle.py diff --git a/python 2/libs/__init__.py b/python2/libs/__init__.py similarity index 100% rename from python 2/libs/__init__.py rename to python2/libs/__init__.py diff --git a/python 2/libs/colorama/LICENSE-colorama b/python2/libs/colorama/LICENSE-colorama similarity index 100% rename from python 2/libs/colorama/LICENSE-colorama rename to python2/libs/colorama/LICENSE-colorama diff --git a/python 2/libs/colorama/__init__.py b/python2/libs/colorama/__init__.py similarity index 100% rename from python 2/libs/colorama/__init__.py rename to python2/libs/colorama/__init__.py diff --git a/python 2/libs/colorama/ansi.py b/python2/libs/colorama/ansi.py similarity index 100% rename from python 2/libs/colorama/ansi.py rename to python2/libs/colorama/ansi.py diff --git a/python 2/libs/colorama/ansitowin32.py b/python2/libs/colorama/ansitowin32.py similarity index 100% rename from python 2/libs/colorama/ansitowin32.py rename to python2/libs/colorama/ansitowin32.py diff --git a/python 2/libs/colorama/initialise.py b/python2/libs/colorama/initialise.py similarity index 100% rename from python 2/libs/colorama/initialise.py rename to python2/libs/colorama/initialise.py diff --git a/python 2/libs/colorama/win32.py b/python2/libs/colorama/win32.py similarity index 100% rename from python 2/libs/colorama/win32.py rename to python2/libs/colorama/win32.py diff --git a/python 2/libs/colorama/winterm.py b/python2/libs/colorama/winterm.py similarity index 100% rename from python 2/libs/colorama/winterm.py rename to python2/libs/colorama/winterm.py diff --git a/python 2/libs/mock.py b/python2/libs/mock.py similarity index 100% rename from python 2/libs/mock.py rename to python2/libs/mock.py diff --git a/python 2/run.bat b/python2/run.bat similarity index 100% rename from python 2/run.bat rename to python2/run.bat diff --git a/python 2/run.sh b/python2/run.sh similarity index 100% rename from python 2/run.sh rename to python2/run.sh diff --git a/python 2/runner/__init__.py b/python2/runner/__init__.py similarity index 100% rename from python 2/runner/__init__.py rename to python2/runner/__init__.py diff --git a/python 2/runner/helper.py b/python2/runner/helper.py similarity index 100% rename from python 2/runner/helper.py rename to python2/runner/helper.py diff --git a/python 2/runner/koan.py b/python2/runner/koan.py similarity index 100% rename from python 2/runner/koan.py rename to python2/runner/koan.py diff --git a/python 2/runner/mockable_test_result.py b/python2/runner/mockable_test_result.py similarity index 100% rename from python 2/runner/mockable_test_result.py rename to python2/runner/mockable_test_result.py diff --git a/python 2/runner/mountain.py b/python2/runner/mountain.py similarity index 100% rename from python 2/runner/mountain.py rename to python2/runner/mountain.py diff --git a/python 2/runner/path_to_enlightenment.py b/python2/runner/path_to_enlightenment.py similarity index 100% rename from python 2/runner/path_to_enlightenment.py rename to python2/runner/path_to_enlightenment.py diff --git a/python 2/runner/runner_tests/__init__.py b/python2/runner/runner_tests/__init__.py similarity index 100% rename from python 2/runner/runner_tests/__init__.py rename to python2/runner/runner_tests/__init__.py diff --git a/python 2/runner/runner_tests/test_helper.py b/python2/runner/runner_tests/test_helper.py similarity index 100% rename from python 2/runner/runner_tests/test_helper.py rename to python2/runner/runner_tests/test_helper.py diff --git a/python 2/runner/runner_tests/test_mountain.py b/python2/runner/runner_tests/test_mountain.py similarity index 100% rename from python 2/runner/runner_tests/test_mountain.py rename to python2/runner/runner_tests/test_mountain.py diff --git a/python 2/runner/runner_tests/test_sensei.py b/python2/runner/runner_tests/test_sensei.py similarity index 100% rename from python 2/runner/runner_tests/test_sensei.py rename to python2/runner/runner_tests/test_sensei.py diff --git a/python 2/runner/sensei.py b/python2/runner/sensei.py similarity index 100% rename from python 2/runner/sensei.py rename to python2/runner/sensei.py diff --git a/python 2/runner/writeln_decorator.py b/python2/runner/writeln_decorator.py similarity index 100% rename from python 2/runner/writeln_decorator.py rename to python2/runner/writeln_decorator.py diff --git a/python 3/_runner_tests.py b/python3/_runner_tests.py similarity index 100% rename from python 3/_runner_tests.py rename to python3/_runner_tests.py diff --git a/python 3/contemplate_koans.py b/python3/contemplate_koans.py similarity index 100% rename from python 3/contemplate_koans.py rename to python3/contemplate_koans.py diff --git a/python 3/example_file.txt b/python3/example_file.txt similarity index 100% rename from python 3/example_file.txt rename to python3/example_file.txt diff --git a/python 3/koans/GREEDS_RULES.txt b/python3/koans/GREEDS_RULES.txt similarity index 100% rename from python 3/koans/GREEDS_RULES.txt rename to python3/koans/GREEDS_RULES.txt diff --git a/python 3/koans/__init__.py b/python3/koans/__init__.py similarity index 100% rename from python 3/koans/__init__.py rename to python3/koans/__init__.py diff --git a/python 3/koans/a_normal_folder/a_module.py b/python3/koans/a_normal_folder/a_module.py similarity index 100% rename from python 3/koans/a_normal_folder/a_module.py rename to python3/koans/a_normal_folder/a_module.py diff --git a/python 3/koans/a_package_folder/__init__.py b/python3/koans/a_package_folder/__init__.py similarity index 100% rename from python 3/koans/a_package_folder/__init__.py rename to python3/koans/a_package_folder/__init__.py diff --git a/python 3/koans/a_package_folder/a_module.py b/python3/koans/a_package_folder/a_module.py similarity index 100% rename from python 3/koans/a_package_folder/a_module.py rename to python3/koans/a_package_folder/a_module.py diff --git a/python 3/koans/about_asserts.py b/python3/koans/about_asserts.py similarity index 100% rename from python 3/koans/about_asserts.py rename to python3/koans/about_asserts.py diff --git a/python 3/koans/about_attribute_access.py b/python3/koans/about_attribute_access.py similarity index 100% rename from python 3/koans/about_attribute_access.py rename to python3/koans/about_attribute_access.py diff --git a/python 3/koans/about_class_attributes.py b/python3/koans/about_class_attributes.py similarity index 100% rename from python 3/koans/about_class_attributes.py rename to python3/koans/about_class_attributes.py diff --git a/python 3/koans/about_classes.py b/python3/koans/about_classes.py similarity index 100% rename from python 3/koans/about_classes.py rename to python3/koans/about_classes.py diff --git a/python 3/koans/about_control_statements.py b/python3/koans/about_control_statements.py similarity index 100% rename from python 3/koans/about_control_statements.py rename to python3/koans/about_control_statements.py diff --git a/python 3/koans/about_decorating_with_classes.py b/python3/koans/about_decorating_with_classes.py similarity index 100% rename from python 3/koans/about_decorating_with_classes.py rename to python3/koans/about_decorating_with_classes.py diff --git a/python 3/koans/about_decorating_with_functions.py b/python3/koans/about_decorating_with_functions.py similarity index 100% rename from python 3/koans/about_decorating_with_functions.py rename to python3/koans/about_decorating_with_functions.py diff --git a/python 3/koans/about_deleting_objects.py b/python3/koans/about_deleting_objects.py similarity index 100% rename from python 3/koans/about_deleting_objects.py rename to python3/koans/about_deleting_objects.py diff --git a/python 3/koans/about_dice_project.py b/python3/koans/about_dice_project.py similarity index 100% rename from python 3/koans/about_dice_project.py rename to python3/koans/about_dice_project.py diff --git a/python 3/koans/about_dictionaries.py b/python3/koans/about_dictionaries.py similarity index 100% rename from python 3/koans/about_dictionaries.py rename to python3/koans/about_dictionaries.py diff --git a/python 3/koans/about_exceptions.py b/python3/koans/about_exceptions.py similarity index 100% rename from python 3/koans/about_exceptions.py rename to python3/koans/about_exceptions.py diff --git a/python 3/koans/about_extra_credit.py b/python3/koans/about_extra_credit.py similarity index 100% rename from python 3/koans/about_extra_credit.py rename to python3/koans/about_extra_credit.py diff --git a/python 3/koans/about_generators.py b/python3/koans/about_generators.py similarity index 100% rename from python 3/koans/about_generators.py rename to python3/koans/about_generators.py diff --git a/python 3/koans/about_inheritance.py b/python3/koans/about_inheritance.py similarity index 100% rename from python 3/koans/about_inheritance.py rename to python3/koans/about_inheritance.py diff --git a/python 3/koans/about_iteration.py b/python3/koans/about_iteration.py similarity index 100% rename from python 3/koans/about_iteration.py rename to python3/koans/about_iteration.py diff --git a/python 3/koans/about_lambdas.py b/python3/koans/about_lambdas.py similarity index 100% rename from python 3/koans/about_lambdas.py rename to python3/koans/about_lambdas.py diff --git a/python 3/koans/about_list_assignments.py b/python3/koans/about_list_assignments.py similarity index 100% rename from python 3/koans/about_list_assignments.py rename to python3/koans/about_list_assignments.py diff --git a/python 3/koans/about_lists.py b/python3/koans/about_lists.py similarity index 100% rename from python 3/koans/about_lists.py rename to python3/koans/about_lists.py diff --git a/python 3/koans/about_method_bindings.py b/python3/koans/about_method_bindings.py similarity index 100% rename from python 3/koans/about_method_bindings.py rename to python3/koans/about_method_bindings.py diff --git a/python 3/koans/about_methods.py b/python3/koans/about_methods.py similarity index 100% rename from python 3/koans/about_methods.py rename to python3/koans/about_methods.py diff --git a/python 3/koans/about_modules.py b/python3/koans/about_modules.py similarity index 100% rename from python 3/koans/about_modules.py rename to python3/koans/about_modules.py diff --git a/python 3/koans/about_monkey_patching.py b/python3/koans/about_monkey_patching.py similarity index 100% rename from python 3/koans/about_monkey_patching.py rename to python3/koans/about_monkey_patching.py diff --git a/python 3/koans/about_multiple_inheritance.py b/python3/koans/about_multiple_inheritance.py similarity index 100% rename from python 3/koans/about_multiple_inheritance.py rename to python3/koans/about_multiple_inheritance.py diff --git a/python 3/koans/about_none.py b/python3/koans/about_none.py similarity index 100% rename from python 3/koans/about_none.py rename to python3/koans/about_none.py diff --git a/python 3/koans/about_packages.py b/python3/koans/about_packages.py similarity index 100% rename from python 3/koans/about_packages.py rename to python3/koans/about_packages.py diff --git a/python 3/koans/about_proxy_object_project.py b/python3/koans/about_proxy_object_project.py similarity index 100% rename from python 3/koans/about_proxy_object_project.py rename to python3/koans/about_proxy_object_project.py diff --git a/python 3/koans/about_regex.py b/python3/koans/about_regex.py similarity index 100% rename from python 3/koans/about_regex.py rename to python3/koans/about_regex.py diff --git a/python 3/koans/about_scope.py b/python3/koans/about_scope.py similarity index 100% rename from python 3/koans/about_scope.py rename to python3/koans/about_scope.py diff --git a/python 3/koans/about_scoring_project.py b/python3/koans/about_scoring_project.py similarity index 100% rename from python 3/koans/about_scoring_project.py rename to python3/koans/about_scoring_project.py diff --git a/python 3/koans/about_sets.py b/python3/koans/about_sets.py similarity index 100% rename from python 3/koans/about_sets.py rename to python3/koans/about_sets.py diff --git a/python 3/koans/about_strings.py b/python3/koans/about_strings.py similarity index 100% rename from python 3/koans/about_strings.py rename to python3/koans/about_strings.py diff --git a/python 3/koans/about_triangle_project.py b/python3/koans/about_triangle_project.py similarity index 100% rename from python 3/koans/about_triangle_project.py rename to python3/koans/about_triangle_project.py diff --git a/python 3/koans/about_triangle_project2.py b/python3/koans/about_triangle_project2.py similarity index 100% rename from python 3/koans/about_triangle_project2.py rename to python3/koans/about_triangle_project2.py diff --git a/python 3/koans/about_true_and_false.py b/python3/koans/about_true_and_false.py similarity index 100% rename from python 3/koans/about_true_and_false.py rename to python3/koans/about_true_and_false.py diff --git a/python 3/koans/about_tuples.py b/python3/koans/about_tuples.py similarity index 100% rename from python 3/koans/about_tuples.py rename to python3/koans/about_tuples.py diff --git a/python 3/koans/about_with_statements.py b/python3/koans/about_with_statements.py similarity index 100% rename from python 3/koans/about_with_statements.py rename to python3/koans/about_with_statements.py diff --git a/python 3/koans/another_local_module.py b/python3/koans/another_local_module.py similarity index 100% rename from python 3/koans/another_local_module.py rename to python3/koans/another_local_module.py diff --git a/python 3/koans/jims.py b/python3/koans/jims.py similarity index 100% rename from python 3/koans/jims.py rename to python3/koans/jims.py diff --git a/python 3/koans/joes.py b/python3/koans/joes.py similarity index 100% rename from python 3/koans/joes.py rename to python3/koans/joes.py diff --git a/python 3/koans/local_module.py b/python3/koans/local_module.py similarity index 100% rename from python 3/koans/local_module.py rename to python3/koans/local_module.py diff --git a/python 3/koans/local_module_with_all_defined.py b/python3/koans/local_module_with_all_defined.py similarity index 100% rename from python 3/koans/local_module_with_all_defined.py rename to python3/koans/local_module_with_all_defined.py diff --git a/python 3/koans/triangle.py b/python3/koans/triangle.py similarity index 100% rename from python 3/koans/triangle.py rename to python3/koans/triangle.py diff --git a/python 3/libs/__init__.py b/python3/libs/__init__.py similarity index 100% rename from python 3/libs/__init__.py rename to python3/libs/__init__.py diff --git a/python 3/libs/colorama/LICENSE-colorama b/python3/libs/colorama/LICENSE-colorama similarity index 100% rename from python 3/libs/colorama/LICENSE-colorama rename to python3/libs/colorama/LICENSE-colorama diff --git a/python 3/libs/colorama/__init__.py b/python3/libs/colorama/__init__.py similarity index 100% rename from python 3/libs/colorama/__init__.py rename to python3/libs/colorama/__init__.py diff --git a/python 3/libs/colorama/ansi.py b/python3/libs/colorama/ansi.py similarity index 100% rename from python 3/libs/colorama/ansi.py rename to python3/libs/colorama/ansi.py diff --git a/python 3/libs/colorama/ansitowin32.py b/python3/libs/colorama/ansitowin32.py similarity index 100% rename from python 3/libs/colorama/ansitowin32.py rename to python3/libs/colorama/ansitowin32.py diff --git a/python 3/libs/colorama/initialise.py b/python3/libs/colorama/initialise.py similarity index 100% rename from python 3/libs/colorama/initialise.py rename to python3/libs/colorama/initialise.py diff --git a/python 3/libs/colorama/win32.py b/python3/libs/colorama/win32.py similarity index 100% rename from python 3/libs/colorama/win32.py rename to python3/libs/colorama/win32.py diff --git a/python 3/libs/colorama/winterm.py b/python3/libs/colorama/winterm.py similarity index 100% rename from python 3/libs/colorama/winterm.py rename to python3/libs/colorama/winterm.py diff --git a/python 3/libs/mock.py b/python3/libs/mock.py similarity index 100% rename from python 3/libs/mock.py rename to python3/libs/mock.py diff --git a/python 3/run.bat b/python3/run.bat similarity index 100% rename from python 3/run.bat rename to python3/run.bat diff --git a/python 3/run.sh b/python3/run.sh similarity index 100% rename from python 3/run.sh rename to python3/run.sh diff --git a/python 3/runner/__init__.py b/python3/runner/__init__.py similarity index 100% rename from python 3/runner/__init__.py rename to python3/runner/__init__.py diff --git a/python 3/runner/helper.py b/python3/runner/helper.py similarity index 100% rename from python 3/runner/helper.py rename to python3/runner/helper.py diff --git a/python 3/runner/koan.py b/python3/runner/koan.py similarity index 100% rename from python 3/runner/koan.py rename to python3/runner/koan.py diff --git a/python 3/runner/mockable_test_result.py b/python3/runner/mockable_test_result.py similarity index 100% rename from python 3/runner/mockable_test_result.py rename to python3/runner/mockable_test_result.py diff --git a/python 3/runner/mountain.py b/python3/runner/mountain.py similarity index 100% rename from python 3/runner/mountain.py rename to python3/runner/mountain.py diff --git a/python 3/runner/path_to_enlightenment.py b/python3/runner/path_to_enlightenment.py similarity index 100% rename from python 3/runner/path_to_enlightenment.py rename to python3/runner/path_to_enlightenment.py diff --git a/python 3/runner/runner_tests/__init__.py b/python3/runner/runner_tests/__init__.py similarity index 100% rename from python 3/runner/runner_tests/__init__.py rename to python3/runner/runner_tests/__init__.py diff --git a/python 3/runner/runner_tests/test_helper.py b/python3/runner/runner_tests/test_helper.py similarity index 100% rename from python 3/runner/runner_tests/test_helper.py rename to python3/runner/runner_tests/test_helper.py diff --git a/python 3/runner/runner_tests/test_mountain.py b/python3/runner/runner_tests/test_mountain.py similarity index 100% rename from python 3/runner/runner_tests/test_mountain.py rename to python3/runner/runner_tests/test_mountain.py diff --git a/python 3/runner/runner_tests/test_sensei.py b/python3/runner/runner_tests/test_sensei.py similarity index 100% rename from python 3/runner/runner_tests/test_sensei.py rename to python3/runner/runner_tests/test_sensei.py diff --git a/python 3/runner/sensei.py b/python3/runner/sensei.py similarity index 100% rename from python 3/runner/sensei.py rename to python3/runner/sensei.py diff --git a/python 3/runner/writeln_decorator.py b/python3/runner/writeln_decorator.py similarity index 100% rename from python 3/runner/writeln_decorator.py rename to python3/runner/writeln_decorator.py From 431cb58bcb40f50232a046865c980cdf3de25e53 Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Fri, 27 Jul 2012 22:25:22 -0400 Subject: [PATCH 017/237] Do rst images work? --- README.rst | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 6c92e2dcf..1e634e935 100644 --- a/README.rst +++ b/README.rst @@ -4,6 +4,8 @@ Python Koans Python Koans is a port of Edgecase's "Ruby Koans". +.. image:: http://i442.photobucket.com/albums/qq150/gregmalcolm/PythonKoansScreenshot.png + Python Koans is an interactive tutorial for learning Python by making tests pass. Most tests are 'fixed' by filling the missing parts of assert functions. Eg: @@ -22,13 +24,13 @@ As well as being a great way to learn some Python, it is also a good way to get Downloading Python Koans ------------------------ -Python Koans is available through Mercurial on bitbucket: +Python Koans is available through git on Github: - http://bitbucket.org/gregmalcolm/python_koans + http://wiki.github.com/gregmalcolm/python_koans -It is also mirrored on github for Git users : +It is also mirrored on bitbucet for Mercurial users : - http://wiki.github.com/gregmalcolm/python_koans + http://bitbucket.org/gregmalcolm/python_koans Either site will allow you to download the source as a zip/gz/bz2. @@ -56,14 +58,17 @@ Getting Started From a *nix terminal or windows command prompt go to the python koans\python_VERSION folder and run: +:: python contemplate_koans.py or +:: python3 contemplate_koans.py In my case I'm using Python 3 with windows, so I fire up my command shell (cmd.exe) and run this: +:: C:\>cd "c:\hg\python_koans\python3" C:\hg\python_koans\python3>python contemplate_koans.py @@ -78,18 +83,19 @@ In my case I'm using Python 3 with windows, so I fire up my command shell (cmd.e assert_truth self.assertTrue(False) # This should be true - Beautiful is better than ugly. C:\hg\python_koans\python3> Apparently a test failed: +:: AssertionError: False is not True It also tells me exactly where the problem in, its an assert on line 12 of .\koans\about_asserts.py. This one is easy, just change False to True to make the test pass. Sooner or later you will likely encounter tests where you are not sure what the expected value should be. For example: +:: class Dog: pass @@ -99,6 +105,7 @@ Sooner or later you will likely encounter tests where you are not sure what the This is where the Python Command Line can come in handy. in this case I can fire up the command line, recreate the scenario and run queries: +:: C:\hg\python_koans\python3>python Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on win32 @@ -110,6 +117,7 @@ This is where the Python Command Line can come in handy. in this case I can fire True >>> + Getting the Most From the Koans ------------------------------- @@ -139,7 +147,6 @@ Acknowledgments Thanks go to Jim Weirich and Joe O'Brien for the original Ruby Koans that Python Koans is based on! Also the Ruby Koans in turn borrows from Metakoans so thanks also go to Ara Howard for that! - Also thanks to everyone who helped with the Python Koans conversion! In particular I got a great headstart on the project by forking from this Python Koans startup project: http://bitbucket.org/mcrute/python_koans/ From 80153984eeab400d0ed28cca1b4ea298650e4ccb Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Fri, 27 Jul 2012 22:32:04 -0400 Subject: [PATCH 018/237] Better... or worse? --- README.rst | 44 +++++++------------------------------------- 1 file changed, 7 insertions(+), 37 deletions(-) diff --git a/README.rst b/README.rst index 1e634e935..76e2e280c 100644 --- a/README.rst +++ b/README.rst @@ -26,7 +26,7 @@ Downloading Python Koans Python Koans is available through git on Github: - http://wiki.github.com/gregmalcolm/python_koans + http://github.com/gregmalcolm/python_koans It is also mirrored on bitbucet for Mercurial users : @@ -56,46 +56,26 @@ If you have problems, this may help: Getting Started --------------- -From a *nix terminal or windows command prompt go to the python koans\python_VERSION folder and run: +From a *nix terminal or windows command prompt go to the python koans\python_VERSION folder and run:: -:: python contemplate_koans.py -or +or:: -:: python3 contemplate_koans.py In my case I'm using Python 3 with windows, so I fire up my command shell (cmd.exe) and run this: -:: - C:\>cd "c:\hg\python_koans\python3" - C:\hg\python_koans\python3>python contemplate_koans.py - - Thinking AboutAsserts - test_assert_truth has damaged your karma. +.. image:: http://i442.photobucket.com/albums/qq150/gregmalcolm/GettingStarted.png - You have not yet reached enlightenment ... - AssertionError: False is not True +Apparently a test failed:: - Please meditate on the following code: - File "C:\hg\python_koans\python3\koans\about_asserts.py", line 12, in test_ - assert_truth - self.assertTrue(False) # This should be true - - Beautiful is better than ugly. - C:\hg\python_koans\python3> - -Apparently a test failed: - -:: AssertionError: False is not True It also tells me exactly where the problem in, its an assert on line 12 of .\koans\about_asserts.py. This one is easy, just change False to True to make the test pass. -Sooner or later you will likely encounter tests where you are not sure what the expected value should be. For example: +Sooner or later you will likely encounter tests where you are not sure what the expected value should be. For example:: -:: class Dog: pass @@ -105,17 +85,7 @@ Sooner or later you will likely encounter tests where you are not sure what the This is where the Python Command Line can come in handy. in this case I can fire up the command line, recreate the scenario and run queries: -:: - C:\hg\python_koans\python3>python - Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on - win32 - Type "help", "copyright", "credits" or "license" for more information. - >>> class Dog: pass - ... - >>> fido = Dog() - >>> isinstance(fido, object) - True - >>> +.. image:: http://i442.photobucket.com/albums/qq150/gregmalcolm/DebuggingPython.png Getting the Most From the Koans From 5bac40a112363ca077faa4c34080977b771019af Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Fri, 27 Jul 2012 22:37:36 -0400 Subject: [PATCH 019/237] Bitbucket, Y U No render Content paragraph properly? --- README.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 76e2e280c..ef1f017af 100644 --- a/README.rst +++ b/README.rst @@ -91,11 +91,10 @@ This is where the Python Command Line can come in handy. in this case I can fire Getting the Most From the Koans ------------------------------- -Quoting the Ruby Koans instructions: +Quoting the Ruby Koans instructions:: "In test-driven development the mantra has always been, red, green, refactor. Write a failing test and run it (red), make the test pass (green), then refactor it (that is look at the code and see if you can make it any better. In this case you will need to run the koan and see it fail (red), make the test pass (green), then take a moment and reflect upon the test to see what it is teaching you and improve the code to better communicate its intent (refactor)." - Content ------- From 018cf37254cd084bd9e60fd4cd2e727c1f716249 Mon Sep 17 00:00:00 2001 From: mikelietz Date: Sun, 29 Jul 2012 14:19:31 -0300 Subject: [PATCH 020/237] All the other 'world's are lowercased. --- python2/koans/about_strings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python2/koans/about_strings.py b/python2/koans/about_strings.py index d978c5c10..af8671b44 100644 --- a/python2/koans/about_strings.py +++ b/python2/koans/about_strings.py @@ -64,7 +64,7 @@ def test_plus_concatenates_strings(self): self.assertEqual(__, string) def test_adjacent_strings_are_concatenated_automatically(self): - string = "Hello" ", " "World" + string = "Hello" ", " "world" self.assertEqual(__, string) def test_plus_will_not_modify_original_strings(self): From 73ab6d2576ccecbd2cf8f229e00937bd60cb1d37 Mon Sep 17 00:00:00 2001 From: Boyan Alexandrov Date: Sun, 29 Jul 2012 13:23:59 -0400 Subject: [PATCH 021/237] enclose string literals of dictionary values with single quotes for consistency --- python2/koans/about_dictionaries.py | 26 +++++++++++++------------- python3/koans/about_dictionaries.py | 24 ++++++++++++------------ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/python2/koans/about_dictionaries.py b/python2/koans/about_dictionaries.py index e2ba91637..49ac268da 100644 --- a/python2/koans/about_dictionaries.py +++ b/python2/koans/about_dictionaries.py @@ -18,36 +18,36 @@ def test_creating_dictionaries(self): def test_dictionary_literals(self): empty_dict = {} self.assertEqual(dict, type(empty_dict)) - babel_fish = {'one': "uno", 'two': "dos"} + babel_fish = {'one': 'uno', 'two': 'dos'} self.assertEqual(__, len(babel_fish)) def test_accessing_dictionaries(self): - babel_fish = {'one': "uno", 'two': "dos"} + babel_fish = {'one': 'uno', 'two': 'dos'} self.assertEqual(__, babel_fish['one']) self.assertEqual(__, 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': __} self.assertEqual(expected, babel_fish) def test_dictionary_is_unordered(self): - dict1 = {'one': "uno", 'two': "dos"} - dict2 = {'two': "dos", 'one': "uno"} + dict1 = {'one': 'uno', 'two': 'dos'} + dict2 = {'two': 'dos', 'one': 'uno'} self.assertEqual(____, dict1 == dict2) def test_dictionary_keys(self): - babel_fish = {'one': "uno", 'two': "dos"} + babel_fish = {'one': 'uno', 'two': 'dos'} self.assertEqual(__, len(babel_fish.keys())) self.assertEqual(__, 'one' in babel_fish) self.assertEqual(__, 'two' in babel_fish) self.assertEqual(list, babel_fish.keys().__class__) def test_dictionary_values(self): - babel_fish = {'one': "uno", 'two': "dos"} + babel_fish = {'one': 'uno', 'two': 'dos'} self.assertEqual(__, len(babel_fish.values())) self.assertEqual(__, 'uno' in babel_fish.values()) self.assertEqual(__, 'dos' in babel_fish.values()) @@ -55,10 +55,10 @@ def test_dictionary_values(self): def test_making_a_dictionary_from_a_sequence_of_keys(self): cards = {}.fromkeys( - ("red warrior", "green elf", "blue valkyrie", "yellow dwarf", - "confused looking zebra"), + ('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"]) + self.assertEqual(__, cards['green elf']) + self.assertEqual(__, cards['yellow dwarf']) diff --git a/python3/koans/about_dictionaries.py b/python3/koans/about_dictionaries.py index 01995e168..bfafcafb6 100644 --- a/python3/koans/about_dictionaries.py +++ b/python3/koans/about_dictionaries.py @@ -17,45 +17,45 @@ def test_creating_dictionaries(self): def test_dictionary_literals(self): empty_dict = {} self.assertEqual(dict, type(empty_dict)) - babel_fish = { 'one': "uno", 'two': "dos" } + babel_fish = { 'one': 'uno', 'two': 'dos' } self.assertEqual(__, len(babel_fish)) def test_accessing_dictionaries(self): - babel_fish = { 'one': "uno", 'two': "dos" } + babel_fish = { 'one': 'uno', 'two': 'dos' } self.assertEqual(__, babel_fish['one']) self.assertEqual(__, 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': __ } self.assertDictEqual(expected, babel_fish) def test_dictionary_is_unordered(self): - dict1 = { 'one': "uno", 'two': "dos" } - dict2 = { 'two': "dos", 'one': "uno" } + dict1 = { 'one': 'uno', 'two': 'dos' } + dict2 = { 'two': 'dos', 'one': 'uno' } self.assertEqual(__, dict1 == dict2) def test_dictionary_keys(self): - babel_fish = { 'one': "uno", 'two': "dos" } + babel_fish = { 'one': 'uno', 'two': 'dos' } self.assertEqual(__, len(babel_fish.keys())) self.assertEqual(__, 'one' in babel_fish) self.assertEqual(__, 'two' in babel_fish) self.assertEqual('dict_keys', babel_fish.keys().__class__.__name__) def test_dictionary_values(self): - babel_fish = { 'one': "uno", 'two': "dos" } + babel_fish = { 'one': 'uno', 'two': 'dos' } self.assertEqual(__, len(babel_fish.values())) self.assertEqual(__, 'uno' in babel_fish.values()) self.assertEqual(__, 'dos' in babel_fish.values()) self.assertEqual('dict_values', babel_fish.values().__class__.__name__) 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) + 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"]) + self.assertEqual(__, cards['green elf']) + self.assertEqual(__, cards['yellow dwarf']) From d60690a64a296fa859cade1f57c82de6b16ae03c Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Sun, 29 Jul 2012 13:33:36 -0400 Subject: [PATCH 022/237] Do same for python3 flavor --- python3/koans/about_strings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python3/koans/about_strings.py b/python3/koans/about_strings.py index 8e60cf290..3b85eebdb 100644 --- a/python3/koans/about_strings.py +++ b/python3/koans/about_strings.py @@ -63,7 +63,7 @@ def test_plus_concatenates_strings(self): self.assertEqual(__, string) def test_adjacent_strings_are_concatenated_automatically(self): - string = "Hello" ", " "World" + string = "Hello" ", " "world" self.assertEqual(__, string) def test_plus_will_not_modify_original_strings(self): From a6d699798107c2ff637990ca000ad5b4cbf17a21 Mon Sep 17 00:00:00 2001 From: Aaron Baker Date: Sun, 29 Jul 2012 13:54:04 -0400 Subject: [PATCH 023/237] changed about_dictionaries.py to combine keys and values to one test to more easily show the difference between keys and values --- python2/koans/about_dictionaries.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/python2/koans/about_dictionaries.py b/python2/koans/about_dictionaries.py index 49ac268da..320212f34 100644 --- a/python2/koans/about_dictionaries.py +++ b/python2/koans/about_dictionaries.py @@ -39,20 +39,17 @@ def test_dictionary_is_unordered(self): self.assertEqual(____, dict1 == dict2) - def test_dictionary_keys(self): + def test_dictionary_keys_and_values(self): babel_fish = {'one': 'uno', 'two': 'dos'} self.assertEqual(__, len(babel_fish.keys())) - self.assertEqual(__, 'one' in babel_fish) - self.assertEqual(__, 'two' in babel_fish) - self.assertEqual(list, babel_fish.keys().__class__) - - def test_dictionary_values(self): - babel_fish = {'one': 'uno', 'two': 'dos'} self.assertEqual(__, len(babel_fish.values())) - self.assertEqual(__, 'uno' in 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()) + self.assertEqual(list, babel_fish.keys().__class__) self.assertEqual(list, babel_fish.values().__class__) - + def test_making_a_dictionary_from_a_sequence_of_keys(self): cards = {}.fromkeys( ('red warrior', 'green elf', 'blue valkyrie', 'yellow dwarf', From 6c4eb824b8f6d375798313dd11f3489cb5fba785 Mon Sep 17 00:00:00 2001 From: Aaron Baker Date: Sun, 29 Jul 2012 14:05:26 -0400 Subject: [PATCH 024/237] changed python2 and python3 about_dictionaries.py to better explain the difference between values and keys in dictionaries --- python2/koans/about_dictionaries.py | 2 ++ python3/koans/about_dictionaries.py | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/python2/koans/about_dictionaries.py b/python2/koans/about_dictionaries.py index 320212f34..ef1c136d9 100644 --- a/python2/koans/about_dictionaries.py +++ b/python2/koans/about_dictionaries.py @@ -48,7 +48,9 @@ def test_dictionary_keys_and_values(self): self.assertEqual(__, 'uno' in babel_fish.keys()) self.assertEqual(__, 'dos' in babel_fish.values()) self.assertEqual(list, babel_fish.keys().__class__) + self.assertEqual('dict_keys', babel_fish.keys().__class__.__name__) self.assertEqual(list, babel_fish.values().__class__) + self.assertEqual('dict_values', babel_fish.values().__class__.__name__) def test_making_a_dictionary_from_a_sequence_of_keys(self): cards = {}.fromkeys( diff --git a/python3/koans/about_dictionaries.py b/python3/koans/about_dictionaries.py index bfafcafb6..051fa9be2 100644 --- a/python3/koans/about_dictionaries.py +++ b/python3/koans/about_dictionaries.py @@ -38,20 +38,20 @@ def test_dictionary_is_unordered(self): self.assertEqual(__, dict1 == dict2) - def test_dictionary_keys(self): - babel_fish = { 'one': 'uno', 'two': 'dos' } + + def test_dictionary_keys_and_values(self): + babel_fish = {'one': 'uno', 'two': 'dos'} self.assertEqual(__, len(babel_fish.keys())) - self.assertEqual(__, 'one' in babel_fish) - self.assertEqual(__, 'two' in babel_fish) - self.assertEqual('dict_keys', babel_fish.keys().__class__.__name__) - - def test_dictionary_values(self): - babel_fish = { 'one': 'uno', 'two': 'dos' } self.assertEqual(__, len(babel_fish.values())) - self.assertEqual(__, 'uno' in 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()) + self.assertEqual(list, babel_fish.keys().__class__) + self.assertEqual('dict_keys', babel_fish.keys().__class__.__name__) + self.assertEqual(lis, babel_fish.values().__class__) self.assertEqual('dict_values', babel_fish.values().__class__.__name__) - + 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) From ef36871e685a542aa28a1c75e44d92320c4cd397 Mon Sep 17 00:00:00 2001 From: mikelietz Date: Sun, 29 Jul 2012 14:21:42 -0400 Subject: [PATCH 025/237] Call 'a' global method, not 'an' global method. Python3 had it right. --- python2/koans/about_methods.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python2/koans/about_methods.py b/python2/koans/about_methods.py index 7279d8c2a..39da18065 100644 --- a/python2/koans/about_methods.py +++ b/python2/koans/about_methods.py @@ -13,7 +13,7 @@ def my_global_function(a, b): class AboutMethods(Koan): - def test_calling_an_global_function(self): + def test_calling_a_global_function(self): self.assertEqual(__, my_global_function(2, 3)) # NOTE: Wrong number of arguments is not a SYNTAX error, but a From 20811df0e6e12d04c51c0a800fb0729463c8a91e Mon Sep 17 00:00:00 2001 From: mikelietz Date: Sun, 29 Jul 2012 14:43:55 -0400 Subject: [PATCH 026/237] A one line method should be one line, right? Python3 had it right. --- python2/koans/about_methods.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python2/koans/about_methods.py b/python2/koans/about_methods.py index 39da18065..173cd0ce3 100644 --- a/python2/koans/about_methods.py +++ b/python2/koans/about_methods.py @@ -113,8 +113,7 @@ def test_pass_does_nothing_at_all(self): # ------------------------------------------------------------------ - 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()) From 9316cec757aa262a4180bf775952cb97913cfa5c Mon Sep 17 00:00:00 2001 From: mikelietz Date: Sun, 29 Jul 2012 14:48:00 -0400 Subject: [PATCH 027/237] A one line method should be one line, right? Python3 had it right. --- python2/koans/about_methods.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python2/koans/about_methods.py b/python2/koans/about_methods.py index 7279d8c2a..65fa8b06f 100644 --- a/python2/koans/about_methods.py +++ b/python2/koans/about_methods.py @@ -113,8 +113,7 @@ def test_pass_does_nothing_at_all(self): # ------------------------------------------------------------------ - 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()) From 6f562204298a932a7d8f059b1b68bdaf74732b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Ezequiel=20Gutierrez=20=C3=81lvarez?= Date: Thu, 2 Aug 2012 23:23:38 -0500 Subject: [PATCH 028/237] Fixing syntax error: equivelant -> equivalent --- python2/koans/about_generators.py | 4 ++-- python3/koans/about_generators.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python2/koans/about_generators.py b/python2/koans/about_generators.py index cb32a50ec..dd31b91f9 100644 --- a/python2/koans/about_generators.py +++ b/python2/koans/about_generators.py @@ -133,9 +133,9 @@ def test_generators_can_see_if_they_have_been_called_with_a_value(self): next(generator2) self.assertEqual(__, next(generator2)) - def test_send_none_is_equivelant_to_next(self): + def test_send_none_is_equivalent_to_next(self): generator = self.yield_tester() next(generator) - # 'next(generator)' is exactly equivelant to 'generator.send(None)' + # 'next(generator)' is exactly equivalent to 'generator.send(None)' self.assertEqual(__, generator.send(None)) diff --git a/python3/koans/about_generators.py b/python3/koans/about_generators.py index 244ea1e6b..5986cf1fa 100644 --- a/python3/koans/about_generators.py +++ b/python3/koans/about_generators.py @@ -136,11 +136,11 @@ def test_generators_can_see_if_they_have_been_called_with_a_value(self): next(generator2) self.assertEqual(__, next(generator2)) - def test_send_none_is_equivelant_to_next(self): + def test_send_none_is_equivalent_to_next(self): generator = self.yield_tester() next(generator) - # 'next(generator)' is exactly equivelant to 'generator.send(None)' + # 'next(generator)' is exactly equivalent to 'generator.send(None)' self.assertEqual(__, generator.send(None)) From 3f3c31975762a3a7ea6d83a453921ea0b65024a9 Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Mon, 6 Aug 2012 15:12:19 -0400 Subject: [PATCH 029/237] Removed some confusing tests in about_dictionaries --- python2/koans/about_dictionaries.py | 4 ---- python3/koans/about_dictionaries.py | 4 ---- 2 files changed, 8 deletions(-) diff --git a/python2/koans/about_dictionaries.py b/python2/koans/about_dictionaries.py index ef1c136d9..518ea54bf 100644 --- a/python2/koans/about_dictionaries.py +++ b/python2/koans/about_dictionaries.py @@ -47,10 +47,6 @@ def test_dictionary_keys_and_values(self): self.assertEqual(__, 'two' in babel_fish.values()) self.assertEqual(__, 'uno' in babel_fish.keys()) self.assertEqual(__, 'dos' in babel_fish.values()) - self.assertEqual(list, babel_fish.keys().__class__) - self.assertEqual('dict_keys', babel_fish.keys().__class__.__name__) - self.assertEqual(list, babel_fish.values().__class__) - self.assertEqual('dict_values', babel_fish.values().__class__.__name__) def test_making_a_dictionary_from_a_sequence_of_keys(self): cards = {}.fromkeys( diff --git a/python3/koans/about_dictionaries.py b/python3/koans/about_dictionaries.py index 051fa9be2..0ef64cf84 100644 --- a/python3/koans/about_dictionaries.py +++ b/python3/koans/about_dictionaries.py @@ -47,10 +47,6 @@ def test_dictionary_keys_and_values(self): self.assertEqual(__, 'two' in babel_fish.values()) self.assertEqual(__, 'uno' in babel_fish.keys()) self.assertEqual(__, 'dos' in babel_fish.values()) - self.assertEqual(list, babel_fish.keys().__class__) - self.assertEqual('dict_keys', babel_fish.keys().__class__.__name__) - self.assertEqual(lis, babel_fish.values().__class__) - self.assertEqual('dict_values', babel_fish.values().__class__.__name__) 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) From 654a80f185d7fd171e9a06f220c15b3a3944d0ff Mon Sep 17 00:00:00 2001 From: Mechanical snail Date: Sat, 11 Aug 2012 04:58:49 +0000 Subject: [PATCH 030/237] Fix punctuation error in comment `it's` -> `its` --- python2/koans/about_proxy_object_project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python2/koans/about_proxy_object_project.py b/python2/koans/about_proxy_object_project.py index 27b89363f..2fe65a6c8 100644 --- a/python2/koans/about_proxy_object_project.py +++ b/python2/koans/about_proxy_object_project.py @@ -13,7 +13,7 @@ # missing handler and any other supporting methods. The specification # of the Proxy class is given in the AboutProxyObjectProject koan. -# Note: This is a bit trickier that it's Ruby Koans counterpart, but you +# Note: This is a bit trickier that its Ruby Koans counterpart, but you # can do it! from runner.koan import * From d4a0ab9eb4a685e728b2f84953931ad007a793b8 Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 18 Sep 2012 15:10:00 -0300 Subject: [PATCH 031/237] Update python2/koans/about_proxy_object_project.py Editing the tests so that they check for the 'channel' string instead of the 'channel=' string. This is more consistent with Python functionality and the '=' sign is unnecessary in the test unlike in the ruby koans. --- python2/koans/about_proxy_object_project.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python2/koans/about_proxy_object_project.py b/python2/koans/about_proxy_object_project.py index 27b89363f..7eb93fd69 100644 --- a/python2/koans/about_proxy_object_project.py +++ b/python2/koans/about_proxy_object_project.py @@ -53,7 +53,7 @@ def test_proxy_records_messages_sent_to_tv(self): tv.power() tv.channel = 10 - self.assertEqual(['power', 'channel='], tv.messages()) + self.assertEqual(['power', 'channel'], tv.messages()) def test_proxy_handles_invalid_messages(self): tv = Proxy(Television()) @@ -83,7 +83,7 @@ def test_proxy_counts_method_calls(self): tv.power() self.assertEqual(2, tv.number_of_times_called('power')) - self.assertEqual(1, tv.number_of_times_called('channel=')) + self.assertEqual(1, tv.number_of_times_called('channel')) self.assertEqual(0, tv.number_of_times_called('is_on')) def test_proxy_can_record_more_than_just_tv_objects(self): From 2e66e539e0f97a1112fe08512c70fc71eea9c43f Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 19 Sep 2012 01:37:48 -0300 Subject: [PATCH 032/237] Update python3/koans/about_proxy_object_project.py --- python3/koans/about_proxy_object_project.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python3/koans/about_proxy_object_project.py b/python3/koans/about_proxy_object_project.py index e1dd6f024..ef8a8c06b 100644 --- a/python3/koans/about_proxy_object_project.py +++ b/python3/koans/about_proxy_object_project.py @@ -51,7 +51,7 @@ def test_proxy_records_messages_sent_to_tv(self): tv.power() tv.channel = 10 - self.assertEqual(['power', 'channel='], tv.messages()) + self.assertEqual(['power', 'channel'], tv.messages()) def test_proxy_handles_invalid_messages(self): tv = Proxy(Television()) @@ -78,7 +78,7 @@ def test_proxy_counts_method_calls(self): tv.power() self.assertEqual(2, tv.number_of_times_called('power')) - self.assertEqual(1, tv.number_of_times_called('channel=')) + self.assertEqual(1, tv.number_of_times_called('channel')) self.assertEqual(0, tv.number_of_times_called('is_on')) def test_proxy_can_record_more_than_just_tv_objects(self): From 137647226d157f75605e9feab523255179f6602b Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Wed, 19 Sep 2012 07:26:44 -0400 Subject: [PATCH 033/237] Accepting the grammar advice of snails --- python3/koans/about_proxy_object_project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python3/koans/about_proxy_object_project.py b/python3/koans/about_proxy_object_project.py index ef8a8c06b..bb5c45620 100644 --- a/python3/koans/about_proxy_object_project.py +++ b/python3/koans/about_proxy_object_project.py @@ -13,7 +13,7 @@ # missing handler and any other supporting methods. The specification # of the Proxy class is given in the AboutProxyObjectProject koan. -# Note: This is a bit trickier that it's Ruby Koans counterpart, but you +# Note: This is a bit trickier that its Ruby Koans counterpart, but you # can do it! from runner.koan import * From 3560b055feabdb1ea5d10bbc2cc91e052215dfb0 Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Wed, 19 Sep 2012 07:45:37 -0400 Subject: [PATCH 034/237] Added screencast info --- README.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index ef1f017af..5969e6daf 100644 --- a/README.rst +++ b/README.rst @@ -56,7 +56,14 @@ If you have problems, this may help: Getting Started --------------- -From a *nix terminal or windows command prompt go to the python koans\python_VERSION folder and run:: +Jake Hebbert has created a couple of screencasts available here: + +.. "Getting started using Python Koans": http://vimeo.com/48330033 +.. "Python Koans about_asserts.py": http://vimeo.com/48387395 + +Or if you prefer to read: + +From a *nix terminal or windows command prompt go to the python koans\python_**VERSION** folder and run:: python contemplate_koans.py From a357cde58c643ded21e444d1511dacd7d339b3c2 Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Wed, 19 Sep 2012 07:47:35 -0400 Subject: [PATCH 035/237] Trying again --- README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 5969e6daf..f06e58c34 100644 --- a/README.rst +++ b/README.rst @@ -58,12 +58,12 @@ Getting Started Jake Hebbert has created a couple of screencasts available here: -.. "Getting started using Python Koans": http://vimeo.com/48330033 -.. "Python Koans about_asserts.py": http://vimeo.com/48387395 +.. _Getting started using Python Koans: http://vimeo.com/48330033 +.. _Python Koans about_asserts.py: http://vimeo.com/48387395 Or if you prefer to read: -From a *nix terminal or windows command prompt go to the python koans\python_**VERSION** folder and run:: +From a *nix terminal or windows command prompt go to the python koans\python_VERSION folder and run:: python contemplate_koans.py From 8f533da9b8161c39a68c0ac6ab6beb4810b69625 Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Wed, 19 Sep 2012 07:52:07 -0400 Subject: [PATCH 036/237] and again... --- README.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index f06e58c34..bdaa21ca1 100644 --- a/README.rst +++ b/README.rst @@ -58,8 +58,11 @@ Getting Started Jake Hebbert has created a couple of screencasts available here: -.. _Getting started using Python Koans: http://vimeo.com/48330033 -.. _Python Koans about_asserts.py: http://vimeo.com/48387395 + `Getting started using Python Koan` _vimeo_getting_started + `Python Koans about_asserts.py` _vimeo_about_asserts + +.. _vimeo_getting_started: http://vimeo.com/48330033 +.. _vimeo_about_asserts: http://vimeo.com/48387395 Or if you prefer to read: From f4f699355e2e12d05cd778ddd2d8f0df8fef9ac2 Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Wed, 19 Sep 2012 07:55:13 -0400 Subject: [PATCH 037/237] and again... --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index bdaa21ca1..d996726ad 100644 --- a/README.rst +++ b/README.rst @@ -58,8 +58,8 @@ Getting Started Jake Hebbert has created a couple of screencasts available here: - `Getting started using Python Koan` _vimeo_getting_started - `Python Koans about_asserts.py` _vimeo_about_asserts + `Getting started using Python Koan`_vimeo_getting_started + `Python Koans about_asserts.py`_vimeo_about_asserts .. _vimeo_getting_started: http://vimeo.com/48330033 .. _vimeo_about_asserts: http://vimeo.com/48387395 From 13c876f02f753a46fbbf8f317ede069ed557dfe1 Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Wed, 19 Sep 2012 07:56:16 -0400 Subject: [PATCH 038/237] and again... --- README.rst | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index d996726ad..8560f5607 100644 --- a/README.rst +++ b/README.rst @@ -58,11 +58,8 @@ Getting Started Jake Hebbert has created a couple of screencasts available here: - `Getting started using Python Koan`_vimeo_getting_started - `Python Koans about_asserts.py`_vimeo_about_asserts - -.. _vimeo_getting_started: http://vimeo.com/48330033 -.. _vimeo_about_asserts: http://vimeo.com/48387395 + http://vimeo.com/48330033 + http://vimeo.com/48387395 Or if you prefer to read: From 5dc46fe17008e540848a7eeff33d380b3259358c Mon Sep 17 00:00:00 2001 From: gregmalcolm Date: Wed, 19 Sep 2012 07:56:57 -0400 Subject: [PATCH 039/237] and finally? --- README.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 8560f5607..ecb6c3bd5 100644 --- a/README.rst +++ b/README.rst @@ -58,8 +58,9 @@ Getting Started Jake Hebbert has created a couple of screencasts available here: - http://vimeo.com/48330033 - http://vimeo.com/48387395 +http://vimeo.com/48330033 + +http://vimeo.com/48387395 Or if you prefer to read: From 6ae4ca21b18450d642d70f6684141e3b765ac82f Mon Sep 17 00:00:00 2001 From: Ymbirtt Date: Sat, 27 Oct 2012 21:39:49 +0200 Subject: [PATCH 040/237] Change sets for set operators to be more intuitive Using actual people for these sets makes it much clearer what the -, |, & and ^ symbols actually mean. --- python2/koans/about_sets.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/python2/koans/about_sets.py b/python2/koans/about_sets.py index 277cd1c46..c10e6123c 100644 --- a/python2/koans/about_sets.py +++ b/python2/koans/about_sets.py @@ -21,17 +21,14 @@ def test_convert_the_set_into_a_list_to_sort_it(self): # ------------------------------------------------------------------ - def chars_in(self, a_set): - return ''.join(sorted(a_set)) - def test_set_have_arithmetic_operators(self): - good_guy = set('macleod') - bad_guy = set('mutunas') - - self.assertEqual(__, self.chars_in(good_guy - bad_guy)) - self.assertEqual(__, self.chars_in(good_guy | bad_guy)) - self.assertEqual(__, self.chars_in(good_guy & bad_guy)) - self.assertEqual(__, self.chars_in(good_guy ^ bad_guy)) + scotsmen = set(["MacLeod","Wallace","Willie