# HG changeset patch # User Paul Boddie # Date 1341348201 -7200 # Node ID 0870065a77d4d06e69de2fa93294c96f925d6f01 # Parent 4e12df5e596541c8a233009436bcad89515db5b1 Added a test of external modification of a module during initialisation. diff -r 4e12df5e5965 -r 0870065a77d4 tests/changed2/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/changed2/__init__.py Tue Jul 03 22:43:21 2012 +0200 @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +def f(): + import changed2.modifier + +def getx(): + return x + +x = 123 +f() # import modifier which changes x in this module + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 4e12df5e5965 -r 0870065a77d4 tests/changed2/modifier.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/changed2/modifier.py Tue Jul 03 22:43:21 2012 +0200 @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +import changed2 # access the package root + +def change(): + + "Change x in the partially imported module." + + changed2.x = 456 + +change() + +# Attempt to confuse the identity of changed2 for the function. + +changed2 = None + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 4e12df5e5965 -r 0870065a77d4 tests/changed_globals2.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/changed_globals2.py Tue Jul 03 22:43:21 2012 +0200 @@ -0,0 +1,8 @@ +#!/usr/bin/env python + +import changed2 + +result1_456 = changed2.x +result2_456 = changed2.getx() + +# vim: tabstop=4 expandtab shiftwidth=4