当前位置: 首页>>代码示例>>Python>>正文


Python TestUtilities类代码示例

本文整理汇总了Python中TestUtilities的典型用法代码示例。如果您正苦于以下问题:Python TestUtilities类的具体用法?Python TestUtilities怎么用?Python TestUtilities使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TestUtilities类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RunTest

def RunTest():
    try:
        arcpy.AddMessage("Starting Test: TestCreateRangeFanIndexFeatures")
        
        # WORKAROUND
        print "Creating New Scratch Workspace (Workaround)"    
        TestUtilities.createScratch()
            
        inputPolygonFC =  os.path.join(TestUtilities.inputGDB, "RangeFans")
        outputExtentBoxes =  os.path.join(TestUtilities.outputGDB, "OutputExtentBoxes")
        outputRangeVertices =  os.path.join(TestUtilities.outputGDB, "RangeVertices")
        toolbox = TestUtilities.toolbox
                
        # Set environment settings
        print "Running from: " + str(TestUtilities.currentPath)
        print "Geodatabase path: " + str(TestUtilities.geodatabasePath)
        
        arcpy.env.overwriteOutput = True
        arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
        arcpy.ImportToolbox(toolbox, "RFT")
    
        inputFeatureCount = int(arcpy.GetCount_management(inputPolygonFC).getOutput(0)) 
        print "Input FeatureClass: " + str(inputPolygonFC)
        print "Input Feature Count: " +  str(inputFeatureCount)
            
        if (inputPolygonFC < 1) :
            print "Invalid Input Feature Count: " +  str(inputPolygonFC)                       
                   
        ########################################################3
        # Execute the Model under test:   
        arcpy.CreateRangeFanIndexFeatures_RFT(inputPolygonFC, outputExtentBoxes, outputRangeVertices)
        ########################################################3
    
        # Verify the results    
        outputFeatureCountExtent = int(arcpy.GetCount_management(outputExtentBoxes).getOutput(0)) 
        print "Output FeatureClass: " + str(outputExtentBoxes)
        print "Output Feature Count: " +  str(outputFeatureCountExtent)
    
        outputFeatureCountPoints = int(arcpy.GetCount_management(outputRangeVertices).getOutput(0))
        print "Output FeatureClass: " + str(outputRangeVertices)
        print "Output Feature Count: " +  str(outputFeatureCountPoints)
                
        if (outputFeatureCountExtent < 1) or (outputFeatureCountPoints < 1) :
            print "Invalid Output Feature Count: " +  str(outputFeatureCountExtent) + ":" + str(outputFeatureCountPoints)
            raise Exception("Test Failed")                                  
            
        # WORKAROUND: delete scratch db
        print "Deleting Scratch Workspace (Workaround)"    
        TestUtilities.deleteScratch()        
        
        print "Test Successful"        
                
    except arcpy.ExecuteError: 
        # Get the tool error messages 
        msgs = arcpy.GetMessages() 
        arcpy.AddError(msgs) 
    
        # return a system error code
        sys.exit(-1)
        
    except Exception as e:
        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
    
        # Concatenate information together concerning the error into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
        msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages() + "\n"
    
        # Return python error messages for use in script tool or Python Window
        arcpy.AddError(pymsg)
        arcpy.AddError(msgs)
    
        # return a system error code
        sys.exit(-1)
开发者ID:ACueva,项目名称:defense-and-intel-analysis-toolbox,代码行数:75,代码来源:TestCreateRangeFanIndexFeatures.py

示例2: Exception

    else:
        raise LicenseError
    
    arcpy.ImportToolbox(TestUtilities.toolbox)
    arcpy.env.overwriteOutput = True
    arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
    
    inputPolyArea = os.path.join(TestUtilities.inputGDB, "samplePolygonArea")
    inputRoads = os.path.join(TestUtilities.inputGDB, "roads")
    inputSurface = os.path.join(TestUtilities.inputGDB, "Jbad_SRTM_USGS_EROS")
    psOutputRV = os.path.join(TestUtilities.outputGDB, "PathSlopeOutputRV")
    classValue = '0 3 1;3 10 2;10 15 3;15 20 4;20 30 5;30 45 6;45 60 7;60 85 8;85 10000000000000 9;NODATA 0'
    
    #Testing Path Slope by Reclass Values
    arcpy.AddMessage("Starting Test: Path Slope by Reclass Values")
    TestUtilities.createScratch()
    arcpy.PathSlopeByRanges_path(inputPolyArea, inputRoads, inputSurface, 'DEGREE', classValue, psOutputRV)

    
    #Test for Feature Outpu
    outputFeatureCount = int(arcpy.GetCount_management(psOutputRV).getOutput(0)) 
    print("Output FeatureClass: " + str(psOutputRV))
    print("Output Feature Count: " +  str(outputFeatureCount))
            
    if (outputFeatureCount < 1):
        print("Invalid Output Feature Count: " +  str(outputFeatureCount))
        raise Exception("Test Failed")  

    print("Test Passed")

except LicenseError:
开发者ID:GISkev,项目名称:solutions-geoprocessing-toolbox,代码行数:31,代码来源:TestPathSlopeReclassValues.py

示例3: RunTest

def RunTest():
    try:
        arcpy.AddMessage("Starting Test: LocalPeaks")

        if arcpy.CheckExtension("Spatial") == "Available":
            arcpy.CheckOutExtension("Spatial")
        else:
            # Raise a custom exception
            raise Exception("LicenseError")

        # WORKAROUND
        print "Creating New Scratch Workspace (Workaround)"
        TestUtilities.createScratch()

        # Verify the expected configuration exists
        inputPolygonFC = os.path.join(TestUtilities.inputGDB, "samplePolygonArea")
        inputSurface = os.path.join(TestUtilities.defaultGDB, "Jbad_SRTM_USGS_EROS")
        outputPointsFC = os.path.join(TestUtilities.outputGDB, "LocalPeaks")
        toolbox = TestUtilities.toolbox

        # Check For Valid Input
        objects2Check = []
        objects2Check.extend([inputPolygonFC, inputSurface, toolbox])
        for object2Check in objects2Check:
            desc = arcpy.Describe(object2Check)
            if desc == None:
                raise Exception("Bad Input")
            else:
                print "Valid Object: " + desc.Name

        # Set environment settings
        print "Running from: " + str(TestUtilities.currentPath)
        print "Geodatabase path: " + str(TestUtilities.geodatabasePath)

        arcpy.env.overwriteOutput = True
        arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
        arcpy.ImportToolbox(toolbox, "VandR")

        inputFeatureCount = int(arcpy.GetCount_management(inputPolygonFC).getOutput(0))
        print "Input FeatureClass: " + str(inputPolygonFC)
        print "Input Feature Count: " + str(inputFeatureCount)

        if inputFeatureCount < 1:
            print "Invalid Input Feature Count: " + str(inputFeatureCount)

        numberOfPeaks = 3

        ########################################################3
        # Execute the Model under test:
        arcpy.FindLocalPeaks_VandR(inputPolygonFC, numberOfPeaks, inputSurface, outputPointsFC)
        ########################################################3

        # Verify the results
        outputFeatureCount = int(arcpy.GetCount_management(outputPointsFC).getOutput(0))
        print "Output FeatureClass: " + str(outputPointsFC)
        print "Output Feature Count: " + str(outputFeatureCount)

        if outputPointsFC < 3:
            print "Invalid Output Feature Count: " + str(outputFeatureCount)
            raise Exception("Test Failed")

        # WORKAROUND: delete scratch db
        print "Deleting Scratch Workspace (Workaround)"
        TestUtilities.deleteScratch()

        print "Test Successful"

    except arcpy.ExecuteError:
        # Get the tool error messages
        msgs = arcpy.GetMessages()
        arcpy.AddError(msgs)

        # return a system error code
        sys.exit(-1)

    except Exception as e:
        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]

        # Concatenate information together concerning the error into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
        msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages() + "\n"

        # Return python error messages for use in script tool or Python Window
        arcpy.AddError(pymsg)
        arcpy.AddError(msgs)

        # return a system error code
        sys.exit(-1)

    finally:
        # Check in the 3D Analyst extension
        arcpy.CheckInExtension("Spatial")
开发者ID:jfrygeo,项目名称:defense-and-intel-analysis-toolbox,代码行数:94,代码来源:TestModelLocalPeaks.py

示例4: RunTest

def RunTest():
    try:
        arcpy.AddMessage("Starting Test: RangeFans")
        
        if arcpy.CheckExtension("Spatial") == "Available":
            arcpy.CheckOutExtension("Spatial")
        else:
            # Raise a custom exception
            raise Exception("LicenseError")        
        
        # WORKAROUND
        print "Creating New Scratch Workspace (Workaround)"    
        TestUtilities.createScratch()
            
        # Verify the expected configuration exists
        inputPointsFC =  os.path.join(TestUtilities.inputGDB, "sampleRangePoints")
        inputSurface =  os.path.join(TestUtilities.inputGDB, "Jbad_SRTM_USGS_EROS")
        outputRangeFansFC =  os.path.join(TestUtilities.outputGDB, "RangeFans")
        outputRangeVizFC =  os.path.join(TestUtilities.outputGDB, "RangeViz") 
        toolbox = TestUtilities.toolbox
        sr = arcpy.SpatialReference(32642) #WGS_1984_UTM_Zone_42N using factoryCode
        
        # Check For Valid Input
        objects2Check = []
        objects2Check.extend([inputPointsFC, inputSurface, toolbox])
        for object2Check in objects2Check :
            desc = arcpy.Describe(object2Check)
            if desc == None :
                raise Exception("Bad Input")
            else :
                print("Valid Object: " + desc.Name)
        
        # Set environment settings
        print("Running from: " + str(TestUtilities.currentPath))
        print("Geodatabase path: " + str(TestUtilities.geodatabasePath))
        
        arcpy.env.overwriteOutput = True
        arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
        arcpy.ImportToolbox(toolbox, "VandR")
    
        inputFeatureCount = int(arcpy.GetCount_management(inputPointsFC).getOutput(0)) 
        print("Input FeatureClass: " + str(inputPointsFC))
        print("Input Feature Count: " +  str(inputFeatureCount))
            
        if (inputFeatureCount < 1) :
            print("Invalid Input Feature Count: " +  str(inputFeatureCount))
                       
        maximumRange = 1000.0
        bearing = 150.0
        traversal = 22.0
           
        ########################################################3
        # Execute the Model under test:
        arcpy.RangeFan_VandR(inputPointsFC, maximumRange, bearing, traversal, inputSurface, outputRangeFansFC, outputRangeVizFC, sr)
        ########################################################3
    
        # Verify the results    
        outputFeatureCountFans = int(arcpy.GetCount_management(outputRangeFansFC).getOutput(0)) 
        print("Output FeatureClass: " + str(outputRangeFansFC))
        print("Output Feature Count: " +  str(outputFeatureCountFans))
    
        outputFeatureCountViz = int(arcpy.GetCount_management(outputRangeVizFC).getOutput(0))
        print("Output FeatureClass: " + str(outputRangeVizFC))
        print("Output Feature Count: " +  str(outputFeatureCountViz))
                
        if (outputFeatureCountFans < 1) or (outputFeatureCountViz < 1):
            print("Invalid Output Feature Count: " +  str(outputFeatureCountFans) + ":" + str(outputFeatureCountViz))
            raise Exception("Test Failed")
            
        # WORKAROUND: delete scratch db
        print("Deleting Scratch Workspace (Workaround)")
        TestUtilities.deleteScratch()        
        
        print("Test Successful")
                
    except arcpy.ExecuteError: 
        # Get the tool error messages 
        msgs = arcpy.GetMessages() 
        arcpy.AddError(msgs) 
    
        # return a system error code
        sys.exit(-1)
        
    except Exception as e:
        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
    
        # Concatenate information together concerning the error into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
        msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages() + "\n"
    
        # Return python error messages for use in script tool or Python Window
        arcpy.AddError(pymsg)
        arcpy.AddError(msgs)
    
        # return a system error code
        sys.exit(-1)
        
    finally:
#.........这里部分代码省略.........
开发者ID:aguha-github,项目名称:solutions-geoprocessing-toolbox,代码行数:101,代码来源:TestModelRangeFan.py

示例5: RunTest

def RunTest():
    try:
        arcpy.AddMessage("Starting Test: TestRangeFanByBearingAndTraversal")
        
        # WORKAROUND
        print("Creating New Scratch Workspace (Workaround)"    )
        TestUtilities.createScratch()
            
        inputPointsFC =  os.path.join(TestUtilities.inputGDB, "sampleRangePoints")
        outputRangeFansFC =  os.path.join(TestUtilities.outputGDB, "RangeFansBearingAndTraversal")
        toolbox = TestUtilities.toolbox
                
        # Set environment settings
        print("Running from: " + str(TestUtilities.currentPath))
        print("Geodatabase path: " + str(TestUtilities.geodatabasePath))
        
        arcpy.env.overwriteOutput = True
        arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
        arcpy.ImportToolbox(toolbox, "Range")
    
        inputFeatureCount = int(arcpy.GetCount_management(inputPointsFC).getOutput(0)) 
        print("Input FeatureClass: " + str(inputPointsFC))
        print("Input Feature Count: " +  str(inputFeatureCount))
            
        if (inputFeatureCount < 1) :
            print("Invalid Input Feature Count: " +  str(inputFeatureCount))
                       
        maximumRangeInMeters = 2000
        centralBearingInDegrees = 320
        traversalWidthInDegrees = 30
                   
        ########################################################3
        # Execute the Model under test:
        # mfunk 8/12/2014: Tool parameters have been modified, this test is no longer valid
        #arcpy.RangeFanByBearingAndTraversal_Range(inputPointsFC, maximumRangeInMeters, centralBearingInDegrees, traversalWidthInDegrees, outputRangeFansFC)
        ########################################################3
    
        # Verify the results    
        outputFeatureCount = int(arcpy.GetCount_management(outputRangeFansFC).getOutput(0)) 
        print("Output FeatureClass: " + str(outputRangeFansFC))
        print("Output Feature Count: " +  str(outputFeatureCount))
                
        if (outputFeatureCount < 1) :
            print("Invalid Output Feature Count: " +  str(outputFeatureCount))
            raise Exception("Test Failed")            
            
        # WORKAROUND: delete scratch db
        print("Deleting Scratch Workspace (Workaround)")
        TestUtilities.deleteScratch()        
        
        print("Test Successful")
                
    except arcpy.ExecuteError: 
        # Get the tool error messages 
        msgs = arcpy.GetMessages() 
        arcpy.AddError(msgs) 
    
        # return a system error code
        sys.exit(-1)
        
    except Exception as e:
        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
    
        # Concatenate information together concerning the error into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
        msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages() + "\n"
    
        # Return python error messages for use in script tool or Python Window
        arcpy.AddError(pymsg)
        arcpy.AddError(msgs)
    
        # return a system error code
        sys.exit(-1)
开发者ID:GISkev,项目名称:solutions-geoprocessing-toolbox,代码行数:75,代码来源:TestRangeFanByBearingAndTraversal.py

示例6: RunTest

def RunTest():
    try:
        arcpy.AddMessage("Starting Test: RangeRings")
        
        # WORKAROUND
        print("Creating New Scratch Workspace (Workaround)")
        TestUtilities.createScratch()
            
        # Verify the expected configuration exists
        inputPointsFC =  os.path.join(TestUtilities.inputGDB, "sampleRangePoints")
        outputRangeRingsFC =  os.path.join(TestUtilities.outputGDB, "RangeRings")
        outputRangeRadialsFC =  os.path.join(TestUtilities.outputGDB, "RangeRadials") 
        toolbox = TestUtilities.toolbox
        
        # Check For Valid Input
        objects2Check = []
        objects2Check.extend([inputPointsFC, toolbox])
        for object2Check in objects2Check :
            desc = arcpy.Describe(object2Check)
            if desc == None :
                raise Exception("Bad Input")
            else :
                print("Valid Object: " + desc.Name)
        
        # Set environment settings
        print("Running from: " + str(TestUtilities.currentPath))
        print("Geodatabase path: " + str(TestUtilities.geodatabasePath))
        
        arcpy.env.overwriteOutput = True
        arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
        arcpy.ImportToolbox(toolbox, "VandR")
    
        inputFeatureCount = int(arcpy.GetCount_management(inputPointsFC).getOutput(0)) 
        print("Input FeatureClass: " + str(inputPointsFC))
        print("Input Feature Count: " +  str(inputFeatureCount))
            
        if (inputFeatureCount < 1) :
            print("Invalid Input Feature Count: " +  str(inputFeatureCount))
                       
        numberOfRings = 5
        ringInterval = 1000.0
        distanceUnits = "METERS"
        numberOfRadials = 8
           
        ########################################################3
        # Execute the Model under test:   
        arcpy.RangeRings_VandR(inputPointsFC, numberOfRings, ringInterval, distanceUnits, numberOfRadials, outputRangeRingsFC, outputRangeRadialsFC)
        ########################################################3
    
        # Verify the results    
        outputFeatureCountRings = int(arcpy.GetCount_management(outputRangeRingsFC).getOutput(0)) 
        print("Output FeatureClass: " + str(outputRangeRingsFC))
        print("Output Feature Count: " +  str(outputFeatureCountRings))
    
        outputFeatureCountRadials = int(arcpy.GetCount_management(outputRangeRadialsFC).getOutput(0))
        print("Output FeatureClass: " + str(outputRangeRadialsFC))
        print("Output Feature Count: " +  str(outputFeatureCountRadials))
                
        if (outputFeatureCountRings < 1) or (outputFeatureCountRadials < 1) :
            print("Invalid Output Feature Count: " +  str(outputFeatureCountRings) + ":" + str(outputFeatureCountRadials))
            raise Exception("Test Failed")            
            
        # WORKAROUND: delete scratch db
        print("Deleting Scratch Workspace (Workaround)")
        TestUtilities.deleteScratch()        
        
        print("Test Successful")
                
    except arcpy.ExecuteError: 
        # Get the tool error messages 
        msgs = arcpy.GetMessages() 
        arcpy.AddError(msgs) 
    
        # return a system error code
        sys.exit(-1)
        
    except Exception as e:
        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
    
        # Concatenate information together concerning the error into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
        msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages() + "\n"
    
        # Return python error messages for use in script tool or Python Window
        arcpy.AddError(pymsg)
        arcpy.AddError(msgs)
    
        # return a system error code
        sys.exit(-1)
开发者ID:GISkev,项目名称:solutions-geoprocessing-toolbox,代码行数:91,代码来源:TestModelRangeRings.py

示例7: RunTest

def RunTest():
    try:
        arcpy.AddMessage("Starting Test: CoordinateConversion")
        
        # WORKAROUND
        print "Creating New Scratch Workspace (Workaround)"    
        TestUtilities.createScratch()
            
        inputTable =  os.path.join(TestUtilities.csvPath, "SigActs.csv")
        outputDbf =  os.path.join(TestUtilities.dbfPath, "test_coordinate_cc.dbf")
        toolbox = TestUtilities.toolbox        
        
        # Set environment settings
        print "Running from: " + str(TestUtilities.currentPath)
        print "Geodatabase path: " + str(TestUtilities.geodatabasePath)
        
        arcpy.env.overwriteOutput = True
        arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
        arcpy.ImportToolbox(toolbox, "MyAlias")
    
        inputFeatureCount = int(arcpy.GetCount_management(inputTable).getOutput(0)) 
        print "Input FeatureClass: " + str(inputTable)
        print "Input Feature Count: " +  str(inputFeatureCount)
            
        if (inputFeatureCount < 1) :
            print "Invalid Input Feature Count: " +  str(inputFeatureCount)
                       
        coordinateConversionFrom = 'MGRS'
        coordinateFieldX = 'Location'
        coordinateFieldY = '#'
        
        ########################################################3
        # Execute the Model under test:   
        
        # sample params:
        # 'data\csv\SigActs.csv', 'MGRS', 'Location', '#', 'data\test_coordinate_cc.dbf', 
        
        arcpy.ConvertCoordinates_MyAlias(inputTable, coordinateConversionFrom, coordinateFieldX, coordinateFieldY, outputDbf)
        ########################################################3
    
        # Verify the results    
        outputFeatureCount = int(arcpy.GetCount_management(outputDbf).getOutput(0)) 
        print "Output FeatureClass: " + str(outputDbf)
        print "Output Feature Count: " +  str(outputFeatureCount)
                    
        if (outputFeatureCount <>  inputFeatureCount) :
            print "Input / Output Feature Count don't match: " +  str(inputFeatureCount) + ":" + str(outputFeatureCount)
            raise Exception("Test Failed")            
            
        # WORKAROUND: delete scratch db
        print "Deleting Scratch Workspace (Workaround)"    
        TestUtilities.deleteScratch()        
        
        print "Test Successful"        
                
    except arcpy.ExecuteError: 
        # Get the tool error messages 
        msgs = arcpy.GetMessages() 
        arcpy.AddError(msgs) 
    
        # return a system error code
        sys.exit(-1)
        
    except Exception as e:
        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
    
        # Concatenate information together concerning the error into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
        msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages() + "\n"
    
        # Return python error messages for use in script tool or Python Window
        arcpy.AddError(pymsg)
        arcpy.AddError(msgs)
    
        # return a system error code
        sys.exit(-1)
开发者ID:ACueva,项目名称:defense-and-intel-analysis-toolbox,代码行数:78,代码来源:TestCoordinateConversion.py

示例8: RunTest

def RunTest():
    try:
        arcpy.AddMessage("Starting Test: TestLocalPeaks")
        
        #TEST_IMPLEMENTED = False
        #
        #if not TEST_IMPLEMENTED :
        #    arcpy.AddWarning("***Test Not Yet Implemented***")
        #    return
        
        # TODO: once model has a version that works with local surface data 
        # (rather than image service), then finish this test/implementation below
        #
        # alternately you can add an image service connection in Catalog and 
        # fill in the parameter below
        
        if arcpy.CheckExtension("Spatial") == "Available":
            arcpy.CheckOutExtension("Spatial")
        else:
            # Raise a custom exception
            raise Exception("LicenseError")        
        
        arcpy.env.overwriteOutput = True
        arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
                
        # WORKAROUND
        print("Creating New Scratch Workspace (Workaround)")
        TestUtilities.createScratch()
            
        # Verify the expected configuration exists
        inputPolygonFC =  os.path.join(TestUtilities.inputGDB, "samplePolygonArea")
        inputSurface =  TestUtilities.inputElevationURL
        outputPointsFC =  os.path.join(TestUtilities.outputGDB, "LocalPeaks")
        toolbox = TestUtilities.toolbox
        arcpy.ImportToolbox(toolbox, "MAoT")        
        
        # Check For Valid Input
        objects2Check = []
        #objects2Check.extend([inputPolygonFC, inputSurface, toolbox])
        objects2Check.extend([inputPolygonFC, toolbox])
        for object2Check in objects2Check :
            desc = arcpy.Describe(object2Check)
            if desc == None :
                raise Exception("Bad Input")
            else :
                print("Valid Object: " + desc.Name)
        
        # Set environment settings
        print("Running from: " + str(TestUtilities.currentPath))
        print("Geodatabase path: " + str(TestUtilities.geodatabasePath))
    
        inputFeatureCount = int(arcpy.GetCount_management(inputPolygonFC).getOutput(0)) 
        print("Input FeatureClass: " + str(inputPolygonFC))
        print("Input Feature Count: " +  str(inputFeatureCount))
            
        if (inputFeatureCount < 1) :
            print("Invalid Input Feature Count: " +  str(inputFeatureCount))
           
        numberOfPeaks = 3
           
        ########################################################3
        # Execute the Model under test:   
        arcpy.FindLocalPeaks_MAoT(inputPolygonFC, numberOfPeaks, inputSurface, outputPointsFC)
        ########################################################3
    
        # Verify the results    
        outputFeatureCount = int(arcpy.GetCount_management(outputPointsFC).getOutput(0)) 
        print("Output FeatureClass: " + str(outputPointsFC))
        print("Output Feature Count: " +  str(outputFeatureCount))
                
        if (outputPointsFC < 3) :
            print("Invalid Output Feature Count: " +  str(outputFeatureCount))
            raise Exception("Test Failed")
            
        # WORKAROUND: delete scratch db
        print("Deleting Scratch Workspace (Workaround)")
        TestUtilities.deleteScratch()        
        
        print("Test Successful")
                
    except arcpy.ExecuteError: 
        # Get the tool error messages 
        msgs = arcpy.GetMessages() 
        arcpy.AddError(msgs) 
    
        # return a system error code
        sys.exit(-1)
        
    except Exception as e:
        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
    
        # Concatenate information together concerning the error into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
        msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages() + "\n"
    
        # Return python error messages for use in script tool or Python Window
        arcpy.AddError(pymsg)
        arcpy.AddError(msgs)
#.........这里部分代码省略.........
开发者ID:GISkev,项目名称:solutions-geoprocessing-toolbox,代码行数:101,代码来源:TestModelLocalPeaks.py

示例9: RunTest

def RunTest():
    try:
        arcpy.AddMessage("Starting Test: TestLocalPeaks")

        #TEST_IMPLEMENTED = False
        #
        #if not TEST_IMPLEMENTED :
        #    arcpy.AddWarning("***Test Not Yet Implemented***")
        #    return

        # TODO: once model has a version that works with local surface data 
        # (rather than image service), then finish this test/implementation below
        #
        # alternately you can add an image service connection in Catalog and 
        # fill in the parameter below

        if arcpy.CheckExtension("Spatial") == "Available":
            print("Checking out Spatial Analyst license...")
            arcpy.CheckOutExtension("Spatial")
        else:
            # Raise a custom exception
            raise Exception("LicenseError")

        if arcpy.CheckExtension("3D") == "Available":
            print("Checking out 3D Analyst license...")
            arcpy.CheckOutExtension("3D")
        else:
            raise Exception("LicenseError")

        try:
            print("Getting Advanced license...")
            import arcinfo
        except ImportError:
            print("Could not use ArcGIS Advanced license...")
            raise Exception
        arcpy.env.overwriteOutput = True
        arcpy.env.scratchWorkspace = TestUtilities.scratchGDB

        # WORKAROUND
        print("Creating New Scratch Workspace (Workaround)")
        TestUtilities.createScratch()

        # Getting inputs
        print("Getting inputs...")
        print("inputPolygonFC...")
        inputPolygonFC = os.path.join(TestUtilities.inputGDB, "samplePolygonArea")
        print("inputSurface...")
        inputSurface = TestUtilities.inputElevationURL
        print("outputPointsFC")
        outputPointsFC = os.path.join(TestUtilities.outputGDB, "LocalPeaks")
        print("ImportToolbox--MAoT...")
        arcpy.ImportToolbox(TestUtilities.toolbox, "MAoT")

        # mf - these have been tested
        # # Check For Valid Input
        # print("Checking valid inputs...")
        # objects2Check = []
        # #objects2Check.extend([inputPolygonFC, inputSurface, toolbox])
        # objects2Check.extend([inputPolygonFC, toolbox])
        # for object2Check in objects2Check :
        #     desc = arcpy.Describe(object2Check)
        #     if desc == None :
        #         raise Exception("Bad Input")
        #     else :
        #         print("Valid Object: " + desc.Name)

        # Set environment settings
        print("Running from: " + str(TestUtilities.currentPath))
        print("Geodatabase path: " + str(TestUtilities.geodatabasePath))
        inputFeatureCount = int(arcpy.GetCount_management(inputPolygonFC).getOutput(0)) 
        print("Input FeatureClass: " + str(inputPolygonFC))
        print("Input Feature Count: " +  str(inputFeatureCount))
        # if (inputFeatureCount < 1):
        #     print("Invalid Input Polygon Feature Count: " +  str(inputFeatureCount))

        # Convert input elevation service to local dataset surface
        print("Converting input image service into a local raster surface")
        polygonExtent = arcpy.Describe(inputPolygonFC).extent
        print("Using extent: " + str(polygonExtent))
        cellSize = CellSize(inputPolygonFC)
        print("Using cell size: " + str(cellSize))
        localSurf = None
        srWGS84 = arcpy.SpatialReference(4326) # GCS_WGS_1984
        srWebMerc = arcpy.SpatialReference(3857) #Web_Mercator_Auxiliary_Sphere
        print("Reworking inputs from image service...")
        try:
            tempClipExtent = os.path.join(TestUtilities.scratchGDB,"tempClipExtent")
            localSurf = os.path.join(TestUtilities.scratchGDB,"localSurf")
            print("     projecting input clip to WGS 1984 to match service...")
            arcpy.Project_management(inputPolygonFC,tempClipExtent,srWGS84)
            tempCellSize = CellSize(tempClipExtent)
            #MakeImageServerLayer_management (in_image_service, out_imageserver_layer, {template},
            #{band_index}, {mosaic_method}, {order_field},
            #{order_base_value}, {lock_rasterid}, {cell_size},
            #{where_clause}, {processing_template})
            print("     getting image service layer with cell size " + str(tempCellSize) + "...")
            arcpy.MakeImageServerLayer_management(inputSurface, "inputSurface", tempClipExtent,
                                                  "#", "#", "#",
                                                  "#", "#", tempCellSize)
            print("     projecting image service layer to match target data...")
#.........这里部分代码省略.........
开发者ID:chinasio,项目名称:solutions-geoprocessing-toolbox,代码行数:101,代码来源:TestModelLocalPeaks.py

示例10: test_zone_properties_from_id

 def test_zone_properties_from_id(self):
   hPk = dbHelp.setup_test_hero_using_default_values()
   z = dbHelp.create_test_zone_obj()
   testZoneKey = ZoneDefinitionFields.EMPTY_SPACE
   z.save_changes(hPk)
   zPk = z.get_pk()
   z2 = z.construct_model_from_pk(zPk)
   self.assertEqual(z.definitionKey, testZoneKey)
   self.assertEqual(z.get_fullName(), ZoneDefinition.get_name_for_key(testZoneKey) + " Alpha")
   self.assertEqual(z.suffix,"Alpha")
   self.assertEqual(z.monstersKilled, 2)
   self.assertEqual(z.maxMonsters,15)
   self.assertEqual(z.lvl, 3)
   self.assertEqual(z.get_description(),ZoneDefinition.get_description_for_key(testZoneKey))
   oldCount = tu.get_record_count_from_table(ZoneDBFields.COLLECTION_NAME)
   z.save_changes(hPk)
   newCount = tu.get_record_count_from_table(ZoneDBFields.COLLECTION_NAME)
   self.assertEqual(oldCount , newCount)
开发者ID:joelliusp,项目名称:SpaceHabit,代码行数:18,代码来源:Test_Zone.py

示例11: test_monster_properties_from_dict

  def test_monster_properties_from_dict(self):
    hpk = dbHelp.setup_test_hero_using_default_values()
    md = dbHelp.create_test_monster_dict()
    m = Monster.construct_model_from_dict(md)

    self.assertEqual(m.nowHp,100)
    self.assertEqual(m.maxHp,150)
    self.assertEqual(m.get_baseXpReward(),1)
    self.assertEqual(m.get_treasureDropRate(),.1)
    self.assertEqual(m.definitionKey,MonsterDefinitionFields.AMBUSH_PIRATES)
    self.assertEqual(len(m.get_treasureDrops()), 0)
    self.assertEqual(m.get_name(),"Sneaky Ambush Pirates")
    self.assertEqual(m.get_description(),"These Sneaky Pirates hide behind asteroids "
        "and surprise you. They're sorta like deadlines.")

    oldCount = tu.get_record_count_from_table(MonsterDbFields.COLLECTION_NAME)

    m.save_changes(hpk)
    newcount = tu.get_record_count_from_table(MonsterDbFields.COLLECTION_NAME)
    self.assertEqual(oldCount,newcount)
开发者ID:joelliusp,项目名称:SpaceHabit,代码行数:20,代码来源:Test_Monster.py

示例12: test_save_counts

  def test_save_counts(self):
    hDict = dbHelp.create_test_hero_dict()
    h = Hero.construct_model_from_dict(hDict)
    oldHeroCount = tu.get_record_count_from_table(HeroDbFields.COLLECTION_NAME)
    oldZoneCOunt = tu.get_record_count_from_table(ZoneDBFields.COLLECTION_NAME)
    h.save_changes()
    newHeroCount = tu.get_record_count_from_table(HeroDbFields.COLLECTION_NAME)
    newZoneCount = tu.get_record_count_from_table(ZoneDBFields.COLLECTION_NAME)
    self.assertEqual(oldHeroCount+1,newHeroCount)
    self.assertEqual(oldZoneCOunt+1,newZoneCount)

    oldHeroCount = tu.get_record_count_from_table(HeroDbFields.COLLECTION_NAME)
    oldZoneCOunt = tu.get_record_count_from_table(ZoneDBFields.COLLECTION_NAME)
    h.save_changes()
    newHeroCount = tu.get_record_count_from_table(HeroDbFields.COLLECTION_NAME)
    newZoneCount = tu.get_record_count_from_table(ZoneDBFields.COLLECTION_NAME)
    self.assertEqual(oldHeroCount,newHeroCount)
    self.assertEqual(oldZoneCOunt,newZoneCount)
开发者ID:joelliusp,项目名称:SpaceHabit,代码行数:18,代码来源:Test_Hero.py


注:本文中的TestUtilities类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。