Esempio n. 1
0
def test_snippets_errors(actions, snippets):

    _actions = []

    @actions.add(name='my_test', alias='t')
    def test(arg):
        # Enforce single-character argument.
        assert len(str(arg)) == 1
        _actions.append(arg)

    logging_name = 'phy.gui.actions'
    with captured_logging(logging_name) as buf:
        snippets.run(':t1')
    assert 'couldn\'t' in buf.getvalue().lower()

    with captured_logging(logging_name) as buf:
        snippets.run(':t')
    assert 'invalid' in buf.getvalue().lower()

    with captured_logging(logging_name) as buf:
        snippets.run(':t 1 2')
    assert 'invalid' in buf.getvalue().lower()

    with captured_logging(logging_name) as buf:
        snippets.run(':t aa')
    assert 'assert 2 == 1' in buf.getvalue()

    snippets.run(':t a')
    assert _actions == ['a']
Esempio n. 2
0
def test_download_already_exists_invalid(tempdir, mock_url):
    with captured_logging() as buf:
        path = Path(tempdir) / 'test'
        # Create empty file.
        open(path, 'a').close()
        _check(_dl(path))
    assert 'redownload' in buf.getvalue()
Esempio n. 3
0
def test_download_already_exists_valid(tempdir, mock_url):
    with captured_logging() as buf:
        path = Path(tempdir) / 'test'
        # Create valid file.
        with open(path, 'ab') as f:
            f.write(_DATA.tobytes())
        _check(_dl(path))
    assert 'skip' in buf.getvalue()
Esempio n. 4
0
def test_javascript_1(qtbot):
    view = WebView()
    with captured_logging() as buf:
        view.set_html('<script>console.log("Test.");</script>')
        qtbot.addWidget(view)
        view.show()
        qtbot.waitForWindowShown(view)
        _block(lambda: view.html is not None)
        view.close()
    assert buf.getvalue() == ""
Esempio n. 5
0
def test_actions_dialog_2(qtbot, gui, actions):
    @actions.add(shortcut='a', prompt=True)
    def hello(arg1, arg2):
        print("hello", arg1, arg2)

    qtbot.addWidget(gui)
    gui.show()
    qtbot.waitForWindowShown(gui)

    with captured_output() as (stdout, stderr):
        with mock_dialogs(('world world', True)):
            # return string, ok
            actions.get('hello').trigger()
    assert 'hello world' in stdout.getvalue()

    with captured_logging('phy.gui.actions') as buf:
        with mock_dialogs(('world', True)):
            actions.get('hello').trigger()
    assert 'invalid' in buf.getvalue().lower()
Esempio n. 6
0
def test_widget_javascript_1(qtbot):
    widget = HTMLWidget()
    widget.builder.add_script('var number = 1;')
    widget.build()
    widget.show()
    qtbot.addWidget(widget)
    qtbot.waitForWindowShown(widget)
    _block(lambda: widget.html is not None)

    _out = []

    def _callback(res):
        _out.append(res)

    widget.eval_js('number', _callback)
    _block(lambda: _out == [1])

    # Test logging from JS.
    with captured_logging('phy.gui') as buf:
        widget.eval_js('console.warn("hello world!");')
        _block(lambda: 'hello world!' in buf.getvalue().lower())

    # qtbot.stop()
    widget.close()