Exemple #1
0
def editorbot(qtbot):
    widget = codeeditor.CodeEditor(None)
    widget.setup_editor(linenumbers=True, markers=True, tab_mode=False,
                        font=QFont("Courier New", 10),
                        show_blanks=True, color_scheme='Zenburn',
                        scroll_past_end=True)
    widget.setup_editor(language='Python')
    qtbot.addWidget(widget)
    widget.show()
    return qtbot, widget
Exemple #2
0
def test_import_ticket_names(qtbot: qtbot.QtBot, mocker: MockerFixture):
    """Tests the import ticket names feature"""
    gui_manager.clear_windows()

    gui_manager.initialize()

    for window in gui_manager.window_list:
        qtbot.addWidget(window)

    # Import ticket names and prizes
    mocker.patch('PyQt5.QtWidgets.QFileDialog.exec')
    mocker.patch('PyQt5.QtWidgets.QFileDialog.selectedFiles',
                 return_value=['examples/ticket_names.txt'])
    gui_manager.window_list[0].import_ticket_names_action.trigger()
    mocker.patch('PyQt5.QtWidgets.QFileDialog.selectedFiles',
                 return_value=['examples/prizes.txt'])
    gui_manager.window_list[0].import_prizes_action.trigger()

    # Restart before starting
    raffle.restart()

    # Mock prize alerts
    mocker.patch('Ui.prize_alert.PrizeAlert')

    # Draw all of the tickets in a random order
    ticket_numbers = list(range(1, 226))
    shuffle(ticket_numbers)
    for ticket_number in ticket_numbers:
        qtbot.mouseClick(
            gui_manager.window_list[0].ticket_labels[ticket_number - 1],
            Qt.LeftButton)

        # Draw the next ticket
        QApplication.processEvents()
        sleep(0.01)

    # Export the results to a csv file
    mocker.patch('PyQt5.QtWidgets.QFileDialog.getSaveFileName',
                 return_value=['results.csv', 'CSV files (*.csv)'])
    gui_manager.window_list[0].export_results_action.trigger()
    QApplication.processEvents()

    with open("results.csv", 'r') as results:
        for i, ticket_number in enumerate(ticket_numbers):
            values = results.readline().strip().split(',')

            # Verify information is present in results
            assert values[0] == str(i + 1)
            assert values[1] == str(ticket_number)
            assert values[2] == raffle.tickets[ticket_number - 1].name

            if raffle.get_prize_from_number(i + 1):
                assert values[3] == raffle.get_prize_from_number(
                    i + 1).description.strip()
Exemple #3
0
def test_NDViewer(simple_small_data, qtbot):
    from xicam.gui.widgets.ndimageview import NDImageView
    from skimage.transform import rescale, resize, downscale_local_mean


    w = NDImageView()
    w.histogram_subsampling_axes = ['E (eV)']
    w.setData(simple_small_data)

    qtbot.addWidget(w)
    w.show()
Exemple #4
0
def test_accessconstraints_from_xml(qtbot):
    widget = accconst.Accconst()
    qtbot.addWidget(widget)

    test_record_fname = "tests/data/Onshore_Industrial_Wind_Turbine_Locations_for_the_United_States_through_July2013.xml"
    test_record = etree.parse(test_record_fname)
    acc_const = test_record.xpath("idinfo/accconst")[0]

    widget.from_xml(acc_const)
    assert widget.findChild(QPlainTextEdit,
                            "fgdc_accconst").toPlainText() == "none"
def test_datacredit_from_xml(qtbot):
    widget = datacred.Datacred()
    qtbot.addWidget(widget)

    test_record_fname = "tests/data/GenericFGDCTemplate_FGDCtemp.xml"
    test_record = etree.parse(test_record_fname)
    data_credit = test_record.xpath("idinfo/datacred")[0]

    widget.from_xml(data_credit)
    assert widget.findChild(
        QPlainTextEdit, "fgdc_datacred").toPlainText() == 'Data set Credits MH'
Exemple #6
0
def test_accessconstraints_to_xml(qtbot):
    widget = accconst.Accconst()
    qtbot.addWidget(widget)

    assert (widget.findChild(QPlainTextEdit, "fgdc_accconst").toPlainText() ==
            "None.  Please see 'Distribution Info' for details.")
    ac = widget.to_xml()
    assert (
        str(etree.tostring(ac, pretty_print=True).decode()) ==
        """<accconst>None.  Please see 'Distribution Info' for details.</accconst>
""")
def setup_tests(qtbot):
    aw = ApplicationWindow()
    qtbot.addWidget(aw)
    logger.setup(aw._ui.log_text, aw)
    config.load_config()
    setattr(MerlinBinary, get_memmap.__name__, get_memmap)

    aw._mib_path = "/home/ubuntu/example-data/13_FeRh-Alisa_DW_diff_20um_115C.mib"
    aw._dm3_path = "/home/ubuntu/example-data/13_FeRh-Alisa_DW_diff_20um_115C.dm3"
    enter()
    aw.load_files()
    return aw
Exemple #8
0
def editorbot(qtbot):
    widget = codeeditor.CodeEditor(None)
    widget.setup_editor(linenumbers=True,
                        markers=True,
                        tab_mode=False,
                        font=QFont("Courier New", 10),
                        show_blanks=True,
                        color_scheme='Zenburn')
    widget.setup_editor(language='Python')
    qtbot.addWidget(widget)
    widget.show()
    return qtbot, widget
def editor_bot(qtbot):
    from spyder.plugins.editor.widgets.editor import codeeditor
    widget = codeeditor.CodeEditor(None)
    widget.setup_editor(linenumbers=True,
                        markers=True,
                        tab_mode=False,
                        show_blanks=True,
                        color_scheme='Zenburn')
    widget.setup_editor(language='Python')
    qtbot.addWidget(widget)
    widget.show()
    return qtbot, widget
def editor_bot(qtbot):
    from spyder.plugins.editor.widgets.editor import codeeditor
    widget = codeeditor.CodeEditor(None)
    widget.setup_editor(linenumbers=True,
                        markers=True,
                        tab_mode=False,
                        show_blanks=True,
                        color_scheme='Zenburn')
    widget.setup_editor(language='Python')
    qtbot.addWidget(widget)
    widget.show()
    return qtbot, widget
Exemple #11
0
def test_mainwindow_from_xml(qtbot, mock):

    widget = MainWindow.PyMdWizardMainForm()
    qtbot.addWidget(widget)

    test_record_fname = "tests/data/GenericFGDCTemplate_FGDCtemp.xml"
    mock.patch.object(QMessageBox, 'question', return_value=QMessageBox.No)
    widget.open_file(test_record_fname)

    assert widget.metadata_root.findChild(
        QPlainTextEdit, "fgdc_logic").toPlainText(
        ) == 'No formal logical accuracy tests were conducted. testing'
def test_datacredit_to_xml(qtbot):
    widget = datacred.Datacred()
    qtbot.addWidget(widget)

    widget.findChild(
        QPlainTextEdit,
        "fgdc_datacred").setPlainText("This is who should be credited.")

    dc = widget.to_xml()

    assert etree.tostring(dc, pretty_print=True).decode() \
    == """<datacred>This is who should be credited.</datacred>
async def test_main(
    qtbot: pytestqt.qtbot.QtBot,
    optional_hold_event: typing.Optional[trio.Event],
) -> None:
    message = "test world"

    async with trio.open_nursery() as nursery:
        start = functools.partial(
            qtrio.examples.buildingrespect.start_widget,
            message=message,
            hold_event=optional_hold_event,
        )
        widget: qtrio.examples.buildingrespect.Widget = await nursery.start(
            start)
        qtbot.addWidget(widget.widget)

        async with qtrio.enter_emissions_channel(signals=[widget.text_changed
                                                          ], ) as emissions:
            if optional_hold_event is not None:
                optional_hold_event.set()

            await trio.testing.wait_all_tasks_blocked(cushion=0.01)

            # lazily click the button and collect results in the memory channel rather
            # than starting concurrent tasks.

            # close the send channel so the receive channel knows when it is done
            async with emissions.send_channel:
                for _ in message:
                    widget.button.click()

                    # give Qt etc a chance to handle the clicks before closing the channel
                    await trio.testing.wait_all_tasks_blocked(cushion=0.01)

            results: typing.List[typing.Tuple[object]] = [
                emission.args async for emission in emissions.channel
            ]

            widget.button.click()

    assert results == [
        ("t", ),
        ("te", ),
        ("tes", ),
        ("test", ),
        ("test ", ),
        ("test w", ),
        ("test wo", ),
        ("test wor", ),
        ("test worl", ),
        ("test world", ),
    ]
Exemple #14
0
def test_valid_pin_entry(qtbot):
    _, terminal_status = set_up_accounts_and_terminal_status()
    terminal_status.current_pan = '1'
    pin_view = PINView(None)
    qtbot.addWidget(pin_view)

    qtbot.mouseClick(pin_view.btn_1, QtCore.Qt.LeftButton)
    qtbot.mouseClick(pin_view.btn_2, QtCore.Qt.LeftButton)
    qtbot.mouseClick(pin_view.btn_3, QtCore.Qt.LeftButton)
    qtbot.mouseClick(pin_view.btn_4, QtCore.Qt.LeftButton)
    qtbot.mouseClick(pin_view.enter_btn, QtCore.Qt.LeftButton)

    assert_screen_shows_and_get_new_screen(SelectTransactionView)
Exemple #15
0
def test_invalid_pin_entry(qtbot):
    _, terminal_status = set_up_accounts_and_terminal_status()
    terminal_status.pin_attempts = 2
    pin_view = PINView(None)
    qtbot.addWidget(pin_view)

    qtbot.mouseClick(pin_view.btn_9, QtCore.Qt.LeftButton)
    qtbot.mouseClick(pin_view.btn_9, QtCore.Qt.LeftButton)
    qtbot.mouseClick(pin_view.btn_9, QtCore.Qt.LeftButton)
    qtbot.mouseClick(pin_view.btn_9, QtCore.Qt.LeftButton)
    qtbot.mouseClick(pin_view.enter_btn, QtCore.Qt.LeftButton)

    assert_screen_shows_and_get_new_screen(WelcomeView)
def test_load_hdf5(qtbot):
    aw = ApplicationWindow()
    qtbot.addWidget(aw)
    logger.setup(aw._ui.log_text, aw)
    config.load_config()

    aw.hdf5_path = "/home/ubuntu/example-data/4DSTEM_FeRh_element.hdf5"
    enter()
    aw._ui.action_hdf5.trigger()
    assert logger.check_if_all_needed(Flags.files_loaded)
    aw.start_dbrowser()
    assert aw._ui.tabWidget.widget(1).findChild(QtWidgets.QComboBox,
                                                "colorMap").currentIndex() == 0
Exemple #17
0
def test_status_from_xml(qtbot):
    widget = Status.Status()
    qtbot.addWidget(widget)

    test_record_fname = "tests/data/Onshore_Industrial_Wind_Turbine_Locations_for_the_United_States_through_July2013.xml"
    test_record = etree.parse(test_record_fname)
    status = test_record.xpath("idinfo/status")[0]

    widget.from_xml(status)
    assert widget.findChild(QComboBox,
                            "fgdc_progress").currentText() == "Complete"
    assert widget.findChild(QComboBox,
                            "fgdc_update").currentText() == "none planned"
 def test_campaign_uri(self, qtbot):  # analysis:ignore
     widget = CommunityTab()
     widget.show()
     qtbot.addWidget(widget)
     test_uri = 'http://go.continuum.io/navigator-testing/'
     campaign_name = 'navigator-testing'
     valid_uri = (
         'http://go.continuum.io/navigator-testing/'
         '?utm_campaign=navigator-testing&'
         'utm_medium=in-app&utm_source=navigator'
     )
     utm_uri = widget.add_campaign(test_uri, campaign_name)
     assert utm_uri == valid_uri
Exemple #19
0
def test_daskflow(qtbot, simple_workflow):

    from pyqtgraph.flowchart import Node, Terminal

    # COREDUMPS HERE!
    a = Terminal(Node("test1"), "test1", "in")

    from xicam.gui.widgets.daskflow import DaskFlow

    df = DaskFlow()
    df.fromDask(simple_workflow)

    qtbot.addWidget(df)
Exemple #20
0
def test_clear_files(qtbot):
    aw = ApplicationWindow()
    qtbot.addWidget(aw)
    logger.setup(aw._ui.log_text, aw)

    aw.clear_files()
    assert aw._files_loaded == False
    with pytest.raises(AttributeError) as excinfo:
        aw._mib_path is None == True
        aw._dm3_path is None == True
        assert "self._mib_path and self._dm3_path have been deleted" in str(
            excinfo.value)
    assert aw._ui.mib_line.text() == ''
    assert aw._ui.dm3_line.text() == ''
def test_status__to_xml(qtbot):
    widget = Status.Status()
    qtbot.addWidget(widget)

    widget._to_xml  #(status)
    #assert type(progress) == 'lxml.etree._Element'
    widget.findChild(QComboBox, 'fgdc_progress').currentText()  # == 'Complete'
    widget.findChild(QComboBox,
                     'fgdc_update').currentText()  # == 'Continually'

    stat = widget._to_xml()

    assert etree.tostring(stat, pretty_print=True).decode() \
    == """<status>
Exemple #22
0
def test_useconstraints_to_xml(qtbot):
    widget = useconst.Useconst()
    qtbot.addWidget(widget)

    assert (
        widget.findChild(QPlainTextEdit, "fgdc_useconst").toPlainText() ==
        "None.  Users are advised to read the dataset's metadata thoroughly to understand appropriate use and data limitations."
    )

    uc = widget.to_xml()
    assert (
        etree.tostring(uc, pretty_print=True).decode() ==
        "<useconst>None.  Users are advised to read the dataset's metadata thoroughly to understand appropriate use and data limitations.</useconst>\n"
    )
Exemple #23
0
def test_status_to_xml(qtbot):
    widget = Status.Status()
    qtbot.addWidget(widget)

    widget.findChild(QComboBox, "fgdc_progress").currentText()
    widget.findChild(QComboBox, "fgdc_update").currentText()

    stat = widget.to_xml()

    assert (etree.tostring(stat, pretty_print=True).decode() == """<status>
  <progress>Complete</progress>
  <update>None planned</update>
</status>
""")
Exemple #24
0
def test_idfplus(qtbot):
    """Test for presence and type of main GUI components.
    """

    main_window = IDFPlus()
    qtbot.addWidget(main_window)

    assert isinstance(main_window.classTable, TableView)
    assert isinstance(main_window.commentView, UndoRedoTextEdit)
    assert isinstance(main_window.infoView, QTextEdit)
    assert isinstance(main_window.classTree, QTreeView)
    assert isinstance(main_window.logView, QPlainTextEdit)
    assert isinstance(main_window.undoView, QUndoView)
    assert isinstance(main_window.refView, QTreeView)
    assert isinstance(main_window.filterTreeBox, QLineEdit)
def test_contactinfo_to_xml(qtbot):
    widget = ContactInfo.ContactInfo()
    qtbot.addWidget(widget)

    widget.findChild(QLineEdit, 'fgdc_cntper').setText("Jay Diffendorfer")
    widget.findChild(QLineEdit, 'fgdc_cntpos').setText("")
    widget.findChild(QLineEdit, 'fgdc_cntvoice').setText("303-236-5369")
    widget.findChild(QLineEdit,
                     'fgdc_cntemail').setText("*****@*****.**")
    widget.findChild(QLineEdit, 'fgdc_postal').setText("80225")

    cntinfo = widget.to_xml()

    assert etree.tostring(cntinfo, pretty_print=True).decode() \
    == """<cntinfo>
Exemple #26
0
def test_validation(qtbot, mock):

    widget = MainWindow.PyMdWizardMainForm()
    qtbot.addWidget(widget)

    test_record_fname = "tests/data/USGS_ASC_PolarBears_FGDC.xml"
    mock.patch.object(QMessageBox, 'question',
                      return_value=QMessageBox.No)
    mock.patch.object(QMessageBox, 'warning',
                      return_value=QMessageBox.Cancel)
    mock.patch.object(QMessageBox, 'information',
                      return_value=QMessageBox.Cancel)
    widget.open_file(test_record_fname)
    widget.validate()
    assert len(widget.error_list.errors) == 1
Exemple #27
0
def test_descriptor__from_xml(qtbot):
    widget = Descriptor.Descriptor()
    qtbot.addWidget(widget)

    test_record_fname = "tests/data/GenericFGDCTemplate_FGDCtemp.xml"
    test_record = etree.parse(test_record_fname)
    descript = test_record.xpath("idinfo/descript")[0]

    widget._from_xml(descript)
    assert widget.findChild(QPlainTextEdit,
                            "fgdc_abstract").toPlainText() == 'Abstract MH'
    assert widget.findChild(QPlainTextEdit,
                            "fgdc_purpose").toPlainText() == 'Purpose MH'
    assert widget.findChild(
        QPlainTextEdit,
        "fgdc_supplinf").toPlainText() == 'Supplemental Information MH'
def test_library_widget(qtbot):
    w = QWidget()
    w.setLayout(QHBoxLayout())

    l = LibraryWidget()
    for i in range(15):
        l.add_image(np.random.random((1000, 1000)), f"Sample {i+1}")

    s = QSlider()
    s.valueChanged.connect(partial(l.set_slice, axis="E"))

    w.layout().addWidget(l)
    w.layout().addWidget(s)

    w.show()

    qtbot.addWidget(w)
def test_contactinfo_from_xml(qtbot):
    widget = ContactInfo.ContactInfo()
    qtbot.addWidget(widget)

    test_record_fname = "tests/data/Onshore_Industrial_Wind_Turbine_Locations_for_the_United_States_through_July2013.xml"
    test_record = etree.parse(test_record_fname)
    contact = test_record.xpath("idinfo/ptcontac/cntinfo")[0]

    widget.from_xml(contact)
    assert widget.findChild(QLineEdit,
                            'fgdc_cntper').text() == "Jay Diffendorfer"
    assert widget.findChild(QLineEdit, 'fgdc_cntpos').text() == ""
    assert widget.findChild(QLineEdit,
                            'fgdc_cntvoice').text() == "303-236-5369"
    assert widget.findChild(
        QLineEdit, 'fgdc_cntemail').text() == "*****@*****.**"
    assert widget.findChild(QLineEdit, 'fgdc_postal').text() == "80225"
Exemple #30
0
def test_descriptor__to_xml(qtbot):
    widget = Descriptor.Descriptor()
    qtbot.addWidget(widget)

    widget._to_xml  #(use_const)
    widget.findChild(
        QPlainTextEdit,
        "fgdc_abstract").setPlainText("This is the description portion")
    widget.findChild(QPlainTextEdit, "fgdc_purpose").setPlainText(
        "The purpose and appropriate use of the data is to...")
    widget.findChild(QPlainTextEdit, "fgdc_supplinf").setPlainText(
        "Any additional supplemental info is this,")

    mdDescript = widget._to_xml()

    assert etree.tostring(mdDescript, pretty_print=True).decode() \
    == """<descript>
Exemple #31
0
def test_datacredit__to_xml(qtbot):
    widget = DataCredit.DataCredit()
    qtbot.addWidget(widget)

    #test_record_fname = "tests/data/Onshore_Industrial_Wind_Turbine_Locations_for_the_United_States_through_July2013.xml"
    #test_record = etree.parse(test_record_fname)
    #use_const = test_record.xpath("idinfo/useconst")[0]

    widget._to_xml  #(use_const)
    widget.findChild(
        QPlainTextEdit,
        "fgdc_datacred").setPlainText("This is who should be credited.")

    dc = widget._to_xml()

    assert etree.tostring(dc, pretty_print=True).decode() \
    == """<datacred>This is who should be credited.</datacred>
def test_library_view(qtbot, random_data_catalog):
    from xicam.plugins.catalogplugin import CatalogModel
    model = CatalogModel(random_data_catalog)

    w = QWidget()
    w.setLayout(QHBoxLayout())

    l = LibraryView(model, slice={"E": 0})

    s = QSlider()
    s.valueChanged.connect(partial(l.set_slice, axis="E"))

    w.layout().addWidget(l)
    w.layout().addWidget(s)

    w.show()

    qtbot.addWidget(w)
def qcombobox_bot(qtbot):
    widget = QComboBox()
    qtbot.addWidget(widget)
    return qtbot, widget
Exemple #34
0
def setup_findinfiles(qtbot, *args, **kwargs):
    """Set up find in files widget."""
    widget = FindInFilesWidget(None, *args, **kwargs)
    qtbot.addWidget(widget)
    return widget
Exemple #35
0
def botinlinefloat(qtbot):
    dialog = NumpyArrayDialog(inline=True, force_float=True)
    qtbot.addWidget(dialog)
    dialog.show()
    return qtbot, dialog, dialog.array_widget
Exemple #36
0
def botarray(qtbot):
    dialog = NumpyArrayDialog(inline=False)
    qtbot.addWidget(dialog)
    dialog.show()
    return qtbot, dialog, dialog.array_widget