Skip to content

Commit c77b931

Browse files
author
Victor Stinner
committed
Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
Stührk.
1 parent d0e11ec commit c77b931

File tree

4 files changed

+44
-31
lines changed

4 files changed

+44
-31
lines changed

Lib/test/test_frozen.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,37 @@
66

77
class FrozenTests(unittest.TestCase):
88
def test_frozen(self):
9-
try:
10-
import __hello__
11-
except ImportError as x:
12-
self.fail("import __hello__ failed:" + str(x))
13-
self.assertEqual(__hello__.initialized, True)
14-
self.assertEqual(len(dir(__hello__)), 6, dir(__hello__))
9+
with captured_stdout() as stdout:
10+
try:
11+
import __hello__
12+
except ImportError as x:
13+
self.fail("import __hello__ failed:" + str(x))
14+
self.assertEqual(__hello__.initialized, True)
15+
self.assertEqual(len(dir(__hello__)), 6, dir(__hello__))
16+
self.assertEqual(stdout.getvalue(), 'Hello world!\n')
1517

16-
try:
17-
import __phello__
18-
except ImportError as x:
19-
self.fail("import __phello__ failed:" + str(x))
20-
self.assertEqual(__phello__.initialized, True)
21-
if not "__phello__.spam" in sys.modules:
22-
self.assertEqual(len(dir(__phello__)), 7, dir(__phello__))
23-
else:
24-
self.assertEqual(len(dir(__phello__)), 8, dir(__phello__))
25-
self.assertEqual(__phello__.__path__, [__phello__.__name__])
18+
with captured_stdout() as stdout:
19+
try:
20+
import __phello__
21+
except ImportError as x:
22+
self.fail("import __phello__ failed:" + str(x))
23+
self.assertEqual(__phello__.initialized, True)
24+
if not "__phello__.spam" in sys.modules:
25+
self.assertEqual(len(dir(__phello__)), 7, dir(__phello__))
26+
else:
27+
self.assertEqual(len(dir(__phello__)), 8, dir(__phello__))
28+
self.assertEqual(__phello__.__path__, [__phello__.__name__])
29+
self.assertEqual(stdout.getvalue(), 'Hello world!\n')
2630

27-
try:
28-
import __phello__.spam
29-
except ImportError as x:
30-
self.fail("import __phello__.spam failed:" + str(x))
31-
self.assertEqual(__phello__.spam.initialized, True)
32-
self.assertEqual(len(dir(__phello__.spam)), 6)
33-
self.assertEqual(len(dir(__phello__)), 8)
31+
with captured_stdout() as stdout:
32+
try:
33+
import __phello__.spam
34+
except ImportError as x:
35+
self.fail("import __phello__.spam failed:" + str(x))
36+
self.assertEqual(__phello__.spam.initialized, True)
37+
self.assertEqual(len(dir(__phello__.spam)), 6)
38+
self.assertEqual(len(dir(__phello__)), 8)
39+
self.assertEqual(stdout.getvalue(), 'Hello world!\n')
3440

3541
try:
3642
import __phello__.foo

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ Build
390390
Tests
391391
-----
392392

393+
- Issue #11614: import __hello__ prints "Hello World!". Patch written by
394+
Andreas Stührk.
395+
393396
- Issue #5723: Improve json tests to be executed with and without accelerations.
394397

395398
- Issue #11910: Fix test_heapq to skip the C tests when _heapq is missing.

Python/frozen.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
the appropriate bytes from M___main__.c. */
1313

1414
static unsigned char M___hello__[] = {
15-
99,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,
16-
0,64,0,0,0,115,10,0,0,0,100,1,0,90,1,0,
17-
100,0,0,83,40,2,0,0,0,78,84,40,2,0,0,0,
18-
117,4,0,0,0,84,114,117,101,117,11,0,0,0,105,110,
19-
105,116,105,97,108,105,122,101,100,40,0,0,0,0,40,0,
20-
0,0,0,40,0,0,0,0,117,7,0,0,0,102,108,97,
21-
103,46,112,121,117,8,0,0,0,60,109,111,100,117,108,101,
22-
62,1,0,0,0,115,0,0,0,0,
15+
99,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,
16+
0,64,0,0,0,115,20,0,0,0,100,2,0,90,1,0,
17+
101,2,0,100,0,0,131,1,0,1,100,1,0,83,40,3,
18+
0,0,0,117,12,0,0,0,72,101,108,108,111,32,119,111,
19+
114,108,100,33,78,84,40,3,0,0,0,117,4,0,0,0,
20+
84,114,117,101,117,11,0,0,0,105,110,105,116,105,97,108,
21+
105,122,101,100,117,5,0,0,0,112,114,105,110,116,40,0,
22+
0,0,0,40,0,0,0,0,40,0,0,0,0,117,7,0,
23+
0,0,102,108,97,103,46,112,121,117,8,0,0,0,60,109,
24+
111,100,117,108,101,62,1,0,0,0,115,2,0,0,0,6,
25+
1,
2326
};
2427

2528
#define SIZE (int)sizeof(M___hello__)

Tools/freeze/flag.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
initialized = True
2+
print("Hello world!")

0 commit comments

Comments
 (0)