File: bl_geometry_attributes.py

package info (click to toggle)
blender 5.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 329,128 kB
  • sloc: cpp: 2,489,823; python: 349,859; ansic: 261,364; xml: 2,103; sh: 999; javascript: 317; makefile: 193
file content (74 lines) | stat: -rw-r--r-- 2,755 bytes parent folder | download
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
64
65
66
67
68
69
70
71
72
73
74
# SPDX-FileCopyrightText: 2024 Blender Authors
#
# SPDX-License-Identifier: Apache-2.0

# ./blender.bin --background --python tests/python/bl_geometry_attributes.py -- --verbose
import bpy
import unittest


class TestCurves(unittest.TestCase):
    def setUp(self):
        self.curves = bpy.data.hair_curves.new("test")
        # 50 points, 4 curves
        self.curves.add_curves([5, 10, 15, 20])

    def tearDown(self):
        bpy.data.hair_curves.remove(self.curves)
        del self.curves

    def test_add_attribute(self):
        a = self.curves.attributes.new("a", 'FLOAT', 'POINT')
        self.assertTrue(a.name == "a")
        self.assertTrue(a.data_type == 'FLOAT')
        self.assertTrue(a.domain == 'POINT')
        self.assertTrue(a.storage_type == 'ARRAY')
        self.assertFalse(a.is_internal)
        self.assertTrue(len(a.data) == 50)

    def test_is_required(self):
        a = self.curves.attributes.new("a", 'FLOAT', 'POINT')
        self.assertFalse(a.is_required)
        self.assertTrue(self.curves.attributes["position"].is_required)

    def test_pointer_stability_on_add(self):
        attrs = [self.curves.attributes.new("a" + str(i), 'FLOAT', 'POINT') for i in range(100)]
        for i in range(100):
            self.assertTrue(attrs[i].name == "a" + str(i))
            self.assertTrue(attrs[i].data_type == 'FLOAT')
            self.assertTrue(attrs[i].domain == 'POINT')

        # Remove some attributes
        for i in range(50):
            self.curves.attributes.remove(attrs[i])
            del attrs[i]

        self.assertTrue(len(self.curves.attributes) == 51)
        self.assertTrue(self.curves.attributes["a51"].name == "a51")

    def test_add_same_name(self):
        a = self.curves.attributes.new("a", 'FLOAT', 'POINT')
        b = self.curves.attributes.new("a", 'BOOLEAN', 'CURVE')
        self.assertFalse(a.name == b.name)

    def test_add_wrong_domain(self):
        with self.assertRaises(RuntimeError):
            self.curves.attributes.new("a", 'FLOAT', 'CORNER')

    def rename_attribute(self, name, new_name):
        with self.assertRaises(RuntimeError):
            self.curves.attributes["position"].name = "asjhfksjhdfkjsh"
        a = self.curves.attributes.new("a", 'FLOAT', 'POINT')
        a.name = "better_name"
        self.assertTrue(a.name == "better_name")
        self.assertTrue(self.curves.attributes["better_name"].name == "better_name")

    def test_long_name(self):
        self.curves.attributes.new("a" * 100, 'FLOAT', 'POINT')
        self.assertTrue(self.curves.attributes["a" * 100].name == "a" * 100)


if __name__ == '__main__':
    import sys
    sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [])
    unittest.main()