Skip to content

Commit ca7f7ac

Browse files
kjcmpirnat
authored andcommitted
about_modules.py: Copy old Python 2 fixes to Python 3 version. (gregmalcolm#144)
* about_modules: Py3 now mostly matches Py2 version. Ported changes made to the Python 2 version of about_modules.py (sha d65e690, 2012-02-10) to the Python 3 version. They are now identical, except that the Python 3 version... 1. ...uses the new relative import syntax. 2. ...uses with-assertRaises(): instead of try-except. This changed one test name, but otherwise only comments and docstrings. * about_modules: Renamed test about __all__. In Python 2 and 3 versions, renamed the test method test_a_modules_XallX_statement_limits_what_wildcards_will_match to test_a_module_can_limit_wildcard_imports. Also, reformatted its docstring to put the Python code on its own line.
1 parent 66fa621 commit ca7f7ac

2 files changed

Lines changed: 24 additions & 15 deletions

File tree

python2/koans/about_modules.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ def test_private_attributes_are_still_accessible_in_modules(self):
6060
# module level attribute hiding doesn't affect class attributes
6161
# (unless the class itself is hidden).
6262

63-
def test_a_modules_XallX_statement_limits_what_wildcards_will_match(self):
64-
"""Examine results of from local_module_with_all_defined import *"""
63+
def test_a_module_can_limit_wildcard_imports(self):
64+
"""
65+
Examine results of:
66+
from local_module_with_all_defined import *
67+
"""
6568

6669
# 'Goat' is on the __all__ list
6770
goat = Goat()

python3/koans/about_modules.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@
1111
from .another_local_module import *
1212
from .local_module_with_all_defined import *
1313

14+
1415
class AboutModules(Koan):
1516
def test_importing_other_python_scripts_as_modules(self):
16-
from . import local_module # local_module.py
17+
from . import local_module # local_module.py
1718

1819
duck = local_module.Duck()
1920
self.assertEqual(__, duck.name)
2021

2122
def test_importing_attributes_from_classes_using_from_keyword(self):
2223
from .local_module import Duck
2324

24-
duck = Duck() # no module qualifier needed this time
25+
duck = Duck() # no module qualifier needed this time
2526
self.assertEqual(__, duck.name)
2627

2728
def test_we_can_import_multiple_items_at_once(self):
@@ -33,10 +34,11 @@ def test_we_can_import_multiple_items_at_once(self):
3334
self.assertEqual(__, joes_dog.identify())
3435

3536
def test_importing_all_module_attributes_at_once(self):
36-
# NOTE Using this module level import declared at the top of this script:
37-
# from .another_local_module import *
38-
#
39-
# Import wildcard cannot be used from within classes or functions
37+
"""
38+
importing all attributes at once is done like so:
39+
from .another_local_module import *
40+
The import wildcard cannot be used from within classes or functions.
41+
"""
4042

4143
goose = Goose()
4244
hamster = Hamster()
@@ -45,21 +47,24 @@ def test_importing_all_module_attributes_at_once(self):
4547
self.assertEqual(__, hamster.name)
4648

4749
def test_modules_hide_attributes_prefixed_by_underscores(self):
48-
with self.assertRaises(___): private_squirrel = _SecretSquirrel()
50+
with self.assertRaises(___):
51+
private_squirrel = _SecretSquirrel()
4952

5053
def test_private_attributes_are_still_accessible_in_modules(self):
51-
from .local_module import Duck # local_module.py
54+
from .local_module import Duck # local_module.py
5255

5356
duck = Duck()
5457
self.assertEqual(__, duck._password)
5558
# module level attribute hiding doesn't affect class attributes
5659
# (unless the class itself is hidden).
5760

58-
def test_a_module_can_choose_which_attributes_are_available_to_wildcards(self):
59-
# NOTE Using this module level import declared at the top of this script:
60-
# from .local_module_with_all_defined import *
61+
def test_a_module_can_limit_wildcard_imports(self):
62+
"""
63+
Examine results of:
64+
from .local_module_with_all_defined import *
65+
"""
6166

62-
# 'Goat' is on the __ALL__ list
67+
# 'Goat' is on the __all__ list
6368
goat = Goat()
6469
self.assertEqual(__, goat.name)
6570

@@ -68,4 +73,5 @@ def test_a_module_can_choose_which_attributes_are_available_to_wildcards(self):
6873
self.assertEqual(__, lizard.name)
6974

7075
# SecretDuck? Never heard of her!
71-
with self.assertRaises(___): duck = SecretDuck()
76+
with self.assertRaises(___):
77+
duck = SecretDuck()

0 commit comments

Comments
 (0)