Exemple #1
0
 def test_init_with_curves_without_meta(self):
     """Test GwyGraphModel constructor with default meta
     """
     graph = GwyGraphModel(curves=self.test_curves)
     self.assertEqual(graph.curves, self.test_curves)
     self.assertDictEqual(
         graph.meta, {
             'ncurves': 2,
             'title': '',
             'top_label': '',
             'left_label': '',
             'right_label': '',
             'bottom_label': '',
             'x_unit': '',
             'y_unit': '',
             'x_min': None,
             'x_min_set': False,
             'x_max': None,
             'x_max_set': False,
             'y_min': None,
             'y_min_set': False,
             'y_max': None,
             'y_max_set': False,
             'x_is_logarithmic': False,
             'y_is_logarithmic': False,
             'label.visible': True,
             'label.has_frame': True,
             'label.reverse': False,
             'label.frame_thickness': 1,
             'label.position': 0,
             'grid-type': 1
         })
Exemple #2
0
    def _dump_graphs(cls, gwyfile):
        """Dump all graphs from Gwyfile instance

        Args:
            gwyfile: Gwyfile object

        Returns
            graphs: list of GwyGraphModel objects

        """

        graph_ids = cls._get_graph_ids(gwyfile)

        # Create list of tuples
        # First element of each tuple is a key for GwyGraphModel data item
        # Second element of each tuple is a key for boolean item
        #     (wheter the graph should be displayed in a window when the file
        #      is loaded)
        graph_keys = [("/0/graph/graph/{:d}".format(graph_id),
                       "/0/graph/graph/{:d}/visible".format(graph_id))
                      for graph_id in graph_ids]

        # Create list of tuples (<cdata GwyGraphModel*>, visibility_flag)
        # First element is <cdata GwyGraphModel*> object
        # Second element is its visibility flag (boolean)
        gwygraphmodels = [(gwyfile.get_gwyitem_object(key[0]),
                           gwyfile.get_gwyitem_bool(key[1]))
                          for key in graph_keys]
        graphs = []

        for gwygraphmodel in gwygraphmodels:
            graph = GwyGraphModel.from_gwy(gwygraphmodel[0])
            graph.visible = gwygraphmodel[1]
            graphs.append(graph)
        return graphs
Exemple #3
0
    def test_bottom_label_field_is_not_empty(self):
        """
        'bottom_label' field in graphmodel object is not empty
        """

        self.mock_lib.gwyfile_object_graphmodel_get.side_effect = (
            self._bottom_label_is_not_empty)
        meta = GwyGraphModel._get_meta(self.gwygraphmodel)
        self.assertEqual(meta['bottom_label'], "test bottom label")
Exemple #4
0
    def test_y_unit_field_is_empty(self):
        """
        'y_unit' field in graphmodel object is empty
        """

        self.mock_lib.gwyfile_object_graphmodel_get.side_effect = (
            self._y_unit_is_empty)
        meta = GwyGraphModel._get_meta(self.gwygraphmodel)
        self.assertEqual(meta['y_unit'], '')
Exemple #5
0
    def test_title_field_is_not_empty(self):
        """
        'title' field in graphmodel object is not empty
        """

        self.mock_lib.gwyfile_object_graphmodel_get.side_effect = (
            self._title_is_not_empty)
        meta = GwyGraphModel._get_meta(self.gwygraphmodel)
        self.assertEqual(meta['title'], "test title")
Exemple #6
0
    def test_getting_number_of_curves(self):
        """
        Test getting number of curves from graphmodel object
        """

        self.mock_lib.gwyfile_object_graphmodel_get.side_effect = (
            self._get_number_of_curves)
        meta = GwyGraphModel._get_meta(self.gwygraphmodel)
        self.assertEqual(meta['ncurves'], 3)
Exemple #7
0
    def test_get_curves_array(self):
        """
        Get array of curves (GwyfileObjects) from graphmodel object
        """

        self.mock_lib.gwyfile_object_graphmodel_get.side_effect = (
            self._side_effect)
        curves = GwyGraphModel._get_curves(self.gwygraphmodel, self.ncurves)
        self.assertListEqual(curves, list(self.curves_array))
Exemple #8
0
    def test_y_max_set_is_false(self):
        """
        Check metadata dictionary if 'y_max_set' is False
        """

        self.mock_lib.gwyfile_object_graphmodel_get.side_effect = (
            self._y_max_set_is_false)
        meta = GwyGraphModel._get_meta(self.gwygraphmodel)
        self.assertIs(meta['y_max_set'], False)
        self.assertIsNone(meta['y_max'])
Exemple #9
0
    def test_y_max_set_is_true(self):
        """
        Check metadata dictionary if 'y_max_set' is True
        """

        self.mock_lib.gwyfile_object_graphmodel_get.side_effect = (
            self._y_max_set_is_true)
        meta = GwyGraphModel._get_meta(self.gwygraphmodel)
        self.assertIs(meta['y_max_set'], True)
        self.assertEqual(meta['y_max'], 0.)
Exemple #10
0
    def test_label_reverse_is_false(self):
        """
        'label.reverse' field is False
        """

        self.mock_lib.gwyfile_object_graphmodel_get.side_effect = (
            self._label_reverse)

        self.label_reverse = False

        meta = GwyGraphModel._get_meta(self.gwygraphmodel)
        self.assertIs(meta['label.reverse'], False)
Exemple #11
0
    def test_label_has_frame_is_true(self):
        """
        'label.has_frame' field is True
        """

        self.mock_lib.gwyfile_object_graphmodel_get.side_effect = (
            self._label_has_frame)

        self.label_has_frame = True

        meta = GwyGraphModel._get_meta(self.gwygraphmodel)
        self.assertIs(meta['label.has_frame'], True)
Exemple #12
0
    def test_y_is_logarithmic_false(self):
        """
        'y_is_logarithmic' field is False
        """

        self.mock_lib.gwyfile_object_graphmodel_get.side_effect = (
            self._y_is_logarithmic)

        self.y_is_logarithmic = False

        meta = GwyGraphModel._get_meta(self.gwygraphmodel)
        self.assertIs(meta['y_is_logarithmic'], False)
Exemple #13
0
    def test_x_is_logarithmic_true(self):
        """
        'x_is_logarithmic' field is True
        """

        self.mock_lib.gwyfile_object_graphmodel_get.side_effect = (
            self._x_is_logarithmic)

        self.x_is_logarithmic = True

        meta = GwyGraphModel._get_meta(self.gwygraphmodel)
        self.assertIs(meta['x_is_logarithmic'], True)
Exemple #14
0
    def test_grid_type(self):
        """
        Check 'grid-type' field in metadata dictionary
        """

        self.mock_lib.gwyfile_object_graphmodel_get.side_effect = (
            self._grid_type)

        self.grid_type = 1

        meta = GwyGraphModel._get_meta(self.gwygraphmodel)
        self.assertEqual(meta['grid-type'], self.grid_type)
Exemple #15
0
    def test_label_position(self):
        """
        Check 'label.position' field in metadata dictionary
        """

        self.mock_lib.gwyfile_object_graphmodel_get.side_effect = (
            self._label_position)

        self.label_position = 1

        meta = GwyGraphModel._get_meta(self.gwygraphmodel)
        self.assertEqual(meta['label.position'], self.label_position)
Exemple #16
0
    def test_label_frame_thickness(self):
        """
        Check 'label.frame_thickness' field in metadata dictionary
        """

        self.mock_lib.gwyfile_object_graphmodel_get.side_effect = (
            self._label_frame_thickness)

        self.label_frame_thickness = 1

        meta = GwyGraphModel._get_meta(self.gwygraphmodel)
        self.assertEqual(meta['label.frame_thickness'],
                         self.label_frame_thickness)
Exemple #17
0
    def test_arg_passing_to_other_methods(self, mock_get_meta, mock_get_curves,
                                          mock_GwyGraphCurve,
                                          mock_GwyGraphModel):
        """
        """
        gwygraphmodel = Mock()
        test_meta = {'ncurves': 2}
        test_gwycurves = [Mock(), Mock()]
        mock_get_meta.return_value = test_meta
        mock_get_curves.return_value = test_gwycurves
        graphmodel = Mock(spec=GwyGraphModel)
        mock_GwyGraphModel.return_value = graphmodel

        graph = GwyGraphModel.from_gwy(gwygraphmodel)

        # get meta data from <GwyGraphModel*> object
        mock_get_meta.assert_has_calls([call(gwygraphmodel)])

        # get list of <GwyGraphModelCurve*> objects
        mock_get_curves.assert_has_calls(
            [call(gwygraphmodel, test_meta['ncurves'])])

        # create list of GwyGraphCurves instances
        mock_GwyGraphCurve.from_gwy.assert_has_calls(
            [call(gwycurve) for gwycurve in test_gwycurves])

        # create GwyGraphModel instance
        mock_GwyGraphModel.assert_has_calls([
            call(curves=[
                mock_GwyGraphCurve.from_gwy.return_value
                for gwycurve in test_gwycurves
            ],
                 meta=test_meta)
        ])

        # return GwyGraphModel instance
        self.assertEqual(graph, graphmodel)
Exemple #18
0
 def test_init_with_curves_and_meta(self):
     """Test GwyGraphModel constructor if meta is defined
     """
     graph = GwyGraphModel(curves=self.test_curves, meta=self.test_meta)
     self.assertEqual(graph.curves, self.test_curves)
     self.assertDictEqual(graph.meta, self.test_meta)