mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2024-12-26 01:10:36 +05:00
Run all GEOM tests at once: all tests pass in 1min instead of 50min
This commit is contained in:
parent
e7194e67dc
commit
cd4fec571d
@ -19,14 +19,21 @@
|
|||||||
|
|
||||||
INCLUDE(tests.set)
|
INCLUDE(tests.set)
|
||||||
|
|
||||||
|
SET(TEST_REINIT_SALOME "False")
|
||||||
|
SALOME_CONFIGURE_FILE(tests.py.in tests.py)
|
||||||
|
|
||||||
SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
|
SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
|
||||||
|
|
||||||
|
IF(GEOM_JOIN_TESTS)
|
||||||
|
ADD_TEST(NAME GEOM_examples COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/doc/salome/examples/testme.py tests.py)
|
||||||
|
ELSE(GEOM_JOIN_TESTS)
|
||||||
FOREACH(test ${GOOD_TESTS})
|
FOREACH(test ${GOOD_TESTS})
|
||||||
GET_FILENAME_COMPONENT(testname ${test} NAME_WE)
|
GET_FILENAME_COMPONENT(testname ${test} NAME_WE)
|
||||||
ADD_TEST(NAME ${testname}
|
ADD_TEST(NAME ${testname}
|
||||||
COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/doc/salome/examples/testme.py ${CMAKE_CURRENT_SOURCE_DIR}/${test})
|
COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/doc/salome/examples/testme.py ${CMAKE_CURRENT_SOURCE_DIR}/${test})
|
||||||
SET_TESTS_PROPERTIES(${testname} PROPERTIES ENVIRONMENT "${tests_env}")
|
SET_TESTS_PROPERTIES(${testname} PROPERTIES ENVIRONMENT "${tests_env}")
|
||||||
ENDFOREACH()
|
ENDFOREACH()
|
||||||
|
ENDIF(GEOM_JOIN_TESTS)
|
||||||
|
|
||||||
# install Python scripts
|
# install Python scripts
|
||||||
SALOME_INSTALL_SCRIPTS("${EXAMPLES_TESTS}" ${SALOME_INSTALL_DOC}/examples/GEOM)
|
SALOME_INSTALL_SCRIPTS("${EXAMPLES_TESTS}" ${SALOME_INSTALL_DOC}/examples/GEOM)
|
||||||
|
@ -8,54 +8,23 @@ geompy = geomBuilder.New()
|
|||||||
import salome
|
import salome
|
||||||
gg = salome.ImportComponentGUI("GEOM")
|
gg = salome.ImportComponentGUI("GEOM")
|
||||||
|
|
||||||
# Add a section based on quadrangles
|
|
||||||
# ----------------------------------
|
|
||||||
def section(s, p1, p2=None, p3=None, p4=None):
|
|
||||||
if p2==None:
|
|
||||||
q = p1
|
|
||||||
else:
|
|
||||||
q = geompy.MakeQuad4Vertices(p1, p2, p3, p4)
|
|
||||||
pass
|
|
||||||
s.append(q)
|
|
||||||
publish(q, "section")
|
|
||||||
return q
|
|
||||||
|
|
||||||
|
|
||||||
# find distance between two points
|
|
||||||
# -------------------------------
|
|
||||||
def Dist(p1,p2):
|
|
||||||
c1 = geompy.PointCoordinates(p1)
|
|
||||||
c2 = geompy.PointCoordinates(p2)
|
|
||||||
return math.sqrt( (c2[0]-c1[0])*(c2[0]-c1[0]) +
|
|
||||||
(c2[1]-c1[1])*(c2[1]-c1[1]) +
|
|
||||||
(c2[2]-c1[2])*(c2[2]-c1[2]) )
|
|
||||||
|
|
||||||
|
|
||||||
# return middle point
|
|
||||||
# -------------------------------
|
|
||||||
def MiddleVert(p1,p2):
|
|
||||||
c1 = geompy.PointCoordinates(p1)
|
|
||||||
c2 = geompy.PointCoordinates(p2)
|
|
||||||
return geompy.MakeVertex( (c2[0]+c1[0])/2, (c2[1]+c1[1])/2, (c2[2]+c1[2])/2 )
|
|
||||||
|
|
||||||
|
|
||||||
# Complex section
|
# Complex section
|
||||||
# result - 16 quads from lines
|
# result - 16 quads from lines
|
||||||
# pnt - point from path
|
# pnt - point from path
|
||||||
# vec - direction from path
|
# vec - direction from path
|
||||||
def MakeComplexSect(pnt,vec,rmax,rmin,nb):
|
def MakeComplexSect(pnt, vec, rmax, rmin, nb, geom_builder):
|
||||||
dang = 1.0/nb/2
|
dang = 1.0/nb/2
|
||||||
cmax = geompy.MakeCircle(pnt,vec,rmax)
|
cmax = geom_builder.MakeCircle(pnt,vec,rmax)
|
||||||
cmin = geompy.MakeCircle(pnt,vec,rmin)
|
cmin = geom_builder.MakeCircle(pnt,vec,rmin)
|
||||||
faces = []
|
faces = []
|
||||||
for i in range(0,2*nb,2):
|
for i in range(0,2*nb,2):
|
||||||
p1 = geompy.MakeVertexOnCurve(cmin,dang*i)
|
p1 = geom_builder.MakeVertexOnCurve(cmin,dang*i)
|
||||||
p2 = geompy.MakeVertexOnCurve(cmax,dang*(i+1))
|
p2 = geom_builder.MakeVertexOnCurve(cmax,dang*(i+1))
|
||||||
p3 = geompy.MakeVertexOnCurve(cmin,dang*(i+2))
|
p3 = geom_builder.MakeVertexOnCurve(cmin,dang*(i+2))
|
||||||
f = geompy.MakeQuad4Vertices(pnt,p1,p2,p3)
|
f = geom_builder.MakeQuad4Vertices(pnt,p1,p2,p3)
|
||||||
faces.append(f)
|
faces.append(f)
|
||||||
pass
|
pass
|
||||||
shell = geompy.MakeSewing(faces,1.e-6)
|
shell = geom_builder.MakeSewing(faces,1.e-6)
|
||||||
return shell
|
return shell
|
||||||
|
|
||||||
|
|
||||||
@ -75,25 +44,25 @@ subbases = []
|
|||||||
locs = []
|
locs = []
|
||||||
|
|
||||||
# 1 section
|
# 1 section
|
||||||
shell = MakeComplexSect(vs[0], geompy.MakeVectorDXDYDZ(1,0,0), 60, 40, 16)
|
shell = MakeComplexSect(vs[0], geompy.MakeVectorDXDYDZ(1,0,0), 60, 40, 16, geom_builder=geompy)
|
||||||
shells.append(shell)
|
shells.append(shell)
|
||||||
vs1 = geompy.SubShapeAllSortedCentres(shell,geompy.ShapeType["VERTEX"])
|
vs1 = geompy.SubShapeAllSortedCentres(shell,geompy.ShapeType["VERTEX"])
|
||||||
locs.append(vs1[17])
|
locs.append(vs1[17])
|
||||||
|
|
||||||
# 2 section
|
# 2 section
|
||||||
shell = MakeComplexSect(vs[1], geompy.MakeVectorDXDYDZ(1,0,0), 80, 30, 16)
|
shell = MakeComplexSect(vs[1], geompy.MakeVectorDXDYDZ(1,0,0), 80, 30, 16, geom_builder=geompy)
|
||||||
shells.append(shell)
|
shells.append(shell)
|
||||||
vs2 = geompy.SubShapeAllSortedCentres(shell,geompy.ShapeType["VERTEX"])
|
vs2 = geompy.SubShapeAllSortedCentres(shell,geompy.ShapeType["VERTEX"])
|
||||||
locs.append(vs2[17])
|
locs.append(vs2[17])
|
||||||
|
|
||||||
# 3 section
|
# 3 section
|
||||||
shell = MakeComplexSect(vs[2], geompy.MakeVectorDXDYDZ(1,0,0), 60, 40, 16)
|
shell = MakeComplexSect(vs[2], geompy.MakeVectorDXDYDZ(1,0,0), 60, 40, 16, geom_builder=geompy)
|
||||||
shells.append(shell)
|
shells.append(shell)
|
||||||
vs3 = geompy.SubShapeAllSortedCentres(shell,geompy.ShapeType["VERTEX"])
|
vs3 = geompy.SubShapeAllSortedCentres(shell,geompy.ShapeType["VERTEX"])
|
||||||
locs.append(vs3[17])
|
locs.append(vs3[17])
|
||||||
|
|
||||||
# 4 section
|
# 4 section
|
||||||
shell = MakeComplexSect(vs[3], geompy.MakeVectorDXDYDZ(0,1,0), 40, 35, 16)
|
shell = MakeComplexSect(vs[3], geompy.MakeVectorDXDYDZ(0,1,0), 40, 35, 16, geom_builder=geompy)
|
||||||
shells.append(shell)
|
shells.append(shell)
|
||||||
vs4 = geompy.SubShapeAllSortedCentres(shell,geompy.ShapeType["VERTEX"])
|
vs4 = geompy.SubShapeAllSortedCentres(shell,geompy.ShapeType["VERTEX"])
|
||||||
locs.append(vs4[17])
|
locs.append(vs4[17])
|
||||||
|
@ -5,7 +5,9 @@ import GEOM
|
|||||||
from salome.geom import geomBuilder
|
from salome.geom import geomBuilder
|
||||||
geompy = geomBuilder.New()
|
geompy = geomBuilder.New()
|
||||||
|
|
||||||
def MakeHelix(radius, height, rotation, direction):
|
def MakeSpring(radius, height, rotation, direction, thread_radius, base_rotation, geom_builder):
|
||||||
|
|
||||||
|
def MakeHelix(radius, height, rotation, direction, geom_builder):
|
||||||
# - create a helix -
|
# - create a helix -
|
||||||
radius = 1.0 * radius
|
radius = 1.0 * radius
|
||||||
height = 1.0 * height
|
height = 1.0 * height
|
||||||
@ -31,13 +33,13 @@ def MakeHelix(radius, height, rotation, direction):
|
|||||||
from math import cos, sin
|
from math import cos, sin
|
||||||
x = radius * cos(angle)
|
x = radius * cos(angle)
|
||||||
y = radius * sin(angle)
|
y = radius * sin(angle)
|
||||||
p = geompy.MakeVertex(x, y, z)
|
p = geom_builder.MakeVertex(x, y, z)
|
||||||
helix_points.append( p )
|
helix_points.append( p )
|
||||||
z += z_step
|
z += z_step
|
||||||
angle += direction * angle_step
|
angle += direction * angle_step
|
||||||
pass
|
pass
|
||||||
helix = geompy.MakeInterpol(helix_points)
|
helix = geom_builder.MakeInterpol(helix_points)
|
||||||
length_test = geompy.BasicProperties(helix)[0]
|
length_test = geom_builder.BasicProperties(helix)[0]
|
||||||
prec = abs(length-length_test)/length
|
prec = abs(length-length_test)/length
|
||||||
# print nb_steps, length_test, prec
|
# print nb_steps, length_test, prec
|
||||||
if prec < epsilon:
|
if prec < epsilon:
|
||||||
@ -46,34 +48,32 @@ def MakeHelix(radius, height, rotation, direction):
|
|||||||
pass
|
pass
|
||||||
return helix
|
return helix
|
||||||
|
|
||||||
def MakeSpring(radius, height, rotation, direction, thread_radius, base_rotation=0.0):
|
|
||||||
# - create a pipe -
|
# - create a pipe -
|
||||||
thread_radius = 1.0 * thread_radius
|
thread_radius = 1.0 * thread_radius
|
||||||
# create a helix
|
# create a helix
|
||||||
helix = MakeHelix(radius, height, rotation, direction)
|
helix = MakeHelix(radius, height, rotation, direction, geom_builder=geom_builder)
|
||||||
# base in the (Ox, Oz) plane
|
# base in the (Ox, Oz) plane
|
||||||
p0 = geompy.MakeVertex(radius-3*thread_radius, 0.0, -thread_radius)
|
p0 = geom_builder.MakeVertex(radius-3*thread_radius, 0.0, -thread_radius)
|
||||||
p1 = geompy.MakeVertex(radius+3*thread_radius, 0.0, -thread_radius)
|
p1 = geom_builder.MakeVertex(radius+3*thread_radius, 0.0, -thread_radius)
|
||||||
p2 = geompy.MakeVertex(radius+3*thread_radius, 0.0, +thread_radius)
|
p2 = geom_builder.MakeVertex(radius+3*thread_radius, 0.0, +thread_radius)
|
||||||
p3 = geompy.MakeVertex(radius-3*thread_radius, 0.0, +thread_radius)
|
p3 = geom_builder.MakeVertex(radius-3*thread_radius, 0.0, +thread_radius)
|
||||||
e0 = geompy.MakeEdge(p0, p1)
|
e0 = geom_builder.MakeEdge(p0, p1)
|
||||||
e1 = geompy.MakeEdge(p1, p2)
|
e1 = geom_builder.MakeEdge(p1, p2)
|
||||||
e2 = geompy.MakeEdge(p2, p3)
|
e2 = geom_builder.MakeEdge(p2, p3)
|
||||||
e3 = geompy.MakeEdge(p3, p0)
|
e3 = geom_builder.MakeEdge(p3, p0)
|
||||||
w = geompy.MakeWire([e0, e1, e2, e3])
|
w = geom_builder.MakeWire([e0, e1, e2, e3])
|
||||||
# create a base face
|
# create a base face
|
||||||
base = geompy.MakeFace(w, True)
|
base = geom_builder.MakeFace(w, True)
|
||||||
# create a binormal vector
|
# create a binormal vector
|
||||||
binormal = geompy.MakeVectorDXDYDZ(0.0, 0.0, 10.0)
|
binormal = geom_builder.MakeVectorDXDYDZ(0.0, 0.0, 10.0)
|
||||||
# create a pipe
|
# create a pipe
|
||||||
spring = geompy.MakePipeBiNormalAlongVector(base, helix, binormal)
|
spring = geom_builder.MakePipeBiNormalAlongVector(base, helix, binormal)
|
||||||
# Publish in the study
|
# Publish in the study
|
||||||
geompy.addToStudy(base, "base")
|
geom_builder.addToStudy(base, "base")
|
||||||
geompy.addToStudy(helix, "helix")
|
geom_builder.addToStudy(helix, "helix")
|
||||||
geompy.addToStudy(binormal, "binormal")
|
geom_builder.addToStudy(binormal, "binormal")
|
||||||
geompy.addToStudy(spring, "spring")
|
geom_builder.addToStudy(spring, "spring")
|
||||||
return spring
|
return spring
|
||||||
|
|
||||||
from math import pi
|
from math import pi
|
||||||
|
spring = MakeSpring(50, 100, 2*pi, 1, 5, pi/2, geom_builder=geompy)
|
||||||
spring = MakeSpring(50, 100, 2*pi, 1, 5, pi/2)
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
# Point Coordinates
|
# Point Coordinates
|
||||||
|
|
||||||
import math
|
|
||||||
import salome
|
import salome
|
||||||
salome.salome_init()
|
salome.salome_init()
|
||||||
import GEOM
|
import GEOM
|
||||||
@ -14,8 +13,9 @@ point = geompy.MakeVertex(15., 23., 80.)
|
|||||||
coords = geompy.PointCoordinates(point)
|
coords = geompy.PointCoordinates(point)
|
||||||
|
|
||||||
# check the obtained coordinate values
|
# check the obtained coordinate values
|
||||||
tolerance = 1.e-07
|
def IsEqual(val1, val2, tolerance = 1.e-07):
|
||||||
def IsEqual(val1, val2): return (math.fabs(val1 - val2) < tolerance)
|
import math
|
||||||
|
return (math.fabs(val1 - val2) < tolerance)
|
||||||
|
|
||||||
if IsEqual(coords[0], 15.) and IsEqual(coords[1], 23.) and IsEqual(coords[2], 80.):
|
if IsEqual(coords[0], 15.) and IsEqual(coords[1], 23.) and IsEqual(coords[2], 80.):
|
||||||
print("All values are OK.")
|
print("All values are OK.")
|
||||||
|
35
doc/salome/examples/tests.py.in
Normal file
35
doc/salome/examples/tests.py.in
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
DIR='@CMAKE_CURRENT_SOURCE_DIR@'
|
||||||
|
TESTS='@GOOD_TESTS@'
|
||||||
|
REINIT_SALOME=@TEST_REINIT_SALOME@
|
||||||
|
|
||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
import salome
|
||||||
|
|
||||||
|
class MyTest(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
if REINIT_SALOME:
|
||||||
|
salome.salome_init()
|
||||||
|
def tearDown(self):
|
||||||
|
if REINIT_SALOME:
|
||||||
|
salome.salome_close()
|
||||||
|
pass
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
tests = TESTS.split(';')
|
||||||
|
for test in tests:
|
||||||
|
file_name = os.path.basename(test)
|
||||||
|
if os.path.isabs(test):
|
||||||
|
file_path = file_name
|
||||||
|
else:
|
||||||
|
file_path = os.path.join(DIR, file_name)
|
||||||
|
case_name = 'test_' + file_name[:-3]
|
||||||
|
code = """
|
||||||
|
def func(self):
|
||||||
|
with open('{}') as f:
|
||||||
|
exec(f.read())
|
||||||
|
"""
|
||||||
|
exec(code.format(file_path))
|
||||||
|
setattr(MyTest, case_name, func)
|
||||||
|
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user