コード例 #1
0
    def test_show_interface_return(self):
        """
        Ensure the show_interface method returns a widget of type HBox
        """
        interface = PlotInterface()
        widget = interface.show_interface()

        self.assertIsInstance(widget, widgets.widgets.widget_box.HBox)
コード例 #2
0
ファイル: plotter.py プロジェクト: PaNOSC-ViNYL/McStasScript
def interface(data):
    """
    Shows plot interface to explore data

    Parameters
    ----------
    data : List of McStasData objects
    """

    interface = PlotInterface(data)
    return interface.show_interface()
コード例 #3
0
    def test_initialization_without_data(self):
        """
        Initialize PlotterInterface without arguments
        """

        interface = PlotInterface()
        self.assertEqual(interface.data, None)
コード例 #4
0
    def test_initialization_with_data(self):
        """
        Initialize PlotterInterface with data
        """
        data = fake_data()
        interface = PlotInterface(data)

        self.assertEqual(len(interface.data), 3)
        self.assertEqual(interface.data[0].Intensity[5], 5)
        self.assertEqual(interface.data[1].Intensity[2, 3], 13)
コード例 #5
0
    def test_set_current_monitor(self):
        """
        Check monitor can be set and that error occurs if wrong name given
        """

        interface = PlotInterface(fake_data())
        interface.show_interface()

        interface.set_current_monitor("test a component")
        self.assertEqual(interface.current_monitor, "test a component")

        with self.assertRaises(NameError):
            interface.set_current_monitor("component that doesnt exist")
コード例 #6
0
    def test_set_data(self):
        """
        Initialize PlotterInterface without data, add later and ensure
        monitor_dropdown received the data and applied it to widget options.

        Furthermore the widget options should be made unique as there are
        two identical monitors in the fake data.
        """

        interface = PlotInterface()
        self.assertEqual(interface.data, None)

        interface.show_interface() # Needed to set up monitor_dropdown

        interface.set_data(fake_data())
        self.assertEqual(len(interface.data), 3)
        self.assertEqual(interface.data[0].Intensity[5], 5)
        self.assertEqual(interface.data[1].Intensity[2, 3], 13)

        mon_drop = interface.monitor_dropdown
        self.assertEqual(len(mon_drop.data), 3)
        self.assertEqual(mon_drop.data[0].Intensity[5], 5)
        self.assertEqual(mon_drop.data[1].Intensity[2, 3], 13)

        self.assertEqual(mon_drop.widget.options[0], "component for 1d")
        self.assertEqual(mon_drop.widget.options[1], "test a component")

        # The last monitor is identical to the second, so the name is modified
        self.assertEqual(mon_drop.widget.options[2], "test a component_1")
コード例 #7
0
    def test_set_colormap(self):
        """
        Check that set_colormap works, even through widget
        """
        interface = PlotInterface()
        interface.show_interface()

        interface.set_colormap("hot")
        self.assertEqual(interface.colormap, "hot")

        colormap_dropdown = ColormapDropdown(interface.set_colormap)

        fake_change = FakeChange(new="Purples")
        colormap_dropdown.update_cmap(fake_change)
        self.assertEqual(interface.colormap, "Purples")
コード例 #8
0
    def test_set_orders_of_mag(self):
        """
        Check that set orders of mag works, even through widget
        """
        interface = PlotInterface()
        interface.show_interface()

        interface.set_orders_of_mag(37)
        self.assertEqual(interface.orders_of_mag, 37)

        log_orders_of_mag = OrdersOfMagField(interface.set_orders_of_mag)

        fake_change = FakeChange(new=42)

        log_orders_of_mag.update(fake_change)
        self.assertEqual(interface.orders_of_mag, 42)
コード例 #9
0
    def test_set_log_mode(self):
        """
        Check that set_log_mode works, even through widget
        """

        interface = PlotInterface()
        interface.show_interface()

        self.assertFalse(interface.log_mode)
        interface.set_log_mode(True)
        self.assertTrue(interface.log_mode)

        log_checkbox = LogCheckbox(interface.log_mode, interface.set_log_mode)

        fake_change = FakeChange(new=False)

        log_checkbox.update(fake_change)
        self.assertFalse(interface.log_mode)