Skip to content

Commit 4d8a4bf

Browse files
committed
Merge pull request #173 from tpaviot/tp/quality-improvements-part-1
Tp/quality improvements part 1
2 parents 44a81b3 + 848801f commit 4d8a4bf

17 files changed

+2439
-2342
lines changed

src/generate_swig_files.py

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
##Copyright 2008-2011 Thomas Paviot (tpaviot@gmail.com)
3+
##Copyright 2008-2013 Thomas Paviot (tpaviot@gmail.com)
44
##
55
##This file is part of pythonOCC.
66
##
@@ -20,8 +20,8 @@
2020
import sys
2121
import os
2222
import glob
23-
# add the ./src directory to the sys.path list
24-
sys.path.append(os.path.join(os.getcwd(),'wrapper'))
23+
24+
sys.path.append(os.path.join(os.getcwd(), 'wrapper'))
2525
import SWIG_generator
2626
import Modules
2727
import environment
@@ -37,80 +37,59 @@
3737
MULTI_PROCESS_GENERATION = False
3838
import time
3939

40+
4041
def check_paths():
4142
#
42-
# Under WNT, modify Standard_Real.hxx so that it can be parsed by GCCXML without issue
43+
# Under WNT, modify Standard_Real.hxx so that it can be parsed by
44+
# GCCXML without issue
4345
#
4446
if sys.platform == 'win32':
45-
standard_real_header = os.path.join(environment.OCC_INC,"Standard_Real.hxx")
47+
standard_real_header = os.path.join(environment.OCC_INC, "Standard_Real.hxx")
4648
if not os.path.isfile(standard_real_header):
47-
print "%s not found."%standard_real_header
49+
print "%s not found." % standard_real_header
4850
sys.exit(0)
49-
# else:
50-
# import shutil
51-
# fp = open(standard_real_header,"r")
52-
# file_content = fp.read()
53-
# fp.close()
54-
# if not '__SWIG_GENERATION__' in file_content:#need rewriting
55-
# key = raw_input("Original Standard_Real.hxx header file needs to be modified. Original file will be available with the name Standard_Real_Original.hxx.\nEnter 'y' or 'Y' if you whish to continue.'n' otherwise:")# first mode Standard_Real.hxx to Standard_Real_Original.hxx
56-
# if key.lower()=='y':
57-
# shutil.copy(standard_real_header, os.path.join(environment.OCC_INC,"Standard_Real_Original.hxx"))
58-
# #replacing string
59-
# file_content = file_content.replace("#if defined(WNT)","#if defined(WNT) && !defined(__SWIG_GENERATION__)")
60-
# fp = open(standard_real_header,"w")
61-
# fp.write(file_content)
62-
# fp.close()
63-
# else:
64-
# sys.exit(0)
65-
# else:
66-
# print "Found modified Standard_Real.hxx header file."
67-
#
68-
# Remove all files from OCC folder
69-
#
70-
#files_to_remove = glob.glob(os.path.join(os.getcwd(),'OCC','*'))
71-
#for file_to_remove in files_to_remove:
72-
# os.remove(file_to_remove)
7351
#
7452
# Create paths
7553
#
7654
if not os.path.isdir(environment.SWIG_FILES_PATH_MODULAR):
7755
os.mkdir(environment.SWIG_FILES_PATH_MODULAR)
7856

57+
7958
def generate_SWIG_file_for_module(module):
8059
''' For each module, create the siwg .i file to be processed
8160
'''
8261
if module in Modules.SALOME_GEOM_MODULES:
83-
SWIG_generator.ModularBuilder(module,environment.SALOME_GEOM_INC)
62+
SWIG_generator.ModularBuilder(module, environment.SALOME_GEOM_INC)
8463
elif module in Modules.SALOME_SMESH_MODULES:
85-
SWIG_generator.ModularBuilder(module,environment.SALOME_SMESH_INC)
64+
SWIG_generator.ModularBuilder(module, environment.SALOME_SMESH_INC)
8665
else:
8766
SWIG_generator.ModularBuilder(module)
8867

68+
8969
def generate_swig_multiprocess(module_list):
9070
''' Generate swig files with parallel support
9171
'''
92-
#raw_input('Enter something')
9372
init_time = time.time()
9473
P = processing.Pool(nprocs)
95-
P.map(generate_SWIG_file_for_module,module_list)
74+
P.map(generate_SWIG_file_for_module, module_list)
9675
final_time = time.time()
97-
#print "%i exported classes"%SWIG_generator.nb_exported_classes
9876
print final_time-init_time
9977

78+
10079
def generate_swig_single_process(module_list):
10180
''' Generate swig files in single process mode (multiprocessing not found)
10281
'''
10382
init_time = time.time()
10483
for module in module_list:
10584
generate_SWIG_file_for_module(module)
10685
final_time = time.time()
107-
print "%i exported classes"%SWIG_generator.nb_exported_classes
86+
print "%i exported classes" % SWIG_generator.nb_exported_classes
10887
print final_time-init_time
10988

11089
if __name__ == '__main__':
11190
check_paths()
11291
# Check if a module name is passed to the command line
113-
if len(sys.argv)>1:
92+
if len(sys.argv) > 1:
11493
module_name_to_wrap = sys.argv[1]
11594
if module_name_to_wrap == 'GEOM':
11695
print "Generating swig files for the GEOM library"
@@ -126,14 +105,13 @@ def generate_swig_single_process(module_list):
126105
modules_to_wrap = [module]
127106
break
128107
#print modules_to_wrap
129-
if modules_to_wrap == None:
130-
raise NameError,"Unknown module"
108+
if modules_to_wrap is None:
109+
raise NameError("Unknown module")
131110
else:
132111
if sys.platform == 'win32':
133112
modules_to_wrap = Modules.COMMON_MODULES + Modules.WIN_MODULES
134113
else:
135114
modules_to_wrap = Modules.COMMON_MODULES + Modules.UNIX_MODULES
136-
137115
if MULTI_PROCESS_GENERATION:
138116
print "Generating pythonOCC SWIG files (MultiProcess mode)."
139117
generate_swig_multiprocess(modules_to_wrap)

src/unittest/SMESH_wrapper_features_unittest.py

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
##Copyright 2009-2011 Thomas Paviot (tpaviot@gmail.com)
3+
##Copyright 2009-2013 Thomas Paviot (tpaviot@gmail.com)
44
##
55
##This file is part of pythonOCC.
66
##
@@ -18,56 +18,59 @@
1818
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.
1919

2020
import unittest
21-
import sys
2221

2322
from OCC.Standard import *
2423
from OCC.Utils.Topology import *
2524
from OCC.BRepPrimAPI import *
2625
from OCC.BRepBuilderAPI import *
2726
from OCC.gp import *
2827
from OCC.StdMeshers import *
28+
from OCC.SMESH import SMESH_Gen
29+
2930

3031
class TestSMESHWrapperFeatures(unittest.TestCase):
3132

3233
def testSTLVectorInt(self):
3334
'''
34-
Checks the IntVector and DoubleVector classes that are used in the StdMeshers
35-
module
35+
Checks the IntVector and DoubleVector classes that are used
36+
in the StdMeshers module
3637
'''
3738
# The IntVector must be initialized from a list/tuple of integers
38-
i_v = IntVector([1,2,3,4])
39-
self.assertEqual(i_v[0],1)
40-
self.assertEqual(i_v[1],2)
41-
self.assertEqual(i_v[2],3)
42-
self.assertEqual(i_v[3],4)
43-
# If at least one item of the list is not an integer, raise an exception
44-
self.assertRaises(TypeError,IntVector,[1,2,3,4.0])
45-
39+
i_v = IntVector([1, 2, 3, 4])
40+
self.assertEqual(i_v[0], 1)
41+
self.assertEqual(i_v[1], 2)
42+
self.assertEqual(i_v[2], 3)
43+
self.assertEqual(i_v[3], 4)
44+
# If at least one item of the list is not an integer,
45+
# raise an exception
46+
self.assertRaises(TypeError, IntVector, [1, 2, 3, 4.0])
47+
4648
def testSTLVectorDouble(self):
4749
'''
48-
Checks the IntVector and DoubleVector classes that are used in the StdMeshers
49-
module
50+
Checks the IntVector and DoubleVector classes that are
51+
used in the StdMeshers module
5052
'''
51-
# The IntVector must be initialized from a list/tuple of floats/integers. Integers will
52-
# be converted to floats
53-
d_v = DoubleVector([0.1,0.2,0.6,0.7])
54-
self.assertEqual(d_v[0],0.1)
55-
self.assertEqual(d_v[1],0.2)
56-
self.assertEqual(d_v[2],0.6)
57-
self.assertEqual(d_v[3],0.7)
58-
# If at least one item of the list is not an float or an integer, raise an exception
59-
self.assertRaises(TypeError,DoubleVector,[1.0,2.0,3.0,"string"])
60-
# Test one method of StdMeshers that takes/returns such a parameter type
61-
from OCC.SMESH import SMESH_Gen
62-
number_of_segments = StdMeshers_NumberOfSegments(1,10,SMESH_Gen())
53+
# The IntVector must be initialized from a list/tuple of
54+
# floats/integers. Integers will be converted into floats
55+
d_v = DoubleVector([0.1, 0.2, 0.6, 0.7])
56+
self.assertEqual(d_v[0], 0.1)
57+
self.assertEqual(d_v[1], 0.2)
58+
self.assertEqual(d_v[2], 0.6)
59+
self.assertEqual(d_v[3], 0.7)
60+
# If at least one item of the list is not an float or an integer,
61+
# raise an exception
62+
self.assertRaises(TypeError, DoubleVector, [1.0, 2.0, 3.0, "string"])
63+
# Test one method of StdMeshers that takes/returns such
64+
# a parameter type
65+
number_of_segments = StdMeshers_NumberOfSegments(1, 10, SMESH_Gen())
6366
number_of_segments.SetTableFunction(d_v)
64-
self.assertEquals(number_of_segments.GetTableFunction(),(0.1,0.2,0.6,0.7))
65-
67+
self.assertEquals(number_of_segments.GetTableFunction(), (0.1, 0.2, 0.6, 0.7))
68+
69+
6670
def suite():
67-
suite = unittest.TestSuite()
68-
suite.addTest(unittest.makeSuite(TestSMESHWrapperFeatures))
69-
return suite
71+
suite = unittest.TestSuite()
72+
suite.addTest(unittest.makeSuite(TestSMESHWrapperFeatures))
73+
return suite
7074

7175
if __name__ == "__main__":
7276
unittest.main()
73-

0 commit comments

Comments
 (0)