def test_decode(self):
        """Ensures that a simple model can be decoded successfully from JSON."""
        # Arrange
        v = '{"asset": {"version": "2.1"}, "buffers": [{ "uri": "triangle.bin", "byteLength": 44 }]}'

        # Act
        model = GLTFModel.from_json(v)

        # Assert
        self.assertEqual(model, GLTFModel(asset=Asset(version='2.1'), buffers=[Buffer(uri='triangle.bin', byteLength=44)]))
Beispiel #2
0
    def test_decode_missing_required_property(self):
        """
        Ensures that an error is raised when decoding a model from JSON if any required properties are missing.
        In this case, the version property on the asset is missing.
        """
        # Arrange
        v = '{}'

        # Act/Assert
        with self.assertRaisesRegex(TypeError, 'version.*Asset'):
            _ = GLTFModel.from_json(v)
    def test_decode_missing_required_property(self):
        """
        Ensures that a warning is emitted when decoding a model from JSON if any required properties are missing.
        In this case, the "asset" property on the model is missing.
        """
        # Arrange
        v = '{}'

        # Act/Assert
        with self.assertWarnsRegex(RuntimeWarning, "non-optional type asset"):
            _ = GLTFModel.from_json(v)