File: test_lineset.py

package info (click to toggle)
pycollada 0.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,116 kB
  • sloc: xml: 11,085; python: 6,859; makefile: 87
file content (63 lines) | stat: -rw-r--r-- 2,746 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import numpy
from numpy.testing import assert_array_equal

import collada
from collada.util import unittest
from collada.xmlutil import etree
from collada.common import DaeIncompleteError

fromstring = etree.fromstring
tostring = etree.tostring


class TestLineset(unittest.TestCase):

    def setUp(self):
        self.dummy = collada.Collada(validate_output=True)

    def test_lineset_construction(self):
        # An empty sources dict should raise an exception.
        with self.assertRaises(DaeIncompleteError) as e:
            collada.lineset.LineSet({}, None, None)
        self.assertIn("at least one", e.exception.msg)

        # As should passing one without VERTEX defined as a key.
        with self.assertRaises(DaeIncompleteError) as e:
            collada.lineset.LineSet({"a": []}, None, None)
        self.assertIn("requires vertex", e.exception.msg)

        # Adding an input list with vertex defined, but empty should raise an error.
        with self.assertRaises(DaeIncompleteError) as e:
            collada.lineset.LineSet({'VERTEX': []}, None, None)
        self.assertIn("requires vertex", e.exception.msg)

    def test_empty_lineset_saving(self):
        linefloats = [1, 1, -1, 1, -1, -1, -1, -0.9999998, -1, -0.9999997, 1, -1, 1, 0.9999995, 1, 0.9999994, -1.000001, 1]
        linefloatsrc = collada.source.FloatSource("mylinevertsource", numpy.array(linefloats), ('X', 'Y', 'Z'))
        geometry = collada.geometry.Geometry(self.dummy, "geometry0", "mygeometry", [linefloatsrc])
        input_list = collada.source.InputList()
        input_list.addInput(0, 'VERTEX', "#mylinevertsource")
        indices = numpy.array([0, 1, 1, 2, 2, 3, 3, 4, 4, 5])
        lineset = geometry.createLineSet(indices, input_list, "mymaterial")

        # Check the initial values for the lineset.
        self.assertIsNotNone(str(lineset))
        assert_array_equal(lineset.index, indices)
        self.assertEqual(lineset.nlines, len(indices))
        self.assertEqual(lineset.material, "mymaterial")

        # Serialize and deserialize.
        lineset.save()
        loaded_lineset = collada.lineset.LineSet.load(collada, {'mylinevertsource': linefloatsrc}, fromstring(tostring(lineset.xmlnode)))

        # Check that the deserialized version has all of the same properties.
        self.assertEqual(loaded_lineset.sources, lineset.sources)
        self.assertEqual(loaded_lineset.material, lineset.material)
        assert_array_equal(loaded_lineset.index, lineset.index)
        assert_array_equal(loaded_lineset.indices, lineset.indices)
        self.assertEqual(loaded_lineset.nindices, lineset.nindices)
        self.assertEqual(loaded_lineset.nlines, lineset.nlines)


if __name__ == '__main__':
    unittest.main()