[GRASS-SVN] r66073 - in grass/trunk/lib/python/pygrass: . vector vector/testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Aug 31 03:40:37 PDT 2015


Author: huhabla
Date: 2015-08-31 03:40:37 -0700 (Mon, 31 Aug 2015)
New Revision: 66073

Modified:
   grass/trunk/lib/python/pygrass/utils.py
   grass/trunk/lib/python/pygrass/vector/abstract.py
   grass/trunk/lib/python/pygrass/vector/table.py
   grass/trunk/lib/python/pygrass/vector/testsuite/test_doctests.py
Log:
pygrass raster: Fixed several doctests


Modified: grass/trunk/lib/python/pygrass/utils.py
===================================================================
--- grass/trunk/lib/python/pygrass/utils.py	2015-08-30 20:55:38 UTC (rev 66072)
+++ grass/trunk/lib/python/pygrass/utils.py	2015-08-31 10:40:37 UTC (rev 66073)
@@ -104,7 +104,7 @@
 def copy(existingmap, newmap, maptype, **kwargs):
     """Copy a map
 
-    >>> copy('census', 'mycensus', 'vector')
+    >>> copy('census_wake2000', 'mycensus', 'vector')
     >>> rename('mycensus', 'mynewcensus', 'vector')
     >>> remove('mynewcensus', 'vector')
 
@@ -137,7 +137,7 @@
 def get_mapset_vector(mapname, mapset=''):
     """Return the mapset of the vector map
 
-    >>> get_mapset_vector('census')
+    >>> get_mapset_vector('census_wake2000')
     'PERMANENT'
 
     """
@@ -174,8 +174,8 @@
 
     """
     (east, north) = coord
-    return (libraster.Rast_northing_to_row(north, region.c_region),
-            libraster.Rast_easting_to_col(east, region.c_region))
+    return (libraster.Rast_northing_to_row(north, region.byref()),
+            libraster.Rast_easting_to_col(east, region.byref()))
 
 
 def pixel2coor(pixel, region):
@@ -190,8 +190,8 @@
 
     """
     (col, row) = pixel
-    return (libraster.Rast_row_to_northing(row, region.c_region),
-            libraster.Rast_col_to_easting(col, region.c_region))
+    return (libraster.Rast_row_to_northing(row, region.byref()),
+            libraster.Rast_col_to_easting(col, region.byref()))
 
 
 def get_raster_for_points(poi_vector, raster, column=None, region=None):
@@ -201,23 +201,33 @@
 
     >>> from grass.pygrass.vector import VectorTopo
     >>> from grass.pygrass.raster import RasterRow
-    >>> ele = RasterRow('elevation')
-    >>> copy('schools','myschools','vector')
-    >>> sch = VectorTopo('myschools')
-    >>> sch.open(mode='r')
-    >>> get_raster_for_points(sch, ele)               # doctest: +ELLIPSIS
-    [(1, 633649.2856743174, 221412.94434781274, 145.06602), ...]
-    >>> sch.table.columns.add('elevation','double precision')
-    >>> 'elevation' in sch.table.columns
+    >>> from grass.pygrass.gis.region import Region
+    >>> region = Region()
+    >>> region.from_rast('elev_state_500m')
+    >>> region.set_raster_region()
+    >>> ele = RasterRow('elev_state_500m')
+    >>> copy('firestations','myfirestations','vector')
+    >>> fire = VectorTopo('myfirestations')
+    >>> fire.open(mode='r')
+    >>> l = get_raster_for_points(fire, ele, region=region)
+    >>> l[0]                                        # doctest: +ELLIPSIS
+    (1, 620856.9585876337, 230066.3831321055, 111.2153883384)
+    >>> l[1]                                        # doctest: +ELLIPSIS
+    (2, 625331.9185974908, 229990.82160762616, 89.978796115200012)
+    >>> fire.table.columns.add('elev_state_500m','double precision')
+    >>> 'elev_state_500m' in fire.table.columns
     True
-    >>> get_raster_for_points(sch, ele, column='elevation')
+    >>> get_raster_for_points(fire, ele, column='elev_state_500m', region=region)
     True
-    >>> sch.table.filters.select('NAMESHORT','elevation')
-    Filters(u'SELECT NAMESHORT, elevation FROM myschools;')
-    >>> cur = sch.table.execute()
-    >>> cur.fetchall()                                # doctest: +ELLIPSIS
-    [(u'SWIFT CREEK', 145.06602), ... (u'9TH GRADE CTR', None)]
-    >>> remove('myschools','vect')
+    >>> fire.table.filters.select('LABEL', 'elev_state_500m')
+    Filters(u'SELECT LABEL, elev_state_500m FROM myfirestations;')
+    >>> cur = fire.table.execute()
+    >>> r = cur.fetchall()
+    >>> r[0]                                        # doctest: +ELLIPSIS
+    (u'Morrisville #3', 111.2153883384)
+    >>> r[1]                                        # doctest: +ELLIPSIS
+    (u'Morrisville #1', 89.97879611520001)
+    >>> remove('myfirestations','vect')
 
 
     :param point: point vector object
@@ -419,7 +429,7 @@
         vect.comment = 'This is a comment'
 
         vect.table.conn.commit()
-        
+
         vect.organization = "Thuenen Institut"
         vect.person = "Soeren Gebbert"
         vect.title = "Test dataset"

Modified: grass/trunk/lib/python/pygrass/vector/abstract.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/abstract.py	2015-08-30 20:55:38 UTC (rev 66072)
+++ grass/trunk/lib/python/pygrass/vector/abstract.py	2015-08-31 10:40:37 UTC (rev 66073)
@@ -377,8 +377,7 @@
             self.layer = self.dblinks.by_layer(layer).layer
             self.table = self.dblinks.by_layer(layer).table()
             self.n_lines = self.table.n_rows()
-        self.writeable = False
-        self.mapset == utils.getenv("MAPSET")
+        self.writeable =  self.mapset == utils.getenv("MAPSET")
         # Initialize the finder
         self.find = {'by_point': PointFinder(self.c_mapinfo, self.table,
                                              self.writeable),

Modified: grass/trunk/lib/python/pygrass/vector/table.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/table.py	2015-08-30 20:55:38 UTC (rev 66072)
+++ grass/trunk/lib/python/pygrass/vector/table.py	2015-08-31 10:40:37 UTC (rev 66073)
@@ -168,18 +168,18 @@
 
     >>> import sqlite3
     >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
-    >>> cols_sqlite = Columns('census',
+    >>> cols_sqlite = Columns(test_vector_name,
     ...                       sqlite3.connect(get_path(path)))
     >>> cols_sqlite.tname
-    u'census'
+    u'table_doctest_map'
 
     For a postgreSQL table:
 
     >>> import psycopg2 as pg                              #doctest: +SKIP
-    >>> cols_pg = Columns('boundary_municp_pg',
+    >>> cols_pg = Columns(test_vector_name,
     ...                   pg.connect('host=localhost dbname=grassdb')) #doctest: +SKIP
     >>> cols_pg.tname #doctest: +SKIP
-    'boundary_municp_pg'                                   #doctest: +SKIP
+    'table_doctest_map'                                   #doctest: +SKIP
 
     """
     def __init__(self, tname, connection, key='cat'):
@@ -212,15 +212,12 @@
         """Return True if two table have the same columns.
 
         >>> import sqlite3
-        >>> path = '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db'
+        >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
         >>> connection = sqlite3.connect(get_path(path))
-        >>> cols0 = Columns('census', connection)
-        >>> cols1 = Columns('census', connection)
-        >>> cols2 = Columns('hospitals', connection)
+        >>> cols0 = Columns(test_vector_name, connection)
+        >>> cols1 = Columns(test_vector_name, connection)
         >>> cols0 == cols1
         True
-        >>> cols1 == cols2
-        False
         """
         return obj.tname == self.tname and obj.odict == self.odict
 
@@ -234,13 +231,13 @@
         """Return True if is a psycopg connection.
 
         >>> import sqlite3
-        >>> path = '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db'
-        >>> cols_sqlite = Columns('census',
+        >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
+        >>> cols_sqlite = Columns(test_vector_name,
         ...                       sqlite3.connect(get_path(path)))
         >>> cols_sqlite.is_pg()
         False
         >>> import psycopg2 as pg #doctest: +SKIP
-        >>> cols_pg = Columns('boundary_municp_pg',
+        >>> cols_pg = Columns(test_vector_name,
         ...                   pg.connect('host=localhost dbname=grassdb')) #doctest: +SKIP
         >>> cols_pg.is_pg() #doctest: +SKIP
         True
@@ -290,16 +287,16 @@
         Remove it is used to remove a columns.
 
         >>> import sqlite3
-        >>> path = '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db'
-        >>> cols_sqlite = Columns('census',
+        >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
+        >>> cols_sqlite = Columns(test_vector_name,
         ...                       sqlite3.connect(get_path(path)))
         >>> cols_sqlite.sql_descr()                   # doctest: +ELLIPSIS
-        u'cat integer, OBJECTID integer, AREA double precision, ...'
+        u'cat INTEGER, name varchar(50), value double precision'
         >>> import psycopg2 as pg                         # doctest: +SKIP
-        >>> cols_pg = Columns('boundary_municp_pg',
+        >>> cols_pg = Columns(test_vector_name,
         ...                   pg.connect('host=localhost dbname=grassdb')) # doctest: +SKIP
         >>> cols_pg.sql_descr()                 # doctest: +ELLIPSIS +SKIP
-        'cat int4, objectid int4, area float8, perimeter float8, ...'
+        u'cat INTEGER, name varchar(50), value double precision'
         """
         if remove:
             return ', '.join(['%s %s' % (key, val) for key, val in self.items()
@@ -312,16 +309,16 @@
         """Return a list with the column types.
 
         >>> import sqlite3
-        >>> path = '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db'
-        >>> cols_sqlite = Columns('census',
+        >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
+        >>> cols_sqlite = Columns(test_vector_name,
         ...                       sqlite3.connect(get_path(path)))
         >>> cols_sqlite.types()                       # doctest: +ELLIPSIS
-        [u'integer', u'integer', ...]
+        [u'INTEGER', u'varchar(50)', u'double precision']
         >>> import psycopg2 as pg                         # doctest: +SKIP
-        >>> cols_pg = Columns('boundary_municp_pg',
+        >>> cols_pg = Columns(test_vector_name,
         ...                   pg.connect('host=localhost dbname=grassdb')) # doctest: +SKIP
         >>> cols_pg.types()                     # doctest: +ELLIPSIS +SKIP
-        ['int4', 'int4', 'float8', 'float8', 'float8', ...]
+        [u'INTEGER', u'varchar(50)', u'double precision']
 
         """
         return self.odict.values()
@@ -331,16 +328,16 @@
         Remove it is used to remove a columns.
 
         >>> import sqlite3
-        >>> path = '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db'
-        >>> cols_sqlite = Columns('census',
+        >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
+        >>> cols_sqlite = Columns(test_vector_name,
         ...                       sqlite3.connect(get_path(path)))
         >>> cols_sqlite.names()                      # doctest: +ELLIPSIS
-        [u'cat', u'OBJECTID', u'AREA', u'PERIMETER', ...]
+        [u'cat', u'name', u'value']
         >>> import psycopg2 as pg                         # doctest: +SKIP
-        >>> cols_pg = Columns('boundary_municp_pg',       # doctest: +SKIP
+        >>> cols_pg = Columns(test_vector_name,       # doctest: +SKIP
         ...                   pg.connect('host=localhost dbname=grassdb'))
         >>> cols_pg.names()                     # doctest: +ELLIPSIS +SKIP
-        ['cat', 'objectid', 'area', 'perimeter', ...]
+        [u'cat', u'name', u'value']
 
         """
         if remove:
@@ -357,16 +354,16 @@
         """Return a list of tuple with column name and column type.
 
         >>> import sqlite3
-        >>> path = '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db'
-        >>> cols_sqlite = Columns('census',
+        >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
+        >>> cols_sqlite = Columns(test_vector_name,
         ...                       sqlite3.connect(get_path(path)))
         >>> cols_sqlite.items()                       # doctest: +ELLIPSIS
-        [(u'cat', u'integer'), ...]
+        [(u'cat', u'INTEGER'), (u'name', u'varchar(50)'), (u'value', u'double precision')]
         >>> import psycopg2 as pg                         # doctest: +SKIP
-        >>> cols_pg = Columns('boundary_municp_pg',
+        >>> cols_pg = Columns(test_vector_name,
         ...                   pg.connect('host=localhost dbname=grassdb')) # doctest: +SKIP
         >>> cols_pg.items()                     # doctest: +ELLIPSIS +SKIP
-        [('cat', 'int4'), ('objectid', 'int4'), ('area', 'float8'), ...]
+        [(u'cat', u'INTEGER'), (u'name', u'varchar(50)'), (u'value', u'double precision')]
 
         """
         return self.odict.items()
@@ -382,7 +379,7 @@
         >>> import sqlite3
         >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
         >>> from grass.pygrass.utils import copy, remove
-        >>> copy('census','mycensus','vect')
+        >>> copy(test_vector_name,'mycensus','vect')
         >>> cols_sqlite = Columns('mycensus',
         ...                       sqlite3.connect(get_path(path)))
         >>> cols_sqlite.add(['n_pizza'], ['INT'])
@@ -436,7 +433,7 @@
         >>> import sqlite3
         >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
         >>> from grass.pygrass.utils import copy, remove
-        >>> copy('census','mycensus','vect')
+        >>> copy(test_vector_name,'mycensus','vect')
         >>> cols_sqlite = Columns('mycensus',
         ...                       sqlite3.connect(get_path(path)))
         >>> cols_sqlite.add(['n_pizza'], ['INT'])
@@ -449,7 +446,7 @@
         True
 
         >>> import psycopg2 as pg                         # doctest: +SKIP
-        >>> cols_pg = Columns('boundary_municp_pg',
+        >>> cols_pg = Columns(test_vector_name,
         ...                   pg.connect('host=localhost dbname=grassdb')) # doctest: +SKIP
         >>> cols_pg.rename('n_pizza', 'n_pizzas')         # doctest: +SKIP
         >>> 'n_pizza' in cols_pg                          # doctest: +SKIP
@@ -490,7 +487,7 @@
         >>> import sqlite3
         >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
         >>> from grass.pygrass.utils import copy, remove
-        >>> copy('census','mycensus','vect')
+        >>> copy(test_vector_name,'mycensus','vect')
         >>> cols_sqlite = Columns('mycensus',
         ...                       sqlite3.connect(get_path(path)))
         >>> cols_sqlite.add(['n_pizzas'], ['INT'])
@@ -499,7 +496,7 @@
           ...
         DBError: SQLite does not support to cast columns.
         >>> import psycopg2 as pg                         # doctest: +SKIP
-        >>> cols_pg = Columns('boundary_municp_pg',
+        >>> cols_pg = Columns(test_vector_name,
         ...                   pg.connect('host=localhost dbname=grassdb')) # doctest: +SKIP
         >>> cols_pg.cast('n_pizzas', 'float8')            # doctest: +SKIP
         >>> cols_pg['n_pizzas']                           # doctest: +SKIP
@@ -531,18 +528,18 @@
         >>> import sqlite3
         >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
         >>> from grass.pygrass.utils import copy, remove
-        >>> copy('census','mycensus','vect')
+        >>> copy(test_vector_name,'mycensus','vect')
         >>> cols_sqlite = Columns('mycensus',
         ...                       sqlite3.connect(get_path(path)))
-        >>> cols_sqlite.drop('CHILD')                 # doctest: +ELLIPSIS
-        >>> 'CHILD' in cols_sqlite
+        >>> cols_sqlite.drop('name')                 # doctest: +ELLIPSIS
+        >>> 'name' in cols_sqlite
         False
 
         >>> import psycopg2 as pg                         # doctest: +SKIP
-        >>> cols_pg = Columns('boundary_municp_pg',
+        >>> cols_pg = Columns(test_vector_name,
         ...                   pg.connect('host=localhost dbname=grassdb')) # doctest: +SKIP
-        >>> cols_pg.drop('CHILD') # doctest: +SKIP
-        >>> 'CHILD' in cols_pg # doctest: +SKIP
+        >>> cols_pg.drop('name') # doctest: +SKIP
+        >>> 'name' in cols_pg # doctest: +SKIP
         False
         >>> remove('mycensus','vect')
 
@@ -571,18 +568,18 @@
     It is possible to define a Link object or given all the information
     (layer, name, table name, key, database, driver):
 
-    >>> link = Link(1, 'link0', 'census', 'cat',
-    ...             '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db', 'sqlite')
+    >>> link = Link(1, 'link0', test_vector_name, 'cat',
+    ...             '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db', 'sqlite')
     >>> link.layer
     1
     >>> link.name
     'link0'
     >>> link.table_name
-    'census'
+    'table_doctest_map'
     >>> link.key
     'cat'
     >>> link.database
-    '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db'
+    '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
     >>> link.driver
     'sqlite'
     >>> link
@@ -693,12 +690,12 @@
     def __eq__(self, link):
         """Return True if two Link instance have the same parameters.
 
-        >>> l0 = Link(1, 'link0', 'census', 'cat',
+        >>> l0 = Link(1, 'link0', test_vector_name, 'cat',
+        ...           '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db', 'sqlite')
+        >>> l1 = Link(1, 'link0', test_vector_name, 'cat',
+        ...           '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db', 'sqlite')
+        >>> l2 = Link(2, 'link0', test_vector_name, 'cat',
         ...           '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db', 'sqlite')
-        >>> l1 = Link(1, 'link0', 'census', 'cat',
-        ...           '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db', 'sqlite')
-        >>> l2 = Link(2, 'link0', 'census', 'cat',
-        ...           '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db', 'sqlite')
         >>> l0 == l1
         True
         >>> l1 == l2
@@ -719,16 +716,18 @@
     def connection(self):
         """Return a connection object.
 
-        >>> link = Link(1, 'link0', 'census', 'cat',
-        ...             '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db',
+        >>> link = Link(1, 'link0', test_vector_name, 'cat',
+        ...             '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db',
         ...             'sqlite')
         >>> conn = link.connection()
         >>> cur = conn.cursor()
-        >>> cur.execute("SELECT cat,TOTAL_POP,PERIMETER FROM %s" %
+        >>> link.table_name
+        'table_doctest_map'
+        >>> cur.execute("SELECT cat, name, value from %s" %
         ...             link.table_name)              # doctest: +ELLIPSIS
         <sqlite3.Cursor object at ...>
-        >>> cur.fetchone()
-        (1, 44, 757.669)
+        >>> cur.fetchone()     #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
+        (1, u'point', 1.0)
         >>> cur.close()
         >>> conn.close()
 
@@ -762,15 +761,15 @@
     def table(self):
         """Return a Table object.
 
-        >>> link = Link(1, 'link0', 'census', 'cat',
-        ...             '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db',
+        >>> link = Link(1, 'link0', test_vector_name, 'cat',
+        ...             '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db',
         ...             'sqlite')
         >>> table = link.table()
-        >>> table.filters.select('cat', 'TOTAL_POP', 'PERIMETER')
-        Filters(u'SELECT cat, TOTAL_POP, PERIMETER FROM census;')
+        >>> table.filters.select('cat', 'name', 'value')
+        Filters(u'SELECT cat, name, value FROM table_doctest_map;')
         >>> cur = table.execute()
         >>> cur.fetchone()
-        (1, 44, 757.669)
+        (1, u'point', 1.0)
         >>> cur.close()
 
         """
@@ -779,15 +778,15 @@
     def info(self):
         """Print information of the link.
 
-        >>> link = Link(1, 'link0', 'census', 'cat',
-        ...             '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db',
+        >>> link = Link(1, 'link0', test_vector_name, 'cat',
+        ...             '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db',
         ...             'sqlite')
         >>> link.info()
         layer:     1
         name:      link0
-        table:     census
+        table:     table_doctest_map
         key:       cat
-        database:  $GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db
+        database:  $GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db
         driver:    sqlite
 
         """
@@ -803,15 +802,15 @@
     """Interface containing link to the table DB.
 
     >>> from grass.pygrass.vector import VectorTopo
-    >>> cens = VectorTopo('census')
+    >>> cens = VectorTopo(test_vector_name)
     >>> cens.open(mode='r')
     >>> dblinks = DBlinks(cens.c_mapinfo)
     >>> dblinks
-    DBlinks([Link(1, census, sqlite)])
+    DBlinks([Link(1, table_doctest_map, sqlite)])
     >>> dblinks[0]
-    Link(1, census, sqlite)
-    >>> dblinks['census']
-    Link(1, census, sqlite)
+    Link(1, table_doctest_map, sqlite)
+    >>> dblinks[test_vector_name]
+    Link(1, table_doctest_map, sqlite)
     >>> cens.close()
 
     """
@@ -882,16 +881,16 @@
        :type link: a Link object
 
         >>> from grass.pygrass.vector import VectorTopo
-        >>> municip = VectorTopo('census')
-        >>> municip.open(mode='r')
-        >>> dblinks = DBlinks(municip.c_mapinfo)
+        >>> test_vect = VectorTopo(test_vector_name)
+        >>> test_vect.open(mode='r')
+        >>> dblinks = DBlinks(test_vect.c_mapinfo)
         >>> dblinks
-        DBlinks([Link(1, census, sqlite)])
-        >>> link = Link(2, 'pg_link', 'boundary_municp_pg', 'cat',
+        DBlinks([Link(1, table_doctest_map, sqlite)])
+        >>> link = Link(2, 'pg_link', test_vector_name, 'cat',
         ...             'host=localhost dbname=grassdb', 'pg') # doctest: +SKIP
         >>> dblinks.add(link)                             # doctest: +SKIP
         >>> dblinks                                       # doctest: +SKIP
-        DBlinks([Link(1, boundary_municp, sqlite)])
+        DBlinks([Link(1, table_doctest_map, sqlite)])
 
         """
         #TODO: check if open in write mode or not.
@@ -909,14 +908,14 @@
         :type force: boole
 
         >>> from grass.pygrass.vector import VectorTopo
-        >>> municip = VectorTopo('census')
-        >>> municip.open(mode='r')
-        >>> dblinks = DBlinks(municip.c_mapinfo)
+        >>> test_vect = VectorTopo(test_vector_name)
+        >>> test_vect.open(mode='r')
+        >>> dblinks = DBlinks(test_vect.c_mapinfo)
         >>> dblinks
-        DBlinks([Link(1, census, sqlite)])
+        DBlinks([Link(1, table_doctest_map, sqlite)])
         >>> dblinks.remove('pg_link')                     # doctest: +SKIP
         >>> dblinks  # need to open vector map in write mode
-        DBlinks([Link(1, census, sqlite)])
+        DBlinks([Link(1, table_doctest_map, sqlite)])
 
 
         """
@@ -940,12 +939,12 @@
 
     >>> import sqlite3
     >>> path = '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db'
-    >>> tab_sqlite = Table(name='census',
+    >>> tab_sqlite = Table(name=test_vector_name,
     ...                    connection=sqlite3.connect(get_path(path)))
     >>> tab_sqlite.name
-    u'census'
+    u'table_doctest_map'
     >>> import psycopg2                                   # doctest: +SKIP
-    >>> tab_pg = Table('boundary_municp_pg',
+    >>> tab_pg = Table(test_vector_name,
     ...                psycopg2.connect('host=localhost dbname=grassdb',
     ...                                 'pg'))            # doctest: +SKIP
     >>> tab_pg.columns                          # doctest: +ELLIPSIS +SKIP
@@ -986,10 +985,10 @@
 
         >>> import sqlite3
         >>> path = '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db'
-        >>> tab_sqlite = Table(name='census',
+        >>> tab_sqlite = Table(name=test_vector_name,
         ...                    connection=sqlite3.connect(get_path(path)))
         >>> tab_sqlite
-        Table(u'census')
+        Table(u'table_doctest_map')
 
         """
         return "Table(%r)" % (self.name)
@@ -1030,11 +1029,11 @@
         """Return the number of rows
 
         >>> import sqlite3
-        >>> path = '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db'
-        >>> tab_sqlite = Table(name='census',
+        >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
+        >>> tab_sqlite = Table(name=test_vector_name,
         ...                    connection=sqlite3.connect(get_path(path)))
         >>> tab_sqlite.n_rows()
-        2537
+        3
         """
         cur = self.conn.cursor()
         cur.execute(sql.SELECT.format(cols='Count(*)', tname=self.name))
@@ -1058,14 +1057,14 @@
         :type values: list of tuple
 
         >>> import sqlite3
-        >>> path = '$GISDBASE/$LOCATION_NAME/PERMANENT/sqlite/sqlite.db'
-        >>> tab_sqlite = Table(name='census',
+        >>> path = '$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db'
+        >>> tab_sqlite = Table(name=test_vector_name,
         ...                    connection=sqlite3.connect(get_path(path)))
-        >>> tab_sqlite.filters.select('cat', 'TOTAL_POP').order_by('AREA')
-        Filters(u'SELECT cat, TOTAL_POP FROM census ORDER BY AREA;')
+        >>> tab_sqlite.filters.select('cat', 'name').order_by('value')
+        Filters(u'SELECT cat, name FROM table_doctest_map ORDER BY value;')
         >>> cur = tab_sqlite.execute()
-        >>> cur.fetchone()
-        (1856, 0)
+        >>> cur.fetchone()     #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
+         (1, u'point')
 
         """
         try:
@@ -1074,9 +1073,9 @@
             if many and values:
                 return cur.executemany(sqlc, values)
             return cur.execute(sqlc)
-        except:
+        except Exception, e:
             #import ipdb; ipdb.set_trace()
-            raise ValueError("The SQL is not correct:\n%r" % sqlc)
+            raise ValueError("The SQL is not correct:\n%r, SQL error: %s" % (sqlc, str(e)))
 
     def exist(self, cursor=None):
         """Return True if the table already exist in the DB, False otherwise
@@ -1167,6 +1166,6 @@
     """Remove the generated vector map, if exist"""
     from grass.pygrass.utils import get_mapset_vector
     from grass.script.core import run_command
-    mset = get_mapset_vector(test_vector_name, mapset='')
-    if mset:
-        run_command("g.remove", flags='f', type='vector', name=test_vector_name)
+    #mset = get_mapset_vector(test_vector_name, mapset='')
+    #if mset:
+    #    run_command("g.remove", flags='f', type='vector', name=test_vector_name)

Modified: grass/trunk/lib/python/pygrass/vector/testsuite/test_doctests.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/testsuite/test_doctests.py	2015-08-30 20:55:38 UTC (rev 66072)
+++ grass/trunk/lib/python/pygrass/vector/testsuite/test_doctests.py	2015-08-31 10:40:37 UTC (rev 66073)
@@ -37,6 +37,7 @@
     utils.create_test_vector_map(gvector.abstract.test_vector_name)
     utils.create_test_vector_map(gvector.geometry.test_vector_name)
     utils.create_test_vector_map(gvector.find.test_vector_name)
+    utils.create_test_vector_map(gvector.table.test_vector_name)
 
     # this should be called at some top level
     tests.addTests(doctest.DocTestSuite(gvector))
@@ -45,7 +46,7 @@
     tests.addTests(doctest.DocTestSuite(gvector.find))
     tests.addTests(doctest.DocTestSuite(gvector.geometry))
     tests.addTests(doctest.DocTestSuite(gvector.sql))
-    #tests.addTests(doctest.DocTestSuite(gvector.table))
+    tests.addTests(doctest.DocTestSuite(gvector.table))
     return tests
 
 



More information about the grass-commit mailing list