1- import subprocess
2-
31import mitogen .core
42import mitogen .parent
53from mitogen .core import b
@@ -16,29 +14,39 @@ class CommandLineTest(testlib.RouterMixin, testlib.TestCase):
1614 # * 2.7 starting 3.x
1715 # * 3.x starting 2.7
1816
19- def test_valid_syntax (self ):
17+ def setUp (self ):
18+ super (CommandLineTest , self ).setUp ()
2019 options = mitogen .parent .Options (max_message_size = 123 )
2120 conn = mitogen .parent .Connection (options , self .router )
2221 conn .context = mitogen .core .Context (None , 123 )
23- args = conn .get_boot_command ()
22+ self .args = conn .get_boot_command ()
23+ self .preamble = conn .get_preamble ()
24+ self .conn = conn
25+
26+ def test_valid_syntax (self ):
27+ """Test valid syntax
28+
29+ The boot command should write an ECO marker to stdout, read the
30+ preamble from stdin, then execute it.
31+
32+ This test attaches /dev/zero to stdin to create a specific failure
2433
25- # The boot command should write an ECO marker to stdout, read the
26- # preamble from stdin, then execute it.
34+ 1. Fork child reads <compressed preamble size> bytes of NUL (`b'\0 '`)
35+ 2. Fork child crashes (trying to decompress the junk data)
36+ 3. Fork child's file descriptors (write pipes) are closed by the OS
37+ 4. Fork parent does `dup(<read pipe>, <stdin>)` and `exec(<python>)`
38+ 5. Python reads `b''` (i.e. EOF) from stdin (a closed pipe)
39+ 6. Python runs `''` (a valid script) and exits with success
2740
28- # This test attaches /dev/zero to stdin to create a specific failure
29- # 1. Fork child reads <compressed preamble size> bytes of NUL (`b'\0'`)
30- # 2. Fork child crashes (trying to decompress the junk data)
31- # 3. Fork child's file descriptors (write pipes) are closed by the OS
32- # 4. Fork parent does `dup(<read pipe>, <stdin>)` and `exec(<python>)`
33- # 5. Python reads `b''` (i.e. EOF) from stdin (a closed pipe)
34- # 6. Python runs `''` (a valid script) and exits with success
41+ """
3542
3643 fp = open ("/dev/zero" , "r" )
3744 try :
38- proc = subprocess .Popen (args ,
45+ proc = testlib .subprocess .Popen (
46+ self .args ,
3947 stdin = fp ,
40- stdout = subprocess .PIPE ,
41- stderr = subprocess .PIPE ,
48+ stdout = testlib . subprocess .PIPE ,
49+ stderr = testlib . subprocess .PIPE ,
4250 )
4351 stdout , stderr = proc .communicate ()
4452 self .assertEqual (0 , proc .returncode )
0 commit comments