Esempio n. 1
0
 def test_return_double_value_if_data_item_is_found(self):
     """ Return double value if data item is found """
     valuep = ffi.new("double*", 1.)
     self.gwyfile._get_gwyitem_value.return_value = valuep[0]
     actual_return = self.gwyfile.get_gwyitem_double(
         self.gwyfile, self.item_key)
     self.assertEqual(actual_return, 1.)
Esempio n. 2
0
 def test_return_int32_value_if_data_item_is_found(self):
     """ Return int32 value if data item is found """
     valuep = ffi.new("int32_t*", 1)
     self.gwyfile._get_gwyitem_value.return_value = valuep[0]
     actual_return = self.gwyfile.get_gwyitem_int32(self.gwyfile,
                                                    self.item_key)
     self.assertEqual(actual_return, 1)
Esempio n. 3
0
 def test_return_string_value_if_data_item_is_found(self):
     """ Return data item string value if data item is found """
     cvalue = ffi.new("char[]", b'Title')
     self.gwyfile._get_gwyitem_value.return_value = cvalue
     actual_return = self.gwyfile.get_gwyitem_string(
         self.gwyfile, self.item_key)
     self.assertEqual(actual_return, 'Title')
Esempio n. 4
0
 def test_return_True_if_data_item_value_is_True(self):
     """ Return True if data item value is True """
     truep = ffi.new("bool*", True)
     self.gwyfile._get_gwyitem_value.return_value = truep[0]
     actual_return = self.gwyfile.get_gwyitem_bool(self.gwyfile,
                                                   self.item_key)
     self.assertIs(actual_return, True)
Esempio n. 5
0
 def test_return_False_if_data_item_value_is_False(self):
     """ Return Flase if data item value is False """
     falsep = ffi.new("bool*", False)
     self.gwyfile._get_gwyitem_value.return_value = falsep[0]
     actual_return = self.gwyfile.get_gwyitem_bool(self.gwyfile,
                                                   self.item_key)
     self.assertIs(actual_return, False)
Esempio n. 6
0
    def test_check_top_level_object_of_c_gwyfile(self, mock_lib):
        """Raise GwyfileError exception if top-level object is not
        'GwyContainer' C string
        """

        c_gwyfile = Mock()
        test_name = ffi.new("char[]", b"non-GwyContainer")
        mock_lib.gwyfile_object_name.return_value = test_name
        self.assertRaises(GwyfileError, Gwyfile, c_gwyfile)
Esempio n. 7
0
    def test_attribute_of_GwyFile_instance(self, mock_lib):
        """
        Create self.c_gwyfile attribute
        """

        c_gwyfile = Mock()
        test_name = ffi.new("char[]", b"GwyContainer")
        mock_lib.gwyfile_object_name.return_value = test_name
        test_instance = Gwyfile(c_gwyfile)
        self.assertIs(c_gwyfile, test_instance.c_gwyfile)
Esempio n. 8
0
 def _side_effect(self, *args):
     """ First argument is GwyContainer
         Second argument is name of the file
         Third argument location of the error
     """
     self.assertEqual(args[0], self.gwycontainer)
     self.assertEqual(ffi.string(args[1]), self.filename.encode('utf-8'))
     self.assertEqual(ffi.typeof(args[2]),
                      ffi.typeof(ffi.new("GwyfileError**")))
     return ffi.cast("bool", True)
Esempio n. 9
0
 def test_c_error_msg_is_non_NULL(self, mock_GwyfileError):
     """Test GwyfileError args if error message is not empty
     """
     c_error_msg = ffi.new("char[]", b'Test error message')
     GwyfileErrorCMsg(c_error_msg)
     mock_GwyfileError.assert_has_calls([call('Test error message')])