FreeCAD

Форк
0
/
TestPathPropertyBag.py 
75 строк · 3.7 Кб
1
# -*- coding: utf-8 -*-
2
# ***************************************************************************
3
# *   Copyright (c) 2021 sliptonic <shopinthewoods@gmail.com>               *
4
# *                                                                         *
5
# *   This program is free software; you can redistribute it and/or modify  *
6
# *   it under the terms of the GNU Lesser General Public License (LGPL)    *
7
# *   as published by the Free Software Foundation; either version 2 of     *
8
# *   the License, or (at your option) any later version.                   *
9
# *   for detail see the LICENCE text file.                                 *
10
# *                                                                         *
11
# *   This program is distributed in the hope that it will be useful,       *
12
# *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
# *   GNU Library General Public License for more details.                  *
15
# *                                                                         *
16
# *   You should have received a copy of the GNU Library General Public     *
17
# *   License along with this program; if not, write to the Free Software   *
18
# *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
19
# *   USA                                                                   *
20
# *                                                                         *
21
# ***************************************************************************
22

23
import FreeCAD
24
import Path.Base.PropertyBag as PathPropertyBag
25
import Tests.PathTestUtils as PathTestUtils
26

27

28
class TestPathPropertyBag(PathTestUtils.PathTestBase):
29
    def setUp(self):
30
        self.doc = FreeCAD.newDocument("test-property-bag")
31

32
    def tearDown(self):
33
        FreeCAD.closeDocument(self.doc.Name)
34

35
    def test00(self):
36
        """basic PropertyBag creation and access test"""
37
        bag = PathPropertyBag.Create()
38
        self.assertTrue(hasattr(bag, "Proxy"))
39
        self.assertEqual(bag.Proxy.getCustomProperties(), [])
40
        self.assertEqual(bag.CustomPropertyGroups, [])
41

42
    def test01(self):
43
        """adding properties to a PropertyBag is tracked properly"""
44
        bag = PathPropertyBag.Create()
45
        proxy = bag.Proxy
46
        proxy.addCustomProperty("App::PropertyString", "Title", "Address", "Some description")
47
        self.assertTrue(hasattr(bag, "Title"))
48
        bag.Title = "Madame"
49
        self.assertEqual(bag.Title, "Madame")
50
        self.assertEqual(bag.Proxy.getCustomProperties(), ["Title"])
51
        self.assertEqual(bag.CustomPropertyGroups, ["Address"])
52

53
    def test02(self):
54
        """refreshCustomPropertyGroups deletes empty groups"""
55
        bag = PathPropertyBag.Create()
56
        proxy = bag.Proxy
57
        proxy.addCustomProperty("App::PropertyString", "Title", "Address", "Some description")
58
        bag.Title = "Madame"
59
        bag.removeProperty("Title")
60
        proxy.refreshCustomPropertyGroups()
61
        self.assertEqual(bag.Proxy.getCustomProperties(), [])
62
        self.assertEqual(bag.CustomPropertyGroups, [])
63

64
    def test03(self):
65
        """refreshCustomPropertyGroups does not delete non-empty groups"""
66
        bag = PathPropertyBag.Create()
67
        proxy = bag.Proxy
68
        proxy.addCustomProperty("App::PropertyString", "Title", "Address", "Some description")
69
        proxy.addCustomProperty("App::PropertyString", "Gender", "Attributes")
70
        bag.Title = "Madame"
71
        bag.Gender = "Female"
72
        bag.removeProperty("Gender")
73
        proxy.refreshCustomPropertyGroups()
74
        self.assertEqual(bag.Proxy.getCustomProperties(), ["Title"])
75
        self.assertEqual(bag.CustomPropertyGroups, ["Address"])
76

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.