def test_multiple_process_registration(self):
     writer1 = xg.ProcessWriter(['cat'], [b'c', b'd'], SEPARATOR)
     proc1 = set(self.last_procs)
     writer2 = xg.ProcessWriter(['cat'], [b'e', b'f'], SEPARATOR)
     writer2.write(4096)
     writer1.poll()
     writer2.poll()
     self.assertProcsRegistered(proc1)
 def test_write_sequence(self):
     with FakePopen.with_returncode(0):
         proc = xg.ProcessWriter(['cat'], [b'a', b'b'], SEPARATOR)
         proc.write(3)
         proc.write(3)
         self.assertDone(proc)
         self.assertStdin(b'a\0b\0')
 def test_write_bytes(self):
     test_b = '←→'.encode('utf-8')
     with FakePopen.with_returncode(0):
         proc = xg.ProcessWriter(['cat'], [test_b], SEPARATOR)
         proc.write(4096)
         self.assertDone(proc)
         self.assertStdin('←→\0'.encode('utf-8'))
 def test_no_registration_when_command_not_found(self):
     xg.ProcessWriter.Popen = mock.Mock(side_effect=OSError)
     try:
         xg.ProcessWriter(['cat'], [], SEPARATOR)
     except Exception:
         pass
     self.assertProcsRegistered(set())
 def test_unregistered_after_write_error(self):
     writer = xg.ProcessWriter(['cat'], [b'a', b'b'], SEPARATOR)
     self.last_procs[-1].stdin.write = mock.Mock(
         side_effect=IOError("test error"))
     writer.write(2)
     writer.poll()
     self.assertProcsRegistered(set())
 def test_no_success_after_io_error(self):
     with FakePopen.with_returncode(0):
         proc = xg.ProcessWriter(['cat'], [b'a', b'b'], SEPARATOR)
         self.setup_write_error()
         proc.write(2)
         self.assertEqual(proc.poll(), 0)
         self.assertFalse(proc.success())
 def test_register_on_create(self, writes=[], expect_procs=None):
     writer = xg.ProcessWriter(['cat'], [b'a', b'b'], SEPARATOR)
     if expect_procs is None:
         expect_procs = set(self.last_procs)
     for write_count in writes:
         writer.write(write_count)
         writer.poll()
     self.assertProcsRegistered(expect_procs)
 def test_stop_after_io_error(self):
     with FakePopen.with_returncode(8):
         proc = xg.ProcessWriter(['cat'], [b'a', b'b'], SEPARATOR)
         self.setup_write_error()
         proc.write(2)
         self.assertDone(proc, 8)
 def test_error_code(self):
     with FakePopen.with_returncode(9):
         proc = xg.ProcessWriter(['cat'], [], SEPARATOR)
         self.assertDone(proc, 9)
         self.assertStdin(b'')
 def test_partial_write(self):
     with FakePopen.with_returncode(0):
         proc = xg.ProcessWriter(['cat'], [b'a', b'b'], SEPARATOR)
         proc.write(3)
         self.assertFalse(proc.done_writing())
         self.assertStdin(b'a\0b')
 def test_no_separator(self):
     with FakePopen.with_returncode(0):
         proc = xg.ProcessWriter(['cat'], [b'a', b'b'], None)
         proc.write(4096)
         self.assertDone(proc)
         self.assertStdin(b'ab')
 def test_done_writing_immediately(self):
     with FakePopen.with_returncode(0):
         proc = xg.ProcessWriter(['cat'], [], SEPARATOR)
         self.assertDone(proc)
         self.assertStdin(b'')
 def test_command_not_found_wrapped(self):
     xg.ProcessWriter.Popen = mock.Mock(side_effect=OSError)
     with self.assertRaisesWrapped(OSError, xg.UserCommandError, 'echo'):
         xg.ProcessWriter(['echo', 'hello world'], [], SEPARATOR)