diff --git a/python2/koans/about_classes.py b/python2/koans/about_classes.py index 7b82e60d1..b36494a65 100644 --- a/python2/koans/about_classes.py +++ b/python2/koans/about_classes.py @@ -10,10 +10,10 @@ class Dog(object): def test_instances_of_classes_can_be_created_adding_parentheses(self): fido = self.Dog() - self.assertEqual(__, fido.__class__.__name__) + self.assertEqual('Dog', fido.__class__.__name__) def test_classes_have_docstrings(self): - self.assertMatch(__, self.Dog.__doc__) + self.assertMatch("Dogs need regular walkies. Never, ever let them drive.", self.Dog.__doc__) # ------------------------------------------------------------------ @@ -26,12 +26,12 @@ def set_name(self, a_name): def test_init_method_is_the_constructor(self): dog = self.Dog2() - self.assertEqual(__, dog._name) + self.assertEqual('Paul', dog._name) def test_private_attributes_are_not_really_private(self): dog = self.Dog2() dog.set_name("Fido") - self.assertEqual(__, dog._name) + self.assertEqual("Fido", dog._name) # The _ prefix in _name implies private ownership, but nothing is truly # private in Python. @@ -39,11 +39,11 @@ 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")) + self.assertEqual('Fido', 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"]) + self.assertEqual('Fido', 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. @@ -62,12 +62,14 @@ def get_name(self): name = property(get_name, set_name) +#Comment: I'm not that sure on how property works + 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', fido.get_name()) # access as method + self.assertEqual('Fido', fido.name) # access as property # ------------------------------------------------------------------ @@ -87,7 +89,7 @@ def test_creating_properties_with_decorators_is_slightly_easier(self): fido = self.Dog4() fido.name = "Fido" - self.assertEqual(__, fido.name) + self.assertEqual('Fido', fido.name) # ------------------------------------------------------------------ @@ -101,19 +103,21 @@ def name(self): def test_init_provides_initial_values_for_instance_variables(self): fido = self.Dog5("Fido") - self.assertEqual(__, fido.name) + self.assertEqual("Fido", fido.name) def test_args_must_match_init(self): - self.assertRaises(___, self.Dog5) # Evaluates self.Dog5() + self.assertRaises(TypeError, self.Dog5) # Evaluates self.Dog5() # THINK ABOUT IT: # Why is this so? + + #Class initialization expects 2 arguments and only gets 1 (self) def test_different_objects_have_different_instance_variables(self): fido = self.Dog5("Fido") rover = self.Dog5("Rover") - self.assertEqual(____, rover.name == fido.name) + self.assertEqual(False, rover.name == fido.name) # ------------------------------------------------------------------ @@ -125,10 +129,8 @@ def get_self(self): return self def __str__(self): - # - # Implement this! - # - return __ + name = str(self._name) + return name def __repr__(self): return "" @@ -136,7 +138,7 @@ def __repr__(self): 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, fido.get_self()) # Not a string! def test_str_provides_a_string_version_of_the_object(self): fido = self.Dog6("Fido") @@ -144,17 +146,19 @@ def test_str_provides_a_string_version_of_the_object(self): def test_str_is_used_explicitly_in_string_interpolation(self): fido = self.Dog6("Fido") - self.assertEqual(__, "My dog is " + str(fido)) + self.assertEqual("My dog is Fido", "My dog is " + str(fido)) def test_repr_provides_a_more_complete_string_version(self): fido = self.Dog6("Fido") - self.assertEqual(__, repr(fido)) + self.assertEqual("", repr(fido)) def test_all_objects_support_str_and_repr(self): seq = [1, 2, 3] - self.assertEqual(__, str(seq)) - self.assertEqual(__, repr(seq)) + self.assertEqual('[1, 2, 3]', str(seq)) + self.assertEqual('[1, 2, 3]', repr(seq)) + + self.assertEqual('STRING', str("STRING")) + self.assertEqual("'STRING'", repr("STRING")) - self.assertEqual(__, str("STRING")) - self.assertEqual(__, repr("STRING")) +#In the last one I'm not sure why the "" appears twice \ No newline at end of file