def test_with_general_function(self): utils.add_field_with_value(self.shapefile, self.field_added, field_type="LONG") utils.populate_field(self.shapefile, lambda row: row[0]**2, self.field_added, "FID") with arcpy.da.SearchCursor(self.shapefile, [self.field_added, "FID"]) as cur: for row in cur: nt.assert_equal(row[0], row[1]**2)
def test_with_general_function(self): utils.add_field_with_value(self.shapefile, self.field_added, field_type="LONG") utils.populate_field( self.shapefile, lambda row: row[0]**2, self.field_added, "FID" ) with arcpy.da.SearchCursor(self.shapefile, [self.field_added, "FID"]) as cur: for row in cur: nt.assert_equal(row[0], row[1] ** 2)
def test_with_dictionary(self): value_dict = {n: n for n in range(7)} value_fxn = lambda row: value_dict.get(row[0], -1) utils.add_field_with_value(self.shapefile, self.field_added, field_type="LONG") utils.populate_field(self.shapefile, lambda row: value_dict.get(row[0], -1), self.field_added, "FID") with arcpy.da.SearchCursor(self.shapefile, [self.field_added, "FID"]) as cur: for row in cur: nt.assert_equal(row[0], row[1])
def test_with_dictionary(self): value_dict = {n: n for n in range(7)} value_fxn = lambda row: value_dict.get(row[0], -1) utils.add_field_with_value(self.shapefile, self.field_added, field_type="LONG") utils.populate_field( self.shapefile, lambda row: value_dict.get(row[0], -1), self.field_added, "FID" ) with arcpy.da.SearchCursor(self.shapefile, [self.field_added, "FID"]) as cur: for row in cur: nt.assert_equal(row[0], row[1])