Ejemplo n.º 1
0
    def test_dtype_function_calls(self):
        """
        Tests the dtype() function call for the data types stored in the array.
        """
        # Set up
        direc = Direction.Output
        validator = NullValidator()

        # Create float array
        float_input_values = [1.1, 2.5, 5.6, 4.6, 9.0, 6.0]
        float_arr = FloatArrayProperty("floats", float_input_values, validator,
                                       direc)

        # Create int array
        int_input_values = [1, 2, 5, 4, 9, 6]
        int_arr = IntArrayProperty("integers", int_input_values, validator,
                                   direc)

        # Create string array
        str_input_values = ["a", "b", "c", "d", "e"]
        str_arr = StringArrayProperty("letters", str_input_values, validator,
                                      direc)

        # Test
        self.assertEquals(float_arr.dtype(), "f")
        self.assertEquals(int_arr.dtype(), "i")
        self.assertEquals(str_arr.dtype(), "S1")
Ejemplo n.º 2
0
 def test_name_validator_direction_constructor_gives_correct_object(self):
     """
         Test the constructor that takes a name, validator & direction
     """
     name = "numbers"
     direc = Direction.Output
     validator = NullValidator()
     arr = FloatArrayProperty(name, validator, direc)
     self._check_object_attributes(arr, name, direc)
     self.assertEquals(arr.isValid, "")
Ejemplo n.º 3
0
 def test_name_values_from_array_validator_direction_constructor_gives_correct_object(
         self):
     """
         Test the constructor that takes a name, values from python object,
         validator & direction
     """
     name = "numbers"
     direc = Direction.Output
     validator = NullValidator()
     input_values = np.array([1.1, 2.5, 5.6, 4.6, 9.0, 6.0])
     arr = FloatArrayProperty(name, input_values, validator, direc)
     self._check_object_attributes(arr, name, direc, length=6)
Ejemplo n.º 4
0
 def test_name_string_values_validator_direction_constructor_gives_correct_object(
         self):
     """
         Test the constructor that takes a name, values as string, validator & direction
     """
     name = "numbers"
     direc = Direction.Output
     validator = NullValidator()
     values_str = "1.345,34.2,5345.3,4,5.3948"
     arr = FloatArrayProperty(name, values_str, validator, direc)
     self._check_object_attributes(arr, name, direc, length=5)
     self.assertEquals(arr.isValid, "")
     values = arr.value
     self.assertTrue(isinstance(values, np.ndarray))
Ejemplo n.º 5
0
    def test_construct_numpy_array_with_given_dtype_int(self):
        # Set up
        direc = Direction.Output
        validator = NullValidator()

        # Create int array
        int_input_values = [1, 2, 5, 4, 9, 6]
        int_arr = IntArrayProperty("integers", int_input_values, validator,
                                   direc)

        # Use the returned dtype() to check it works with numpy arrays
        x = np.arange(1, 10, dtype=int_arr.dtype())
        self.assertIsInstance(x, np.ndarray)
        self.assertEquals(x.dtype, int_arr.dtype())
Ejemplo n.º 6
0
    def test_construct_numpy_array_with_given_dtype_float(self):
        # Set up
        direc = Direction.Output
        validator = NullValidator()

        # Create float array
        float_input_values = [1.1, 2.5, 5.6, 4.6, 9.0, 6.0]
        float_arr = FloatArrayProperty("floats", float_input_values, validator,
                                       direc)

        # Use the returned dtype() to check it works with numpy arrays
        x = np.arange(1, 10, dtype=float_arr.dtype())
        self.assertIsInstance(x, np.ndarray)
        self.assertEquals(x.dtype, float_arr.dtype())
Ejemplo n.º 7
0
    def test_construct_numpy_array_with_given_dtype_string(self):
        # Set up
        direc = Direction.Output
        validator = NullValidator()

        # Create string array
        str_input_values = ["hello", "testing", "word", "another word", "word"]
        str_arr = StringArrayProperty("letters", str_input_values, validator,
                                      direc)

        # Use the returned dtype() to check it works with numpy arrays
        x = np.array(str_input_values, dtype=str_arr.dtype())
        self.assertIsInstance(x, np.ndarray)
        # Expect longest string to be returned
        self.assertEquals(x.dtype, "S12")