1 from GeomAlgoAPI import *
5 def generateTests(theFeature, theFeatureName, theTestsList = []):
6 """ Generates tests for theFeature.
7 :param theFeature: feature to test. Should be ModelHighAPI_Interface.
8 :param theFeatureName: feature name to put in test commands.
9 :param theTestsList: list of test to be generated. If empty generates all tests.
11 if "testNbResults" in theTestsList or len(theTestsList) == 0:
12 aNbResults = len(theFeature.results())
13 print "model.testNbResults({}, {})".format(theFeatureName, aNbResults)
15 if "testNbSubResults" in theTestsList or len(theTestsList) == 0:
16 aNbResults = len(theFeature.results())
18 for anIndex in range(0, aNbResults):
19 aNbSubResults.append(theFeature.results()[anIndex].numberOfSubs())
20 print "model.testNbSubResults({}, {})".format(theFeatureName, aNbSubResults)
22 if "testResultsVolumes" in theTestsList or len(theTestsList) == 0:
23 aNbResults = len(theFeature.results())
25 for anIndex in range(0, aNbResults):
26 aResultsVolumes.append(GeomAlgoAPI_ShapeTools_volume(theFeature.results()[anIndex].resultSubShapePair()[0].shape()))
27 print "model.testResultsVolumes({}, [{}])".format(theFeatureName, ", ".join("{:0.27f}".format(i) for i in aResultsVolumes))
30 def testNbResults(theFeature, theExpectedNbResults):
31 """ Tests number of feature results.
32 :param theFeature: feature to test.
33 :param theExpectedNbResults: expected number of results.
35 aNbResults = len(theFeature.results())
36 assert (aNbResults == theExpectedNbResults), "Number of results: {}. Expected: {}.".format(aNbResults, theExpectedNbResults)
39 def testNbSubResults(theFeature, theExpectedNbSubResults):
40 """ Tests number of feature sub-results for each result.
41 :param theFeature: feature to test.
42 :param theExpectedNbSubResults: list of sub-results numbers. Size of list should be equal to len(theFeature.results()).
44 aNbResults = len(theFeature.results())
45 aListSize = len(theExpectedNbSubResults)
46 assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize)
47 for anIndex in range(0, aNbResults):
48 aNbSubResults = theFeature.results()[anIndex].numberOfSubs()
49 anExpectedNbSubResults = theExpectedNbSubResults[anIndex]
50 assert (aNbSubResults == anExpectedNbSubResults), "Number of sub-results for result[{}]: {}. Expected: {}.".format(anIndex, aNbSubResults, anExpectedNbSubResults)
53 def testResultsVolumes(theFeature, theExpectedResultsVolumes, theNbSignificantDigits = 10):
54 """ Tests results volumes.
55 :param theFeature: feature to test.
56 :param theExpectedResultsVolumes: list of results volumes. Size of list should be equal to len(theFeature.results()).
58 aNbResults = len(theFeature.results())
59 aListSize = len(theExpectedResultsVolumes)
60 assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize)
61 for anIndex in range(0, aNbResults):
62 aResultVolume = GeomAlgoAPI_ShapeTools_volume(theFeature.results()[anIndex].resultSubShapePair()[0].shape())
63 aResultVolumeStr = "{:0.27f}".format(aResultVolume).lstrip("0").lstrip(".").lstrip("0")
64 anExpectedResultVolume = theExpectedResultsVolumes[anIndex]
65 anExpectedResultVolumeStr = "{:0.27f}".format(anExpectedResultVolume).lstrip("0").lstrip(".").lstrip("0")
66 assert (aResultVolumeStr[:theNbSignificantDigits] == anExpectedResultVolumeStr[:theNbSignificantDigits]), "Volume of result[{}]: {:0.27f}. Expected: {:0.27f}. The first {} significant digits not equal.".format(anIndex, aResultVolume, anExpectedResultVolume, theNbSignificantDigits)