Exemplo n.º 1
0
    def test_construct_plot(self, _, __, mock_dashapp):
        """
        Test: dashapp object is returned
        When: called with self.create_trace_list() and Layout().layout
        """
        actual = PlotFactory().create_plot(plot_meta_file_location=MockPlotVariables().plot_meta_file_location,
                                           data=MockPlotVariables().raw_multi_single_data_dataframe,
                                           figure_name=MockPlotVariables().plot_name)

        mock_dashapp.assert_called_once()

        self.assertEqual('Instrument_Run_number', actual.app_id)
Exemplo n.º 2
0
    def test_extract_layout(self, mock_rpmd):
        """
        Test: extract_layout is called within Layout() returning layout values in dictionary only
        When: mode and plot values exist in dict returned by read_plot_meta_data()
        """

        mock_rpmd.return_value = MockPlotVariables().raw_interpreted_layout

        actual = Layout(MockPlotVariables().raw_interpreted_layout,
                        'Instrument_Run_Number')._extract_layout()

        self.assertIsInstance(actual, dict)
        self.assertEqual(actual, MockPlotVariables().processed_layout)
Exemplo n.º 3
0
 def test_str_to_class(self):
     """
     Test: _str_to_class() converts string to class object
     When: called within create_trace()
     """
     actual = MockPlotVariables().trace_object._str_to_class('Scattergl')
     self.assertIsInstance(actual, type)
Exemplo n.º 4
0
    def test_read_plot_meta_data(self, mock_interpreter):
        """
        Test: read_plot_meta_data is called within Layout()
        When: Layout().extract_layout() is called with meta_file_location
        """
        mock_interpreter.return_value = MockPlotVariables(
        ).raw_interpreted_layout

        actual = Layout(MockPlotVariables().plot_meta_file_location,
                        'Instrument_Run_Number')._read_plot_meta_data()

        # assert that interpreter has been called with correct argument
        mock_interpreter.assert_called_with(
            MockPlotVariables().plot_meta_file_location)

        # return value assertions
        self.assertIsInstance(actual, dict)
        self.assertEqual(actual, MockPlotVariables().raw_interpreted_layout)
Exemplo n.º 5
0
    def test_create_trace(self):
        """
        Test: create_trace returns a plotly graph object of type Scattergl
        When: called by Trace class initialisation
        """

        actual = MockPlotVariables().trace_object.trace

        self.assertIsInstance(actual, plotly.graph_objs.Scattergl)
Exemplo n.º 6
0
    def test_get_trace_list(self, mock_layout, _):
        """
        Test: create_trace_list is called within TestPlotFactory().create_plot()
        When: trace_list = []
        """
        mock_layout.return_value.mode = PropertyMock("mock_mode")
        mock_layout.return_value.plot_type = PropertyMock("mock_plot_type")
        layout = mock_layout

        # Assert that a list of trace object is returned
        actual = PlotFactory().create_trace_list(MockPlotVariables().indexed_single_multi_raw_data_dataframe, layout)
        self.assertIsInstance(actual, list)  # is list
        self.assertEqual(len(actual), 2)
Exemplo n.º 7
0
    def test_create_dashapp(self, mock_dashapp):
        """
        Test:create_dashapp() is called returning an instance of DashApp object
        When: called with figure and app_id by DashApp()
        """
        mock_dash_obj = Mock()
        mock_dashapp.return_value = mock_dash_obj
        # Assert a DashApp is returned
        DashApp(self.figure, MockPlotVariables().plot_name)
        mock_dashapp.assert_called_once()

        # self.assertEqual(mock_dash_obj, "Div([Div(Graph(id='Instrument_Run_number'))])")
        self.assertEqual('Div', type(mock_dash_obj.layout).__name__)
        self.assertEqual("[Div(Graph(id='Instrument_Run_number'))]",
                         str(mock_dash_obj.layout.__dict__['children']))
Exemplo n.º 8
0
    def test_trace_dict_error_bars_set_false(self):
        """
        Test: trace_dict() returns a dict in expected trace format without error_bars
        When: called with dataframe and error_bars=False
        """
        actual = MockPlotVariables().trace_object.trace_dict(
            MockPlotVariables().indexed_multi_single_raw_data_dataframe, False)

        expected = MockPlotVariables().trace_multi_single_error_y_not_visible

        self.assertEqual(len(actual), len(expected))  # Length of dictionaries
        self.assertEqual(actual['error_y'], expected['error_y'])  # Compare nested dictionary
        self.assertEqual(actual.keys(), expected.keys())  # Compare dictionary keys
        for key, value in actual.items():
            if isinstance(value, pandas.Series):
                self.assertTrue(value.equals(expected[key]))
            else:
                self.assertEqual(value, expected[key])
        self.assertIsInstance(actual, dict)