'Testing Data Source Layers.'

def test03a_layers(self):

    print '\nBEGIN    -    expecting    out    of    range    feature    id    error;    safe    to    ignore.\n'
    for source in ds_list:
        ds = DataSource(source.ds)
        for layer in ds:
            self.assertEqual(len(layer), source.nfeat)
            self.assertEqual(source.nfld, layer.num_fields)
            self.assertEqual(source.nfld, len(layer.fields))
            if ((source.driver == 'VRT') and ((GDAL_VERSION > (1, 7, 0)) and (GDAL_VERSION < (1, 7, 3)))):
                pass
            else:
                self.assertEqual(True, isinstance(layer.extent, Envelope))
                self.assertAlmostEqual(source.extent[0], layer.extent.min_x, 5)
                self.assertAlmostEqual(source.extent[1], layer.extent.min_y, 5)
                self.assertAlmostEqual(source.extent[2], layer.extent.max_x, 5)
                self.assertAlmostEqual(source.extent[3], layer.extent.max_y, 5)
            flds = layer.fields
            for f in flds:
                self.assertEqual(True, (f in source.fields))
            self.assertRaises(OGRIndexError, layer.__getitem__, (-1))
            self.assertRaises(OGRIndexError, layer.__getitem__, 50000)
            if hasattr(source, 'field_values'):
                fld_names = source.field_values.keys()
                for fld_name in fld_names:
                    self.assertEqual(source.field_values[fld_name], layer.get_fields(fld_name))
                for (i, fid) in enumerate(source.fids):
                    feat = layer[fid]
                    self.assertEqual(fid, feat.fid)
                    for fld_name in fld_names:
                        self.assertEqual(source.field_values[fld_name][i], feat.get(fld_name))
    print '\nEND    -    expecting    out    of    range    feature    id    error;    safe    to    ignore.'
