diff options
author | Christian Heimes <christian@cheimes.de> | 2008-01-07 20:12:44 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-01-07 20:12:44 (GMT) |
commit | 3b06e5378ae21572a024b6484176b9678100ee53 (patch) | |
tree | d56a47c4e63a72ca999bf09c53093dcba3820b85 /Lib | |
parent | a38f73b1bb327ceb1aad3a3001255ab81da91c22 (diff) | |
download | cpython-3b06e5378ae21572a024b6484176b9678100ee53.zip cpython-3b06e5378ae21572a024b6484176b9678100ee53.tar.gz cpython-3b06e5378ae21572a024b6484176b9678100ee53.tar.bz2 |
Another patch for #1762972: __file__ points to the py file instead pyo/pyc file
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_import.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index 6c9e0b0..760713e 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -1,4 +1,4 @@ -from test.test_support import TESTFN, run_unittest, catch_warning +from test.test_support import TESTFN, run_unittest, catch_warning import unittest import os @@ -200,6 +200,27 @@ class ImportTest(unittest.TestCase): if TESTFN in sys.modules: del sys.modules[TESTFN] + def test_file_to_source(self): + # check if __file__ points to the source file where available + source = TESTFN + ".py" + with open(source, "w") as f: + f.write("test = None\n") + + sys.path.insert(0, os.curdir) + try: + mod = __import__(TESTFN) + self.failUnless(mod.__file__.endswith('.py')) + os.remove(source) + del sys.modules[TESTFN] + mod = __import__(TESTFN) + self.failUnless(mod.__file__.endswith('.pyc')) + finally: + sys.path.pop(0) + remove_files(TESTFN) + if TESTFN in sys.modules: + del sys.modules[TESTFN] + + class PathsTests(unittest.TestCase): SAMPLES = ('test', 'test\u00e4\u00f6\u00fc\u00df', 'test\u00e9\u00e8', 'test\u00b0\u00b3\u00b2') |