Example #1
0
 def test1(self):
     child = ipc.Subprocess(['false'])
     with assert_raises(ipc.CalledProcessError) as ecm:
         child.wait()
     message = str(ecm.exception)
     if message[-1] == '.':  # subprocess32 >= 3.5
         message = message[:-1]
     assert_equal(message, "Command 'false' returned non-zero exit status 1")
Example #2
0
 def _test_signal(self, name):
     child = ipc.Subprocess(
         ['cat'], stdin=ipc.PIPE)  # Any long-standing process would do.
     os.kill(child.pid, getattr(signal, name))
     with assert_raises(ipc.CalledProcessInterrupted) as ecm:
         child.wait()
     assert_equal(str(ecm.exception),
                  "Command 'cat' was interrupted by signal " + name)
Example #3
0
 def test_fail(self):
     prog = 'ocrodjvu-nonexistent'
     with assert_raises(OSError) as ecm:
         ipc.require(prog)
     exc_message = "[Errno {errno.ENOENT}] command not found: {cmd!r}".format(
         errno=errno,
         cmd=prog,
     )
     assert_equal(str(ecm.exception), exc_message)
Example #4
0
 def test1(self):
     child = ipc.Subprocess(['false'])
     with assert_raises(ipc.CalledProcessError) as ecm:
         child.wait()
     message = str(ecm.exception)
     if message[-1] == '.':  # subprocess32 >= 3.5
         message = message[:-1]
     assert_equal(message,
                  "Command 'false' returned non-zero exit status 1")
Example #5
0
 def test_fail(self):
     prog = 'ocrodjvu-nonexistent'
     with assert_raises(OSError) as ecm:
         ipc.require(prog)
     exc_message = "[Errno {errno.ENOENT}] command not found: {cmd!r}".format(
         errno=errno,
         cmd=prog,
     )
     assert_equal(str(ecm.exception), exc_message)
Example #6
0
def test_init_exc():
    # https://bugs.python.org/issue32490
    prog = 'ocrodjvu-nonexistent'
    with assert_raises(EnvironmentError) as ecm:
        ipc.Subprocess([prog])
    msg = '[Errno {err}] {strerr}: {prog!r}'.format(err=errno.ENOENT,
                                                    strerr=os.strerror(
                                                        errno.ENOENT),
                                                    prog=prog)
    assert_equal(str(ecm.exception), msg)
Example #7
0
def test_init_exc():
    # https://bugs.python.org/issue32490
    prog = 'ocrodjvu-nonexistent'
    with assert_raises(EnvironmentError) as ecm:
        ipc.Subprocess([prog])
    msg = '[Errno {err}] {strerr}: {prog!r}'.format(
        err=errno.ENOENT,
        strerr=os.strerror(errno.ENOENT),
        prog=prog
    )
    assert_equal(str(ecm.exception), msg)
Example #8
0
 def _test_recognize(self, lang1, lang2):
     def fake_subprocess(args, *rest, **kwrest):
         # Record arguments that were used and break immediately.
         assert_equal(args[0], self.engine.executable)
         assert_equal(args[1], '-l')
         assert_equal(args[2], lang1)
         raise EOFError
     with interim(lib.ipc, Subprocess=fake_subprocess):
         with assert_raises(EOFError):
             with self.engine.recognize(sys.stdin, lang1):
                 pass
Example #9
0
    def _test_recognize(self, lang1, lang2):
        def fake_subprocess(args, *rest, **kwrest):
            # Record arguments that were used and break immediately.
            assert_equal(args[0], self.engine.executable)
            assert_equal(args[1], '-l')
            assert_equal(args[2], lang1)
            raise EOFError

        with interim(lib.ipc, Subprocess=fake_subprocess):
            with assert_raises(EOFError):
                with self.engine.recognize(sys.stdin, lang1):
                    pass
Example #10
0
 def t():
     with assert_raises(ImportError) as ecm:
         try:
             import nonexistent
         except ImportError as ex:
             enhance_import_error(ex, 'PyNonexistent', None,
                                  'http://pynonexistent.example.net/')
             raise
         nonexistent.f()  # quieten pyflakes
     assert_equal(
         str(ecm.exception), 'No module named nonexistent; '
         'please install the PyNonexistent package <http://pynonexistent.example.net/>'
     )
Example #11
0
 def test_debian(self):
     with interim(lib.utils, debian=True):
         with assert_raises(ImportError) as ecm:
             try:
                 import nonexistent
             except ImportError as ex:
                 enhance_import_error(ex, 'PyNonexistent',
                                      'python-nonexistent',
                                      'http://pynonexistent.example.net/')
                 raise
             nonexistent.f()  # quieten pyflakes
         assert_equal(
             str(ecm.exception), 'No module named nonexistent; '
             'please install the python-nonexistent package')
Example #12
0
 def _test_signal(self, name):
     child = ipc.Subprocess(['cat'], stdin=ipc.PIPE)  # Any long-standing process would do.
     os.kill(child.pid, getattr(signal, name))
     with assert_raises(ipc.CalledProcessInterrupted) as ecm:
         child.wait()
     assert_equal(str(ecm.exception), "Command 'cat' was interrupted by signal " + name)
Example #13
0
 def test1(self):
     child = ipc.Subprocess(['false'])
     with assert_raises(ipc.CalledProcessError) as ecm:
         child.wait()
     assert_equal(str(ecm.exception),
                  "Command 'false' returned non-zero exit status 1")