FreeCAD

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

24
import FreeCAD
25

26
import Path
27
import Tests.PathTestUtils as PathTestUtils
28
from Path.Post.scripts import refactored_test_post as postprocessor
29

30

31
Path.Log.setLevel(Path.Log.Level.DEBUG, Path.Log.thisModule())
32
Path.Log.trackModule(Path.Log.thisModule())
33

34

35
class TestRefactoredTestPostMCodes(PathTestUtils.PathTestBase):
36
    """Test the refactored_test_post.py postprocessor."""
37

38
    @classmethod
39
    def setUpClass(cls):
40
        """setUpClass()...
41

42
        This method is called upon instantiation of this test class.  Add code
43
        and objects here that are needed for the duration of the test() methods
44
        in this class.  In other words, set up the 'global' test environment
45
        here; use the `setUp()` method to set up a 'local' test environment.
46
        This method does not have access to the class `self` reference, but it
47
        is able to call static methods within this same class.
48
        """
49
        # Open existing FreeCAD document with test geometry
50
        FreeCAD.newDocument("Unnamed")
51

52
    @classmethod
53
    def tearDownClass(cls):
54
        """tearDownClass()...
55

56
        This method is called prior to destruction of this test class.  Add
57
        code and objects here that cleanup the test environment after the
58
        test() methods in this class have been executed.  This method does
59
        not have access to the class `self` reference.  This method is able
60
        to call static methods within this same class.
61
        """
62
        # Close geometry document without saving
63
        FreeCAD.closeDocument(FreeCAD.ActiveDocument.Name)
64

65
    # Setup and tear down methods called before and after each unit test
66

67
    def setUp(self):
68
        """setUp()...
69

70
        This method is called prior to each `test()` method.  Add code and
71
        objects here that are needed for multiple `test()` methods.
72
        """
73
        self.doc = FreeCAD.ActiveDocument
74
        self.con = FreeCAD.Console
75
        self.docobj = FreeCAD.ActiveDocument.addObject("Path::Feature", "testpath")
76
        #
77
        # Re-initialize all of the values before doing a test.
78
        #
79
        postprocessor.UNITS = "G21"
80
        postprocessor.init_values(postprocessor.global_values)
81

82
    def tearDown(self):
83
        """tearDown()...
84

85
        This method is called after each test() method. Add cleanup instructions here.
86
        Such cleanup instructions will likely undo those in the setUp() method.
87
        """
88
        FreeCAD.ActiveDocument.removeObject("testpath")
89

90
    def single_compare(self, path, expected, args, debug=False):
91
        """Perform a test with a single comparison."""
92
        nl = "\n"
93
        self.docobj.Path = Path.Path(path)
94
        postables = [self.docobj]
95
        gcode = postprocessor.export(postables, "-", args)
96
        if debug:
97
            print(f"--------{nl}{gcode}--------{nl}")
98
        self.assertEqual(gcode, expected)
99

100
    def compare_third_line(self, path_string, expected, args, debug=False):
101
        """Perform a test with a single comparison to the third line of the output."""
102
        nl = "\n"
103
        if path_string:
104
            self.docobj.Path = Path.Path([Path.Command(path_string)])
105
        else:
106
            self.docobj.Path = Path.Path([])
107
        postables = [self.docobj]
108
        gcode = postprocessor.export(postables, "-", args)
109
        if debug:
110
            print(f"--------{nl}{gcode}--------{nl}")
111
        self.assertEqual(gcode.splitlines()[2], expected)
112

113
    #############################################################################
114
    #
115
    # The tests are organized into groups:
116
    #
117
    #   00000 - 00099  tests that don't fit any other category
118
    #   00100 - 09999  tests for all of the various arguments/options
119
    #   10000 - 19999  tests for the various G codes at 10000 + 10 * g_code_value
120
    #   20000 - 29999  tests for the various M codes at 20000 + 10 * m_code_value
121
    #
122
    #############################################################################
123

124
    def test20000(self):
125
        """Test M0 command Generation."""
126
        self.compare_third_line("M0", "M0", "")
127
        self.compare_third_line("M00", "M00", "")
128

129
    #############################################################################
130

131
    def test20010(self):
132
        """Test M1 command Generation."""
133
        self.compare_third_line("M1", "M1", "")
134
        self.compare_third_line("M01", "M01", "")
135

136
    #############################################################################
137

138
    def test20020(self):
139
        """Test M2 command Generation."""
140
        self.compare_third_line("M2", "M2", "")
141
        self.compare_third_line("M02", "M02", "")
142

143
    #############################################################################
144

145
    def test20030(self):
146
        """Test M3 command Generation."""
147
        self.compare_third_line("M3", "M3", "")
148
        self.compare_third_line("M03", "M03", "")
149

150
    #############################################################################
151

152
    def test20040(self):
153
        """Test M4 command Generation."""
154
        self.compare_third_line("M4", "M4", "")
155
        self.compare_third_line("M04", "M04", "")
156

157
    #############################################################################
158

159
    def test20050(self):
160
        """Test M5 command Generation."""
161
        self.compare_third_line("M5", "M5", "")
162
        self.compare_third_line("M05", "M05", "")
163

164
    #############################################################################
165

166
    def test20060(self):
167
        """Test M6 command Generation."""
168
        self.compare_third_line("M6", "M6", "")
169
        self.compare_third_line("M06", "M06", "")
170

171
    #############################################################################
172

173
    def test20070(self):
174
        """Test M7 command Generation."""
175
        self.compare_third_line("M7", "M7", "")
176
        self.compare_third_line("M07", "M07", "")
177

178
    #############################################################################
179

180
    def test20080(self):
181
        """Test M8 command Generation."""
182
        self.compare_third_line("M8", "M8", "")
183
        self.compare_third_line("M08", "M08", "")
184

185
    #############################################################################
186

187
    def test20090(self):
188
        """Test M9 command Generation."""
189
        self.compare_third_line("M9", "M9", "")
190
        self.compare_third_line("M09", "M09", "")
191

192
    #############################################################################
193

194
    def test20300(self):
195
        """Test M30 command Generation."""
196
        self.compare_third_line("M30", "M30", "")
197

198
    #############################################################################
199

200
    def test20480(self):
201
        """Test M48 command Generation."""
202
        self.compare_third_line("M48", "M48", "")
203

204
    #############################################################################
205

206
    def test20490(self):
207
        """Test M49 command Generation."""
208
        self.compare_third_line("M49", "M49", "")
209

210
    #############################################################################
211

212
    def test20600(self):
213
        """Test M60 command Generation."""
214
        self.compare_third_line("M60", "M60", "")
215

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

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

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

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