Beispiel #1
0
    def test_json_representation_is_correct(self):
        """Verify that the JSON repr of float properties is correct."""

        prop = properties.FloatProperty('name', 5.123)
        self.assertEquals(json.loads(json.dumps(prop, cls=JSONObjectEncoder)),
                          5.123)

        prop = properties.FloatProperty('name', -73.503)
        self.assertEquals(json.loads(json.dumps(prop, cls=JSONObjectEncoder)),
                          -73.503)
Beispiel #2
0
    def test_yaml_representation_has_all_expected_fields(self):
        """Verify that the YAML representation of float properties is ok."""

        prop = properties.FloatProperty('name', 5)
        string = yaml.dump(prop)
        data = yaml.load(string)
        self.assertTrue(isinstance(data, float))
        self.assertEqual(data, 5.0)

        prop = properties.FloatProperty('name', 32.37123)
        string = yaml.dump(prop)
        data = yaml.load(string)
        self.assertTrue(isinstance(data, float))
        self.assertEqual(data, 32.37123)
    def float_property_in_data(self, context, object_entry, prop_def, data):
        """Return a float property from an object properties dictionary."""

        if not isinstance(data, float):
            context.error(
                FloatPropertyValueInvalidError(context, prop_def.name, data))

        return properties.FloatProperty(prop_def.name, data)
Beispiel #4
0
    def test_equality_operator_is_false_for_different_property_types(self):
        """Verify == is false when comparing properties of different types."""

        test_properties = [
            properties.IntProperty('name', 5),
            properties.BooleanProperty('name', True),
            properties.FloatProperty('name', 5.0),
            properties.TextProperty('name', '5'), 1, 2.0, 'some text'
        ]

        for p1, p2 in itertools.permutations(test_properties, 2):
            self.assertNotEqual(p1, p2)
            self.assertFalse(p1 == p2)
Beispiel #5
0
    def test_constructor_sets_property_name_and_value_properly(self):
        """Verify that the constructor sets property name and value."""

        test_input = [
            ('property1', 0.1),
            ('property2', 1.2),
            ('property3', 2.3),
        ]

        for name, value in test_input:
            float_property = properties.FloatProperty(name, value)
            self.assertEqual(float_property.name, name)
            self.assertEqual(float_property.value, value)
Beispiel #6
0
    def test_min_and_max_double_values_are_set_correctly(self):
        """Verify that minimum and maximum double values are supported."""

        test_input = [
            (1.79769313486e+308, '1.79769313486e+308'),
            (2.22507385851e-308, '2.22507385851e-308'),
            (-1.79769313486e+308, '-1.79769313486e+308'),
            (-2.22507385851e-308, '-2.22507385851e-308'),
        ]

        for value, str_value in test_input:
            float_property = properties.FloatProperty('property name', value)
            self.assertEqual(float_property.value, value)
            self.assertEqual(str(float_property.value), str_value)
Beispiel #7
0
    def test_input_value_is_converted_to_float(self):
        """Verify that the input value is converted to an float."""

        test_input = [15, 15.0, 15.000, '15', '15.000', True, False]

        for value in test_input:
            float_property = properties.FloatProperty('name', value)
            self.assertTrue(isinstance(float_property.value, float))
            self.assertEqual(type(float_property.value), type(15.0))
            if isinstance(value, bool):
                if value is True:
                    self.assertEqual(float_property.value, 1.0)
                else:
                    self.assertEqual(float_property.value, 0.0)
            else:
                self.assertEqual(float_property.value, 15.0)
Beispiel #8
0
    def setUp(self):
        """Initialise helper variables for the tests."""

        self.test_input = [
            ('hash1', '5e27f17c-ff22-4c49-82d9-6549f2800d1a',
             objects.ObjectClass('someclass', []), []),
            ('hash2', 'ad791799-4c3a-4cac-a07d-43493baab121',
             objects.ObjectClass('someclass', []), [
                 properties.TextProperty('title', 'Title'),
                 properties.TextProperty('info', 'Info'),
                 properties.FloatProperty('amount', 237.5),
                 properties.BooleanProperty('important', False),
                 properties.IntProperty('count', 5),
                 properties.TimestampProperty('date', '1377703755 +0100'),
                 properties.ReferenceProperty(
                     'others',
                     set([
                         references.Reference('a', None, None),
                         references.Reference('b', None, None),
                         references.Reference('c', None, None),
                     ])),
                 properties.ListProperty('tags', ['tag-1', 'tag-2', 'tag-3']),
             ]),
        ]