Beispiel #1
0
def version():
    """
    return eagle version.
    It does not work without X!

    :rtype: string
    """
    return extract_version(EasyProcess("eagle -?").call().stdout)
Beispiel #2
0
 def test_slowshot_timeout(self):
     disp = SmartDisplay(visible=0)
     py = Path(__file__).parent / ("slowgui.py")
     proc = EasyProcess("python " + py)
     with disp:
         with proc:
             with self.assertRaises(DisplayTimeoutError):
                 img = disp.waitgrab(timeout=1)
Beispiel #3
0
    def upload_testdata(self, data, suffix=''):
        path = os.path.join(os.path.dirname(__file__), 'judge')
        zipfile = os.path.join(path, 'tmp.zip')
        desfile = os.path.join(path, 'tmp')
        zipdata = data.get('zipdata')
        zipdata = zipdata.replace('data:application/zip;base64,', '')
        zipdata = base64.b64decode(zipdata)
        with open(zipfile, 'wb') as f:
            f.write(zipdata)
        #extract
        os.system('unzip %s -d %s' % (zipfile, desfile))

        cmd = '"ls %s | grep .in"' % desfile
        input_data = EasyProcess('bash -c ' + cmd).call().stdout.split('\n')
        cmd = '"ls %s | grep .out"' % desfile
        output_data = EasyProcess('bash -c ' + cmd).call().stdout.split('\n')

        #check files name
        if len(input_data) != len(output_data):
            os.system('rm %s' % zipfile)
            os.system('rm -r %s' % desfile)
            return {'result': '.in files does not match .out files'}

        for x, y in zip(input_data, output_data):
            if x.replace('.in', '') != y.replace('.out', ''):
                os.system('rm %s' % zipfile)
                os.system('rm -r %s' % desfile)
                return {'result': '.in files does not match .out files'}

        #read in out files
        self.data_name = []
        self.data_in = []
        self.data_out = []

        for x, y in zip(input_data, output_data):
            self.data_name.append(x.replace('.in', ''))
            path = os.path.join(desfile, x)
            cmd = '"cat %s"' % (path)
            self.data_in.append(EasyProcess('bash -c ' + cmd).call().stdout)
            path = os.path.join(desfile, y)
            cmd = '"cat %s"' % (path)
            self.data_out.append(EasyProcess('bash -c ' + cmd).call().stdout)

        os.system('rm %s' % zipfile)
        os.system('rm -r %s' % desfile)
        return {'result': 'success'}
Beispiel #4
0
def test_slowshot_nocrop():
    disp = SmartDisplay(visible=False)
    py = Path(__file__).parent / ("slowgui.py")
    proc = EasyProcess([python, py])
    with disp:
        with proc:
            img = disp.waitgrab(autocrop=False)
    assert img is not None
Beispiel #5
0
def test_slowshot_timeout():
    disp = SmartDisplay(visible=False)
    py = Path(__file__).parent / ("slowgui.py")
    proc = EasyProcess([python, py])
    with disp:
        with proc:
            with pytest.raises(DisplayTimeoutError):
                img = disp.waitgrab(timeout=1)
Beispiel #6
0
 def backend_version(self):
     # grim doesn't have a version flag for some reason
     p = EasyProcess([PROGRAM, "-help"])
     p.enable_stdout_log = False
     p.enable_stderr_log = False
     p.call()
     if p.return_code == 0:
         return UNKNOWN_VERSION
Beispiel #7
0
def test_slowshot():
    disp = SmartDisplay(visible=False).start()
    py = Path(__file__).parent / ("slowgui.py")
    proc = EasyProcess([python, py]).start()
    img = disp.waitgrab()
    proc.stop()
    disp.stop()
    assert img is not None
Beispiel #8
0
 def test_slowshot_wrap(self):
     disp = SmartDisplay(visible=0)
     py = Path(__file__).parent / ("slowgui.py")
     proc = EasyProcess("python " + py)
     with disp:
         with proc:
             img = disp.waitgrab()
     eq_(img is not None, True)
Beispiel #9
0
 def test_slowshot(self):
     disp = SmartDisplay(visible=0).start()
     py = Path(__file__).parent / ("slowgui.py")
     proc = EasyProcess("python " + py).start()
     img = disp.waitgrab()
     proc.stop()
     disp.stop()
     eq_(img is not None, True)
Beispiel #10
0
 def backend_version(self):
     p = EasyProcess([PROGRAM, "-help"])
     p.enable_stdout_log = False
     p.enable_stderr_log = False
     p.call()
     if p.return_code == 0:
         # TODO: get real version
         return "0.0"
Beispiel #11
0
def test_check_hints_list_int():
    if PY39PLUS:
        hints = """
list[str] -> list ['3', '42']
list[bytes] -> list [b'3', b'42']
list[int] -> list [3, 42]
list[float] -> list [3.0, 42.0]
list[complex] -> list [(3+0j), (42+0j)]
list[bool] -> list [True, True]
    """.strip()
    else:
        hints = """
list[str] -> TypeError: 'type' object is not subscriptable
list[bytes] -> TypeError: 'type' object is not subscriptable
list[int] -> TypeError: 'type' object is not subscriptable
list[float] -> TypeError: 'type' object is not subscriptable
list[complex] -> TypeError: 'type' object is not subscriptable
list[bool] -> TypeError: 'type' object is not subscriptable
""".strip()

    hints += """
str -> -c: error: unrecognized arguments: 42
bytes -> -c: error: unrecognized arguments: 42
int -> -c: error: unrecognized arguments: 42
float -> -c: error: unrecognized arguments: 42
complex -> -c: error: unrecognized arguments: 42
bool -> -c: error: unrecognized arguments: 42
List[str] -> list ['3', '42']
List[bytes] -> list [b'3', b'42']
List[int] -> list [3, 42]
List[float] -> list [3.0, 42.0]
List[complex] -> list [(3+0j), (42+0j)]
List[bool] -> list [True, True]
Sequence[str] -> list ['3', '42']
Sequence[bytes] -> list [b'3', b'42']
Sequence[int] -> list [3, 42]
Sequence[float] -> list [3.0, 42.0]
Sequence[complex] -> list [(3+0j), (42+0j)]
Sequence[bool] -> list [True, True]
Iterable[str] -> list ['3', '42']
Iterable[bytes] -> list [b'3', b'42']
Iterable[int] -> list [3, 42]
Iterable[float] -> list [3.0, 42.0]
Iterable[complex] -> list [(3+0j), (42+0j)]
Iterable[bool] -> list [True, True]
Optional[str] -> -c: error: unrecognized arguments: 42
Optional[bytes] -> -c: error: unrecognized arguments: 42
Optional[int] -> -c: error: unrecognized arguments: 42
Optional[float] -> -c: error: unrecognized arguments: 42
Optional[complex] -> -c: error: unrecognized arguments: 42
Optional[bool] -> -c: error: unrecognized arguments: 42
Any -> -c: error: unrecognized arguments: 42
"""
    p = EasyProcess([python, "-m", "entrypoint2.check.hints", "3",
                     "42"]).call()
    assert p.stderr == ""
    assert p.return_code == 0
    assert p.stdout.splitlines() == hints.strip().splitlines()
Beispiel #12
0
def test_check_hints_float():
    if PY39PLUS:
        hints = """
list[str] -> list ['42.1']
list[bytes] -> list [b'42.1']
list[int] -> -c: error: argument param: invalid int value: '42.1'
list[float] -> list [42.1]
list[complex] -> list [(42.1+0j)]
list[bool] -> list [True]
    """.strip()
    else:
        hints = """
list[str] -> TypeError: 'type' object is not subscriptable
list[bytes] -> TypeError: 'type' object is not subscriptable
list[int] -> TypeError: 'type' object is not subscriptable
list[float] -> TypeError: 'type' object is not subscriptable
list[complex] -> TypeError: 'type' object is not subscriptable
list[bool] -> TypeError: 'type' object is not subscriptable
""".strip()

    hints += """
str -> str '42.1'
bytes -> bytes b'42.1'
int -> -c: error: argument param: invalid int value: '42.1'
float -> float 42.1
complex -> complex (42.1+0j)
bool -> bool True
List[str] -> list ['42.1']
List[bytes] -> list [b'42.1']
List[int] -> -c: error: argument param: invalid int value: '42.1'
List[float] -> list [42.1]
List[complex] -> list [(42.1+0j)]
List[bool] -> list [True]
Sequence[str] -> list ['42.1']
Sequence[bytes] -> list [b'42.1']
Sequence[int] -> -c: error: argument param: invalid int value: '42.1'
Sequence[float] -> list [42.1]
Sequence[complex] -> list [(42.1+0j)]
Sequence[bool] -> list [True]
Iterable[str] -> list ['42.1']
Iterable[bytes] -> list [b'42.1']
Iterable[int] -> -c: error: argument param: invalid int value: '42.1'
Iterable[float] -> list [42.1]
Iterable[complex] -> list [(42.1+0j)]
Iterable[bool] -> list [True]
Optional[str] -> str '42.1'
Optional[bytes] -> bytes b'42.1'
Optional[int] -> -c: error: argument param: invalid int value: '42.1'
Optional[float] -> float 42.1
Optional[complex] -> complex (42.1+0j)
Optional[bool] -> bool True
Any -> str '42.1'
"""
    p = EasyProcess([python, "-m", "entrypoint2.check.hints", "42.1"]).call()
    assert p.stderr == ""
    assert p.return_code == 0
    assert p.stdout.splitlines() == hints.strip().splitlines()
Beispiel #13
0
def test_1_help():
    cmd = [python, example1_py, "--help"]
    p = EasyProcess(cmd).call()
    assert p.stderr == ""
    assert p.return_code == 0
    assert "one" in p.stdout
    assert "--two" in p.stdout
    assert "-t" in p.stdout
    assert "--three" in p.stdout
 def test_timeout_out(self):
     p = EasyProcess([
         python, '-c',
         "import time;print( 'start');time.sleep(5);print( 'end')"
     ]).call(timeout=1)
     eq_(p.is_alive(), False)
     eq_(p.timeout_happened, True)
     ok_(p.return_code < 0)
     eq_(p.stdout, '')
Beispiel #15
0
def test_check_hints_0():
    if PY39PLUS:
        hints = """
list[str] -> list ['0']
list[bytes] -> list [b'0']
list[int] -> list [0]
list[float] -> list [0.0]
list[complex] -> list [0j]
list[bool] -> list [False]
    """.strip()
    else:
        hints = """
list[str] -> TypeError: 'type' object is not subscriptable
list[bytes] -> TypeError: 'type' object is not subscriptable
list[int] -> TypeError: 'type' object is not subscriptable
list[float] -> TypeError: 'type' object is not subscriptable
list[complex] -> TypeError: 'type' object is not subscriptable
list[bool] -> TypeError: 'type' object is not subscriptable
""".strip()

    hints += """
str -> str '0'
bytes -> bytes b'0'
int -> int 0
float -> float 0.0
complex -> complex 0j
bool -> bool False
List[str] -> list ['0']
List[bytes] -> list [b'0']
List[int] -> list [0]
List[float] -> list [0.0]
List[complex] -> list [0j]
List[bool] -> list [False]
Sequence[str] -> list ['0']
Sequence[bytes] -> list [b'0']
Sequence[int] -> list [0]
Sequence[float] -> list [0.0]
Sequence[complex] -> list [0j]
Sequence[bool] -> list [False]
Iterable[str] -> list ['0']
Iterable[bytes] -> list [b'0']
Iterable[int] -> list [0]
Iterable[float] -> list [0.0]
Iterable[complex] -> list [0j]
Iterable[bool] -> list [False]
Optional[str] -> str '0'
Optional[bytes] -> bytes b'0'
Optional[int] -> int 0
Optional[float] -> float 0.0
Optional[complex] -> complex 0j
Optional[bool] -> bool False
Any -> str '0'
"""
    p = EasyProcess([python, "-m", "entrypoint2.check.hints", "0"]).call()
    assert p.stderr == ""
    assert p.return_code == 0
    assert p.stdout.splitlines() == hints.strip().splitlines()
Beispiel #16
0
def display_size():
    # http://www.cyberciti.biz/faq/how-do-i-find-out-screen-resolution-of-my-linux-desktop/
    # xdpyinfo  | grep 'dimensions:'
    for x in EasyProcess('xdpyinfo').call().stdout.splitlines():
        if 'dimensions:' in x:
            screen_width, screen_height = map(
                int, x.strip().split()[1].split('x'))

    return screen_width, screen_height
Beispiel #17
0
 def testrun(self, command, timeout=0.5):
     result = {'result': False}
     pro = EasyProcess(command.split()).call(timeout=timeout)
     if pro.return_code > 0:
         result['error'] = pro.stderr
     else:
         result['result'] = True
     pro.stop()
     return result
Beispiel #18
0
def screenshot(cmd, fname):
    logging.info("%s %s", cmd, fname)
    # fpath = "docs/_img/%s" % fname
    # if os.path.exists(fpath):
    #     os.remove(fpath)
    with SmartDisplay() as disp:
        with EasyProcess(cmd):
            img = disp.waitgrab()
            img.save(fname)
Beispiel #19
0
def func2(results):
    with SmartDisplay(manage_global_env=False) as disp:
        env = disp.env()
        logging.info("env=%s", env)
        sleep(2)
        with EasyProcess(["xmessage", "hello"], env=env):
            im = disp.waitgrab(timeout=1)
            results[0] = im
            sleep(2)
Beispiel #20
0
def prog_check(cmd):
    try:
        p = EasyProcess(cmd)
        p.enable_stdout_log = False
        p.enable_stderr_log = False
        p.call()
        return p.return_code == 0
    except Exception:
        return False
Beispiel #21
0
def test_1_help():
    cmd = [python, example1_py, "--help"]
    p = EasyProcess(cmd).call()
    ported_eq(p.stderr, "")
    ported_eq(p.return_code, 0)
    ported_eq("one" in p.stdout, 1)
    ported_eq("--two" in p.stdout, 1)
    ported_eq("-t" in p.stdout, 1)
    ported_eq("--three" in p.stdout, 1)
Beispiel #22
0
 def test_vncserver():
     if worker() == 0:
         p = EasyProcess(
             [python, "-m", "pyvirtualdisplay.examples.vncserver"]
         ).start()
         sleep(1)
         assert p.is_alive()
         # p.stop()
         kill_process_tree(p)
Beispiel #23
0
def gather_datum(prog, path, base, additional_flags, timeout):
    start = time.time()
    flags = additional_flags
    #flags = map(lambda t: t(path,base),additional_flags)
    process_output = EasyProcess([prog] + BASE_FLAGS + flags +
                                 [join(path, base + TEST_EXT)]).call(
                                     timeout=timeout)
    end = time.time()
    return ((end - start), process_output.stdout, process_output.stderr)
Beispiel #24
0
def export(params, fail=0):
    # mod=path(__file__).parent.parent / 'eagexp.py'
    # cmd='python '+mod+' '+params
    cmd = "python -m eagexp.image " + params
    p = EasyProcess(cmd).call()
    if fail:
        assert p.return_code != 0
    else:
        assert p.return_code == 0
Beispiel #25
0
def test_check_hints_int():
    if PY39PLUS:
        hints = """
list[str] -> list ['42']
list[bytes] -> list [b'42']
list[int] -> list [42]
list[float] -> list [42.0]
list[complex] -> list [(42+0j)]
list[bool] -> list [True]
    """.strip()
    else:
        hints = """
list[str] -> TypeError: 'type' object is not subscriptable
list[bytes] -> TypeError: 'type' object is not subscriptable
list[int] -> TypeError: 'type' object is not subscriptable
list[float] -> TypeError: 'type' object is not subscriptable
list[complex] -> TypeError: 'type' object is not subscriptable
list[bool] -> TypeError: 'type' object is not subscriptable
""".strip()

    hints += """
str -> str '42'
bytes -> bytes b'42'
int -> int 42
float -> float 42.0
complex -> complex (42+0j)
bool -> bool True
List[str] -> list ['42']
List[bytes] -> list [b'42']
List[int] -> list [42]
List[float] -> list [42.0]
List[complex] -> list [(42+0j)]
List[bool] -> list [True]
Sequence[str] -> list ['42']
Sequence[bytes] -> list [b'42']
Sequence[int] -> list [42]
Sequence[float] -> list [42.0]
Sequence[complex] -> list [(42+0j)]
Sequence[bool] -> list [True]
Iterable[str] -> list ['42']
Iterable[bytes] -> list [b'42']
Iterable[int] -> list [42]
Iterable[float] -> list [42.0]
Iterable[complex] -> list [(42+0j)]
Iterable[bool] -> list [True]
Optional[str] -> str '42'
Optional[bytes] -> bytes b'42'
Optional[int] -> int 42
Optional[float] -> float 42.0
Optional[complex] -> complex (42+0j)
Optional[bool] -> bool True
Any -> str '42'
"""
    p = EasyProcess([python, "-m", "entrypoint2.check.hints", "42"]).call()
    assert p.stderr == ""
    assert p.return_code == 0
    assert p.stdout.splitlines() == hints.strip().splitlines()
Beispiel #26
0
def test_check_hints_str():
    if PY39PLUS:
        hints = """
list[str] -> list ['abc']
list[bytes] -> list [b'abc']
list[int] -> -c: error: argument param: invalid int value: 'abc'
list[float] -> -c: error: argument param: invalid float value: 'abc'
list[complex] -> -c: error: argument param: invalid complex value: 'abc'
list[bool] -> list [True]
    """.strip()
    else:
        hints = """
list[str] -> TypeError: 'type' object is not subscriptable
list[bytes] -> TypeError: 'type' object is not subscriptable
list[int] -> TypeError: 'type' object is not subscriptable
list[float] -> TypeError: 'type' object is not subscriptable
list[complex] -> TypeError: 'type' object is not subscriptable
list[bool] -> TypeError: 'type' object is not subscriptable
""".strip()

    hints += """
str -> str 'abc'
bytes -> bytes b'abc'
int -> -c: error: argument param: invalid int value: 'abc'
float -> -c: error: argument param: invalid float value: 'abc'
complex -> -c: error: argument param: invalid complex value: 'abc'
bool -> bool True
List[str] -> list ['abc']
List[bytes] -> list [b'abc']
List[int] -> -c: error: argument param: invalid int value: 'abc'
List[float] -> -c: error: argument param: invalid float value: 'abc'
List[complex] -> -c: error: argument param: invalid complex value: 'abc'
List[bool] -> list [True]
Sequence[str] -> list ['abc']
Sequence[bytes] -> list [b'abc']
Sequence[int] -> -c: error: argument param: invalid int value: 'abc'
Sequence[float] -> -c: error: argument param: invalid float value: 'abc'
Sequence[complex] -> -c: error: argument param: invalid complex value: 'abc'
Sequence[bool] -> list [True]
Iterable[str] -> list ['abc']
Iterable[bytes] -> list [b'abc']
Iterable[int] -> -c: error: argument param: invalid int value: 'abc'
Iterable[float] -> -c: error: argument param: invalid float value: 'abc'
Iterable[complex] -> -c: error: argument param: invalid complex value: 'abc'
Iterable[bool] -> list [True]
Optional[str] -> str 'abc'
Optional[bytes] -> bytes b'abc'
Optional[int] -> -c: error: argument param: invalid int value: 'abc'
Optional[float] -> -c: error: argument param: invalid float value: 'abc'
Optional[complex] -> -c: error: argument param: invalid complex value: 'abc'
Optional[bool] -> bool True
Any -> str 'abc'
"""
    p = EasyProcess([python, "-m", "entrypoint2.check.hints", "abc"]).call()
    assert p.stderr == ""
    assert p.return_code == 0
    assert p.stdout.splitlines() == hints.strip().splitlines()
Beispiel #27
0
def prog_shot(cmd, f, wait, timeout, screen_size, visible, bgcolor, backend):
    '''start process in headless X and create screenshot after 'wait' sec.
    Repeats screenshot until it is not empty if 'repeat_if_empty'=True.

    wait: wait at least N seconds after first window is displayed,
    it can be used to skip splash screen

    :param wait: int
    '''
    # disp = SmartDisplay(visible=visible, size=screen_size, bgcolor=bgcolor)
    #'xvfb', 'xvnc' or 'xephyr',
    disp = SmartDisplay(visible=visible,
                        backend=backend,
                        size=screen_size,
                        bgcolor=bgcolor)
    proc = EasyProcess(cmd)

    def cb_imgcheck(img):
        """accept img if height > minimum."""
        rec = get_black_box(img)
        if not rec:
            return False
        left, upper, right, lower = rec
        accept = lower - upper > 30  # pixel
        log.debug('cropped img size=' + str((left, upper, right, lower)) +
                  ' accepted=' + str(accept))
        return accept

    # def func():
    #     if wait:
    #         proc.sleep(wait)
    #     try:
    #         img = disp.waitgrab(timeout=timeout, cb_imgcheck=cb_imgcheck)
    #     except DisplayTimeoutError as e:
    #         raise DisplayTimeoutError(str(e) + ' ' + str(proc))
    #     return img

    with disp:
        with proc:
            try:
                if wait:
                    proc.sleep(wait)
                img = disp.waitgrab(timeout=timeout, cb_imgcheck=cb_imgcheck)
            except DisplayTimeoutError as e:
                raise DisplayTimeoutError(str(e) + ' ' + str(proc))

    # img = disp.wrap(proc.wrap(func))()
    if img:
        bbox = get_black_box(img)
        assert bbox
        # extend to the left side
        bbox = (0, bbox[1], bbox[2], bbox[3])
        img = img.crop(bbox)

        img.save(f)
    return (proc.stdout, proc.stderr)
 def vnc(self, vnc_display):
     os.environ["DISPLAY"] = vnc_display
     with Display(backend='xvnc', rfbport=5902, size=(223, 150)) as disp:
         with EasyProcess(' '.join([
                 'gnash',
                 os.path.join(self.env.path,
                              self.env.swf), "--width", "150", "--height",
                 "150", "--render-mode", "1", "--hide-menubar"
         ])) as proc:
             proc.wait()
Beispiel #29
0
def test_1_ver():
    cmd = [python, example1_py, "--version"]
    p = EasyProcess(cmd).call()
    if PY3:
        ported_eq(p.stderr, "")
        ported_eq(p.stdout, "3.2")
    else:
        ported_eq(p.stdout, "")
        ported_eq(p.stderr, "3.2")
    ported_eq(p.return_code, 0)
def screenshot(cmd, fname):
    logging.info("%s %s", cmd, fname)
    fpath = "docs/_img/%s" % fname
    if os.path.exists(fpath):
        os.remove(fpath)
    with SmartDisplay(visible=0, bgcolor="black") as disp:
        with EasyProcess(cmd):
            img = disp.waitgrab()
            img.save(fpath)
            cog.outl(".. image:: _img/%s" % fname)