Esempio n. 1
0
 def test_Features(self):
     try:
         fo = testGP.FieldObject()
         
         fo.setFieldOrder(["field1", "field2"])
         fo.setLabels({"field1":"Field 1","field2":"Field 2"})
         
         try:
             fo.addFeature({"field":"1val2","field2":"2val2"})
             raise Exception("Should have thrown an exception because labels weren't defined")
         except:# Exception, e:
             pass#print "Caught labels undefined exception - "+e.message        
         
         
         fo.addFeature({"field1":"1val1","field2":"2val1"})
         fo.addFeature({"field1":"1val2","field2":"2val2"})  
         assert 2 == fo.getNumberOfFeatures(), fo.getNumberOfFeatures()
         
         assert {'field2': '2val1', 'field1': '1val1'} == fo.getFeature(0), fo.getFeature(0)
         assert {'field2': '2val2', 'field1': '1val2'} ==  fo.getFeature(1), fo.getFeature(1)
         
         assert ['1val1', '2val1'] == fo.getFeatureList(0), fo.getFeatureList(0)
         assert ['1val2', '2val2'] == fo.getFeatureList(1), fo.getFeatureList(1)
     
         try:
             fo.addFeature({"field":"1val2","field2":"2val2"})
             raise Exception("Should have thrown an exception because fields didn't match")
         except:# Exception, e:
             pass#print "Caught bad feature exception - "+e.message
         return 1
     except Exception, e:
         print e
         return 0
Esempio n. 2
0
 def test_Labels(self):
     try:
         fo = testGP.FieldObject()
         fo.setLabels({"field1":"Field 1","field2":"Field 2"})
         assert {'field2': 'Field 2', 'field1': 'Field 1'} == fo.getLabels(), fo.getLabels()
         assert ['Field 2', 'Field 1'] == fo.getLabelsList(), fo.getLabelsList()
         return 1
     except Exception, e:
         print e
         return 0
Esempio n. 3
0
 def test_Types(self):
     try:
         fo = testGP.FieldObject()
         labelsList = {"field1":"Field 1","field2":"Field 2","field3":"Field 3"}
         fo.setLabels(labelsList)
         fo.setTypes({"field1":"esriFieldTypeOID","field2":"esriFieldTypeDate", "field3":"esriFieldTypeDate"})
         assert "Field 2" == labelsList.values()[fo.getDateFields()[0]], labelsList.values()[fo.getDateFields()[0]]
         assert "Field 3" == labelsList.values()[fo.getDateFields()[1]], labelsList.values()[fo.getDateFields()[1]]
         assert "Field 1" == labelsList.values()[fo.getIDField()], labelsList.values()[fo.getIDField()] 
         return 1
     except Exception, e:
         print e
         return 0
    def test_CSV(self, keep=True):
        rWriter = testGP.ReportWriter("CSV")

        inputJSON = Generator.generateInputString_CSV()
        featureSet = arcpy.AsShape(json.loads(inputJSON)['featureSet'], True)
        testObject = testGP.FieldObject(featureSet)
        testObject.setFormats({"date": "dd-MM-yyyy", 'floatPrecision': 1})

        fPath = ""
        try:
            fPath = rWriter.write(testObject, doZip=False)
        except Exception, e:
            print "Failed writing CSV: " + e.message
            return 0
Esempio n. 5
0
    def test_Format(self):
        try:               
            fo = testGP.FieldObject()
            fo.setFieldOrder(["AcquisitionDate", "Tag", "SensorName", "OBJECTID"])
            fo.setTypes({"AcquisitionDate":"esriFieldTypeDate", "Tag":"esriFieldTypeString", "SensorName":"esriFieldTypeString", "OBJECTID":"esriFieldTypeOID"})
            fo.addFeature({'AcquisitionDate':'1338622980000', 'Tag':'MS', 'SensorName':'GeoEye-1', 'OBJECTID':'1'})
            
            fo.setFormats({"date": "MM/dd-yyyy"})
            assert ['06/02-2012', 'MS', 'GeoEye-1', '1'] == fo.getFeatureList(0, doFormat=True), str(fo.getFeatureList(0, doFormat=True))

            fo.setFormats({"date": "yy-MM"})
            assert ['12-06', 'MS', 'GeoEye-1', '1'] == fo.getFeatureList(0, doFormat=True), fo.getFeatureList(0, doFormat=True)
            assert ['1338622980000', 'MS', 'GeoEye-1'] == fo.getFeatureList(0, doFormat=False, doIncludeID=False), fo.getFeatureList(0, doFormat=False, doIncludeID=False)
            
            fo.setFormats({})
            assert ['1338622980000', 'MS', 'GeoEye-1', '1'] == fo.getFeatureList(0, doFormat=True), fo.getFeatureList(0, doFormat=True)
            return 1
        except Exception, e:
            print e
            return 0