[OpenSCAD] Add unit test framework to module
The OpenSCAD module did not have any unit tests. This commit adds the basic framework (and two very simple tests). The framework is modeled after the unit tests in the FEM module.
This commit is contained in:
@@ -15,9 +15,45 @@ SET(OpenSCAD_SRCS
|
||||
colorcodeshapes.py
|
||||
expandplacements.py
|
||||
replaceobj.py
|
||||
TestOpenSCADApp.py
|
||||
)
|
||||
IF (BUILD_GUI)
|
||||
LIST(APPEND OpenSCAD_SRCS TestOpenSCADGui.py)
|
||||
ENDIF (BUILD_GUI)
|
||||
SOURCE_GROUP("" FILES ${OpenSCAD_SRCS})
|
||||
|
||||
SET(OpenSCADTests_SRCS
|
||||
OpenSCADTest/__init__.py
|
||||
OpenSCADTest/test_information.md
|
||||
)
|
||||
|
||||
SET(OpenSCADTestsApp_SRCS
|
||||
OpenSCADTest/app/__init__.py
|
||||
OpenSCADTest/app/test_importCSG.py
|
||||
)
|
||||
|
||||
SET(OpenSCADTestsGui_SRCS
|
||||
OpenSCADTest/gui/__init__.py
|
||||
OpenSCADTest/gui/test_dummy.py
|
||||
)
|
||||
|
||||
SET(OpenSCADTestsFiles_SRCS
|
||||
OpenSCADTest/data/__init__.py
|
||||
OpenSCADTest/data/CSG.scad
|
||||
OpenSCADTest/data/CSG.csg
|
||||
)
|
||||
|
||||
SET(OpenSCADTests_ALL
|
||||
${OpenSCADTests_SRCS}
|
||||
${OpenSCADTestsApp_SRCS}
|
||||
${OpenSCADTestsFiles_SRCS}
|
||||
)
|
||||
|
||||
IF (BUILD_GUI)
|
||||
LIST(APPEND OpenSCADTests_ALL ${OpenSCADTestsGui_SRCS})
|
||||
ENDIF (BUILD_GUI)
|
||||
|
||||
|
||||
set(all_files ${OpenSCAD_SRCS})
|
||||
|
||||
SET(OpenSCADGuiIcon_SVG
|
||||
@@ -28,10 +64,16 @@ ADD_CUSTOM_TARGET(OpenSCAD ALL
|
||||
SOURCES ${all_files} ${OpenSCAD_QRC_SRCS} ${OpenSCADGuiIcon_SVG}
|
||||
)
|
||||
|
||||
ADD_CUSTOM_TARGET(OpenSCADTests ALL
|
||||
SOURCES ${OpenSCADTests_ALL}
|
||||
)
|
||||
|
||||
fc_copy_sources(OpenSCAD "${CMAKE_BINARY_DIR}/Mod/OpenSCAD" ${all_files})
|
||||
|
||||
fc_copy_sources(OpenSCAD "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/OpenSCAD" ${OpenSCADGuiIcon_SVG})
|
||||
|
||||
fc_copy_sources(OpenSCADTests "${CMAKE_BINARY_DIR}/Mod/OpenSCAD" ${OpenSCADTests_ALL})
|
||||
|
||||
IF (BUILD_GUI)
|
||||
fc_target_copy_resource(OpenSCAD
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
@@ -59,3 +101,7 @@ INSTALL(
|
||||
"${CMAKE_INSTALL_DATADIR}/Mod/OpenSCAD/Resources/icons"
|
||||
)
|
||||
|
||||
INSTALL(FILES ${OpenSCADTests_SRCS} DESTINATION Mod/OpenSCAD/OpenSCADTest)
|
||||
INSTALL(FILES ${OpenSCADTestsApp_SRCS} DESTINATION Mod/OpenSCAD/OpenSCADTest/app)
|
||||
INSTALL(FILES ${OpenSCADTestsGui_SRCS} DESTINATION Mod/OpenSCAD/OpenSCADTest/gui)
|
||||
INSTALL(FILES ${OpenSCADTestsFiles_SRCS} DESTINATION Mod/OpenSCAD/OpenSCADTest/data)
|
||||
|
||||
@@ -32,6 +32,8 @@ openscadfilename = param.GetString('openscadexecutable')
|
||||
openscadbin = openscadfilename and os.path.isfile(openscadfilename)
|
||||
if openscadbin:
|
||||
FreeCAD.addImportType("OpenSCAD Format (*.scad)","importCSG")
|
||||
FreeCAD.__unit_test__ += ["TestOpenSCADApp"]
|
||||
|
||||
FreeCAD.addExportType("OpenSCAD CSG Format (*.csg)","exportCSG")
|
||||
FreeCAD.addExportType("OpenSCAD Format (*.scad)","exportCSG")
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#***************************************************************************/
|
||||
|
||||
import FreeCAD
|
||||
import OpenSCADUtils
|
||||
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD")
|
||||
openscadfilename = param.GetString('openscadexecutable')
|
||||
|
||||
@@ -91,3 +92,7 @@ class OpenSCADWorkbench ( Workbench ):
|
||||
|
||||
|
||||
Gui.addWorkbench(OpenSCADWorkbench())
|
||||
|
||||
openscadfilename = OpenSCADUtils.searchforopenscadexe()
|
||||
if openscadfilename: #automatic search was succsessful
|
||||
FreeCAD.__unit_test__ += ["TestOpenSCADGui"]
|
||||
|
||||
0
src/Mod/OpenSCAD/OpenSCADTest/__init__.py
Normal file
0
src/Mod/OpenSCAD/OpenSCADTest/__init__.py
Normal file
0
src/Mod/OpenSCAD/OpenSCADTest/app/__init__.py
Normal file
0
src/Mod/OpenSCAD/OpenSCADTest/app/__init__.py
Normal file
72
src/Mod/OpenSCAD/OpenSCADTest/app/test_importCSG.py
Normal file
72
src/Mod/OpenSCAD/OpenSCADTest/app/test_importCSG.py
Normal file
@@ -0,0 +1,72 @@
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2021 Chris Hennes <chennes@pioneerlibrarysystem.org> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENSE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
import unittest
|
||||
import FreeCAD
|
||||
import OpenSCAD
|
||||
import importCSG
|
||||
|
||||
from os.path import join
|
||||
|
||||
__title__ = "ImportCSG OpenSCAD App unit tests"
|
||||
__author__ = "Chris Hennes"
|
||||
__url__ = "https://www.freecadweb.org"
|
||||
|
||||
|
||||
class TestImportCSG(unittest.TestCase):
|
||||
|
||||
MODULE = 'test_importCSG' # file name without extension
|
||||
|
||||
|
||||
def setUp(self):
|
||||
self.test_dir = join(FreeCAD.getHomePath(), "Mod", "OpenSCAD", "OpenSCADTest", "data")
|
||||
pass
|
||||
|
||||
def test_open_scad(self):
|
||||
testfile = join(self.test_dir, "CSG.scad")
|
||||
doc = importCSG.open(testfile)
|
||||
|
||||
# Doc should now contain three solids: a union, an intersection, and a difference
|
||||
union = doc.getObject("union")
|
||||
intersection = doc.getObject("intersection")
|
||||
difference = doc.getObject("difference")
|
||||
|
||||
self.assertTrue (union is not None)
|
||||
self.assertTrue (intersection is not None)
|
||||
self.assertTrue (difference is not None)
|
||||
|
||||
FreeCAD.closeDocument("CSG")
|
||||
|
||||
def test_open_csg(self):
|
||||
testfile = join(self.test_dir, "CSG.csg")
|
||||
doc = importCSG.open(testfile)
|
||||
|
||||
# Doc should now contain three solids: a union, an intersection, and a difference
|
||||
union = doc.getObject("union")
|
||||
intersection = doc.getObject("intersection")
|
||||
difference = doc.getObject("difference")
|
||||
|
||||
self.assertTrue (union is not None)
|
||||
self.assertTrue (intersection is not None)
|
||||
self.assertTrue (difference is not None)
|
||||
|
||||
FreeCAD.closeDocument("CSG")
|
||||
18
src/Mod/OpenSCAD/OpenSCADTest/data/CSG.csg
Normal file
18
src/Mod/OpenSCAD/OpenSCADTest/data/CSG.csg
Normal file
@@ -0,0 +1,18 @@
|
||||
multmatrix([[1, 0, 0, -24], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
|
||||
union() {
|
||||
cube(size = [15, 15, 15], center = true);
|
||||
sphere($fn = 0, $fa = 12, $fs = 2, r = 10);
|
||||
}
|
||||
}
|
||||
intersection() {
|
||||
cube(size = [15, 15, 15], center = true);
|
||||
sphere($fn = 0, $fa = 12, $fs = 2, r = 10);
|
||||
}
|
||||
multmatrix([[1, 0, 0, 24], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
|
||||
difference() {
|
||||
cube(size = [15, 15, 15], center = true);
|
||||
sphere($fn = 0, $fa = 12, $fs = 2, r = 10);
|
||||
}
|
||||
}
|
||||
group();
|
||||
|
||||
32
src/Mod/OpenSCAD/OpenSCADTest/data/CSG.scad
Normal file
32
src/Mod/OpenSCAD/OpenSCADTest/data/CSG.scad
Normal file
@@ -0,0 +1,32 @@
|
||||
// CSG.scad - Basic example of CSG usage
|
||||
|
||||
translate([-24,0,0]) {
|
||||
union() {
|
||||
cube(15, center=true);
|
||||
sphere(10);
|
||||
}
|
||||
}
|
||||
|
||||
intersection() {
|
||||
cube(15, center=true);
|
||||
sphere(10);
|
||||
}
|
||||
|
||||
translate([24,0,0]) {
|
||||
difference() {
|
||||
cube(15, center=true);
|
||||
sphere(10);
|
||||
}
|
||||
}
|
||||
|
||||
echo(version=version());
|
||||
// Written by Marius Kintel <marius@kintel.net>
|
||||
//
|
||||
// To the extent possible under law, the author(s) have dedicated all
|
||||
// copyright and related and neighboring rights to this software to the
|
||||
// public domain worldwide. This software is distributed without any
|
||||
// warranty.
|
||||
//
|
||||
// You should have received a copy of the CC0 Public Domain
|
||||
// Dedication along with this software.
|
||||
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
0
src/Mod/OpenSCAD/OpenSCADTest/data/__init__.py
Normal file
0
src/Mod/OpenSCAD/OpenSCADTest/data/__init__.py
Normal file
0
src/Mod/OpenSCAD/OpenSCADTest/gui/__init__.py
Normal file
0
src/Mod/OpenSCAD/OpenSCADTest/gui/__init__.py
Normal file
38
src/Mod/OpenSCAD/OpenSCADTest/gui/test_dummy.py
Normal file
38
src/Mod/OpenSCAD/OpenSCADTest/gui/test_dummy.py
Normal file
@@ -0,0 +1,38 @@
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2021 Chris Hennes <chennes@pioneerlibrarysystem.org> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENSE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
# OpenSCAD Module GUI Tests
|
||||
|
||||
import unittest
|
||||
import FreeCAD
|
||||
import OpenSCAD
|
||||
|
||||
class TestDummy(unittest.TestCase):
|
||||
|
||||
MODULE = 'test_dummy' # file name without extension
|
||||
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def test_tests(self):
|
||||
self.assertTrue(True)
|
||||
3
src/Mod/OpenSCAD/OpenSCADTest/test_information.md
Normal file
3
src/Mod/OpenSCAD/OpenSCADTest/test_information.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# OpenSCAD Unit Test Information
|
||||
|
||||
The OpenSCAD testing framework is based on the tests in the FEM Module.
|
||||
28
src/Mod/OpenSCAD/TestOpenSCADApp.py
Normal file
28
src/Mod/OpenSCAD/TestOpenSCADApp.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2021 Chris Hennes <chennes@pioneerlibrarysystem.org> *
|
||||
# * *
|
||||
# * This file is part of the FreeCAD CAx development system. *
|
||||
# * *
|
||||
# * This program is free software; you can redistribute it and/or modify *
|
||||
# * it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
# * as published by the Free Software Foundation; either version 2 of *
|
||||
# * the License, or (at your option) any later version. *
|
||||
# * for detail see the LICENCE text file. *
|
||||
# * *
|
||||
# * This program is distributed in the hope that it will be useful, *
|
||||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# * GNU Library General Public License for more details. *
|
||||
# * *
|
||||
# * You should have received a copy of the GNU Library General Public *
|
||||
# * License along with this program; if not, write to the Free Software *
|
||||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
|
||||
# Unit test for the OpenSCAD module
|
||||
from OpenSCADTest.app.test_importCSG import TestImportCSG as OpenSCADTestImportCSG
|
||||
|
||||
# dummy usage to get flake8 and lgtm quiet
|
||||
False if OpenSCADTestImportCSG.__name__ else True
|
||||
29
src/Mod/OpenSCAD/TestOpenSCADGui.py
Normal file
29
src/Mod/OpenSCAD/TestOpenSCADGui.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2021 Chris Hennes <chennes@pioneerlibrarysystem.org> *
|
||||
# * *
|
||||
# * This file is part of the FreeCAD CAx development system. *
|
||||
# * *
|
||||
# * This program is free software; you can redistribute it and/or modify *
|
||||
# * it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
# * as published by the Free Software Foundation; either version 2 of *
|
||||
# * the License, or (at your option) any later version. *
|
||||
# * for detail see the LICENCE text file. *
|
||||
# * *
|
||||
# * This program is distributed in the hope that it will be useful, *
|
||||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# * GNU Library General Public License for more details. *
|
||||
# * *
|
||||
# * You should have received a copy of the GNU Library General Public *
|
||||
# * License along with this program; if not, write to the Free Software *
|
||||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
|
||||
# Gui Unit tests for the FEM module
|
||||
from OpenSCADTest.gui.test_dummy import TestDummy as OpenSCADGuiTestDummy
|
||||
|
||||
|
||||
# dummy usage to get flake8 and lgtm quiet
|
||||
False if OpenSCADGuiTestDummy.__name__ else True
|
||||
Reference in New Issue
Block a user