File: bl_brush_test.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 (69 lines) | stat: -rw-r--r-- 3,162 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
# SPDX-FileCopyrightText: 2025 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later

import sys
import unittest

import bpy


class AssetActivateTest(unittest.TestCase):
    def setUp(self):
        # Test case isn't specific to Sculpt Mode, but we need a paint mode in general.
        bpy.ops.object.mode_set(mode='SCULPT')
        bpy.ops.brush.asset_activate(
            asset_library_type='ESSENTIALS',
            relative_asset_identifier='brushes/essentials_brushes-mesh_sculpt.blend/Brush/Draw')

    def test_loads_essential_asset(self):
        result = bpy.ops.brush.asset_activate(
            asset_library_type='ESSENTIALS',
            relative_asset_identifier='brushes/essentials_brushes-mesh_sculpt.blend/Brush/Smooth')
        self.assertEqual({'FINISHED'}, result)

    def test_toggle_when_brush_differs_sets_specified_brush(self):
        """Test that using the 'Toggle' parameter when the brush is not active still activates the correct brush"""
        bpy.ops.brush.asset_activate(
            asset_library_type='ESSENTIALS',
            relative_asset_identifier='brushes/essentials_brushes-mesh_sculpt.blend/Brush/Mask',
            use_toggle=True)
        self.assertEqual(bpy.context.tool_settings.sculpt.brush.name, 'Mask')

    def test_toggle_when_brush_matches_sets_previous_brush(self):
        """Test that using the 'Toggle' parameter when the brush is active activates the previously activated brush"""
        bpy.ops.brush.asset_activate(
            asset_library_type='ESSENTIALS',
            relative_asset_identifier='brushes/essentials_brushes-mesh_sculpt.blend/Brush/Mask',
            use_toggle=True)
        self.assertEqual(bpy.context.tool_settings.sculpt.brush.name, 'Mask')
        bpy.ops.brush.asset_activate(
            asset_library_type='ESSENTIALS',
            relative_asset_identifier='brushes/essentials_brushes-mesh_sculpt.blend/Brush/Mask',
            use_toggle=True)
        self.assertEqual(bpy.context.tool_settings.sculpt.brush.name, 'Draw')


class AssetSaveAsTest(unittest.TestCase):
    def setUp(self):
        # Test case isn't specific to Sculpt Mode, but we need a paint mode in general.
        bpy.ops.object.mode_set(mode='SCULPT')

        bpy.ops.brush.asset_activate(
            asset_library_type='ESSENTIALS',
            relative_asset_identifier='brushes/essentials_brushes-mesh_sculpt.blend/Brush/Smooth')

    def test_saves_asset_locally(self):
        """Test that saving an asset to the local creates a copy correctly"""
        result = bpy.ops.brush.asset_save_as(name="Local Copy", asset_library_reference="LOCAL", catalog_path="")
        self.assertEqual({'FINISHED'}, result)

        self.assertTrue("Local Copy" in bpy.data.brushes)
        local_brush = bpy.data.brushes["Local Copy"]
        self.assertEqual(local_brush.sculpt_brush_type, 'SMOOTH')
        self.assertGreaterEqual(local_brush.users, 1)


if __name__ == "__main__":
    # Drop all arguments before "--", or everything if the delimiter is absent. Keep the executable path.
    unittest.main(argv=sys.argv[:1] + (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []))