~ubuntu-branches/ubuntu/trusty/mapnik/trusty

« back to all changes in this revision

Viewing changes to tests/python_tests/datasource_test.py

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2009-08-27 00:28:37 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090827002837-ztqzfg2rmclfh4i9
Tags: 0.6.1-0ubuntu1
* New upstream release.
* Change usr/lib to usr/lib* to enable build on 64 bits systems due to new
  configuration in SConstruct in :
  - debian/libmapnik-dev.install
  - debian/libmapnik0.6.install
  - debian/mapnik-plugin-base

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
from nose.tools import *
 
4
from utilities import execution_path
 
5
 
 
6
import os, mapnik
 
7
 
 
8
def setup():
 
9
    # All of the paths used are relative, if we run the tests
 
10
    # from another directory we need to chdir()
 
11
    os.chdir(execution_path('.'))
 
12
    
 
13
def test_field_listing():
 
14
    lyr = mapnik.Layer('test')
 
15
    lyr.datasource = mapnik.Shapefile(file='../data/shp/poly.shp')
 
16
    fields = lyr.datasource.fields()
 
17
    eq_(fields, ['AREA', 'EAS_ID', 'PRFEDEA'])
 
18
 
 
19
def test_total_feature_count():
 
20
    lyr = mapnik.Layer('test')
 
21
    lyr.datasource = mapnik.Shapefile(file='../data/shp/poly.shp')
 
22
    features = lyr.datasource.all_features()
 
23
    num_feats = len(features)
 
24
    eq_(num_feats, 10)
 
25
 
 
26
def test_feature_envelope():
 
27
    lyr = mapnik.Layer('test')
 
28
    lyr.datasource = mapnik.Shapefile(file='../data/shp/poly.shp')
 
29
    features = lyr.datasource.all_features()
 
30
    for feat in features:
 
31
        env = feat.envelope()
 
32
        contains = lyr.envelope().contains(env)
 
33
        eq_(contains, True)
 
34
        intersects = lyr.envelope().contains(env)
 
35
        eq_(intersects, True)
 
36
 
 
37
def test_feature_attributes():
 
38
    lyr = mapnik.Layer('test')
 
39
    lyr.datasource = mapnik.Shapefile(file='../data/shp/poly.shp')
 
40
    features = lyr.datasource.all_features()
 
41
    feat = features[0]
 
42
    attrs = {'PRFEDEA': u'35043411', 'EAS_ID': 168, 'AREA': 215229.266}
 
43
    eq_(feat.attributes, attrs)
 
44
    fld_name = 'AREA'
 
45
    fld_idx = lyr.datasource.fields().index(fld_name)
 
46
    eq_(lyr.datasource.field_types()[fld_idx],type(feat.attributes[fld_name]))
 
47
    
 
 
b'\\ No newline at end of file'