FreeCAD
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
23import Path24import Path.Base.Generator.toolchange as generator25import Tests.PathTestUtils as PathTestUtils26
27Path.Log.setLevel(Path.Log.Level.DEBUG, Path.Log.thisModule())28Path.Log.trackModule(Path.Log.thisModule())29
30
31class TestPathToolChangeGenerator(PathTestUtils.PathTestBase):32def test00(self):33"""Test Basic Tool Change Generator Return"""34
35args = {36"toolnumber": 1,37"toollabel": "My Label",38"spindlespeed": 500,39"spindledirection": generator.SpindleDirection.OFF,40}41
42results = generator.generate(**args)43
44# Get a label45self.assertTrue(len(results) == 2)46commentcommand = results[0]47self.assertTrue(isinstance(commentcommand, Path.Command))48self.assertTrue(commentcommand.toGCode() == "(My Label)")49
50# Get a tool command51toolcommand = results[1]52self.assertTrue(toolcommand.Name == "M6")53
54# Turn on the spindle55args["spindledirection"] = generator.SpindleDirection.CW56results = generator.generate(**args)57self.assertTrue(len(results) == 3)58
59speedcommand = results[2]60self.assertTrue(speedcommand.Name == "M3")61self.assertTrue(speedcommand.Parameters["S"] == 500)62
63# speed zero with spindle on64args["spindlespeed"] = 065results = generator.generate(**args)66self.assertTrue(len(results) == 2)67Path.Log.track(results)68
69# negative spindlespeed70args["spindlespeed"] = -1071self.assertRaises(ValueError, generator.generate, **args)72