[GRASS-SVN] r69535 - in grass/trunk/vector/v.info: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Sep 19 09:42:28 PDT 2016
Author: huhabla
Date: 2016-09-19 09:42:28 -0700 (Mon, 19 Sep 2016)
New Revision: 69535
Added:
grass/trunk/vector/v.info/testsuite/
grass/trunk/vector/v.info/testsuite/test_vinfo.py
Modified:
grass/trunk/vector/v.info/local_proto.h
grass/trunk/vector/v.info/main.c
grass/trunk/vector/v.info/print.c
Log:
vector modules: Added layer specific database information to v.info extended metadata flag
Modified: grass/trunk/vector/v.info/local_proto.h
===================================================================
--- grass/trunk/vector/v.info/local_proto.h 2016-09-19 14:22:39 UTC (rev 69534)
+++ grass/trunk/vector/v.info/local_proto.h 2016-09-19 16:42:28 UTC (rev 69535)
@@ -10,8 +10,8 @@
/* parse.c */
void parse_args(int, char**,
- char **, char**,
- int *, int *, int *);
+ char **, char**,
+ int *, int *, int *);
/* print.c */
void format_double(double, char *);
@@ -19,4 +19,4 @@
void print_topo(const struct Map_info *);
void print_columns(const struct Map_info *, const char *, const char *);
void print_info(const struct Map_info *);
-void print_shell(const struct Map_info *);
+void print_shell(const struct Map_info *, const char *);
Modified: grass/trunk/vector/v.info/main.c
===================================================================
--- grass/trunk/vector/v.info/main.c 2016-09-19 14:22:39 UTC (rev 69534)
+++ grass/trunk/vector/v.info/main.c 2016-09-19 16:42:28 UTC (rev 69535)
@@ -82,7 +82,7 @@
}
if (shell_flag & SHELL_BASIC) {
- print_shell(&Map);
+ print_shell(&Map, field_opt);
}
if (shell_flag & SHELL_REGION) {
print_region(&Map);
Modified: grass/trunk/vector/v.info/print.c
===================================================================
--- grass/trunk/vector/v.info/print.c 2016-09-19 14:22:39 UTC (rev 69534)
+++ grass/trunk/vector/v.info/print.c 2016-09-19 16:42:28 UTC (rev 69535)
@@ -165,12 +165,12 @@
db_shutdown_driver(driver);
}
-void print_shell(const struct Map_info *Map)
+void print_shell(const struct Map_info *Map, const char *field_opt)
{
int map_type;
int time_ok, first_time_ok, second_time_ok;
char timebuff[256];
-
+ struct field_info *fi;
struct TimeStamp ts;
time_ok = first_time_ok = second_time_ok = FALSE;
@@ -263,6 +263,18 @@
if (Vect_level(Map) > 0) {
fprintf(stdout, "num_dblinks=%d\n",
Vect_get_num_dblinks(Map));
+
+ if (Vect_get_num_dblinks(Map) > 0) {
+ fi = Vect_get_field2(Map, field_opt);
+ if(fi != NULL) {
+ fprintf(stdout, "attribute_layer_number=%i\n",fi->number);
+ fprintf(stdout, "attribute_layer_name=%s\n",fi->name);
+ fprintf(stdout, "attribute_database=%s\n",fi->database);
+ fprintf(stdout, "attribute_database_driver=%s\n",fi->driver);
+ fprintf(stdout, "attribute_table=%s\n",fi->table);
+ fprintf(stdout, "attribute_primary_key=%s\n",fi->key);
+ }
+ }
}
fprintf(stdout, "projection=%s\n",
Added: grass/trunk/vector/v.info/testsuite/test_vinfo.py
===================================================================
--- grass/trunk/vector/v.info/testsuite/test_vinfo.py (rev 0)
+++ grass/trunk/vector/v.info/testsuite/test_vinfo.py 2016-09-19 16:42:28 UTC (rev 69535)
@@ -0,0 +1,137 @@
+from grass.gunittest.case import TestCase
+from grass.gunittest.main import test
+
+
+class TestVInfo(TestCase):
+ """Test the shell output of v.info that is not location/mapset or user dependent
+ """
+
+ test_vinfo_no_db = 'test_vinfo_no_db'
+ test_vinfo_with_db = 'test_vinfo_with_db'
+ test_vinfo_with_db_3d = 'test_vinfo_with_db_3d'
+
+ # All maps should be tested against these references
+ reference = dict(format="native", level=2,
+ nodes=0, points=5, lines=0, boundaries=0,
+ centroids=0, areas=0, islands=0, primitives=5,
+ scale="1:1")
+
+ @classmethod
+ def setUpClass(cls):
+ """Generate some vector layer with attribute table, z coordinates
+ and timestamp
+ """
+ cls.runModule('v.random', output=cls.test_vinfo_no_db, npoints=5,
+ zmin=0, zmax=100)
+
+ cls.runModule('v.random', output=cls.test_vinfo_with_db, npoints=5,
+ zmin=0, zmax=100,
+ column="elevation")
+
+ cls.runModule('v.random', output=cls.test_vinfo_with_db_3d, npoints=5,
+ zmin=0, zmax=100,
+ column="elevation",
+ flags="z")
+
+ cls.runModule("v.timestamp", map=cls.test_vinfo_with_db_3d, date='15 jan 1994')
+
+ @classmethod
+ def tearDownClass(cls):
+ """Remove created maps
+ """
+ cls.runModule('g.remove', flags='f', type='vector',
+ name=[cls.test_vinfo_no_db,
+ cls.test_vinfo_with_db,
+ cls.test_vinfo_with_db_3d])
+
+ def test_smoke(self):
+ """Simply test running the module with different parameters
+ """
+ self.assertModule('v.info', map=self.test_vinfo_with_db_3d)
+ self.assertModule('v.info', map=self.test_vinfo_with_db_3d, flags='e')
+ self.assertModule('v.info', map=self.test_vinfo_with_db_3d, flags='et')
+ self.assertModule('v.info', map=self.test_vinfo_with_db_3d, flags='tg')
+ self.assertModule('v.info', map=self.test_vinfo_with_db_3d, flags='t')
+ self.assertModule('v.info', map=self.test_vinfo_with_db_3d, flags='c')
+ self.assertModule('v.info', map=self.test_vinfo_with_db_3d, flags='h')
+
+ def test_common_references(self):
+ """Test all maps against the common references
+ """
+ self.assertModuleKeyValue('v.info', map=self.test_vinfo_no_db, flags='etg',
+ sep="=", precision=0.1,
+ reference=self.reference)
+ self.assertModuleKeyValue('v.info', map=self.test_vinfo_with_db, flags='etg',
+ sep="=", precision=0.1,
+ reference=self.reference)
+ self.assertModuleKeyValue('v.info', map=self.test_vinfo_with_db_3d, flags='etg',
+ sep="=", precision=0.1,
+ reference=self.reference)
+
+ def test_info_no_db(self):
+ """Test the simple vector map
+ """
+ self.assertModuleKeyValue('v.info', map=self.test_vinfo_no_db, flags='etg',
+ sep="=", precision=0.1,
+ reference=dict(name=self.test_vinfo_no_db,
+ map3d=0,
+ num_dblinks=0,
+ bottom=0.0,
+ top=0.0))
+
+ def test_info_with_db(self):
+ """Test the vector map with database
+ """
+ self.assertModuleKeyValue('v.info', map=self.test_vinfo_with_db, flags='etg',
+ sep="=", precision=0.1, layer="1",
+ reference=dict(name=self.test_vinfo_with_db,
+ num_dblinks=1,
+ attribute_layer_name=self.test_vinfo_with_db,
+ attribute_layer_number=1,
+ attribute_database_driver="sqlite",
+ attribute_table=self.test_vinfo_with_db,
+ attribute_primary_key="cat",
+ timestamp="none",
+ map3d=0,
+ bottom=0.0,
+ top=0.0))
+
+ def test_info_with_db_wrong_layer(self):
+ """Test the vector map with database and set the wrong layer, the output should not contain attribute data
+ """
+ self.assertModuleKeyValue('v.info', map=self.test_vinfo_with_db, flags='etg',
+ sep="=", precision=0.1, layer="2",
+ reference=dict(name=self.test_vinfo_with_db,
+ num_dblinks=1,
+ timestamp="none",
+ map3d=0,
+ bottom=0.0,
+ top=0.0))
+
+ def test_info_with_db_3d(self):
+ """Test the vector map with database, z coordinates and timestamp
+ """
+ self.assertModuleKeyValue('v.info', map=self.test_vinfo_with_db_3d, flags='etg',
+ sep="=", precision=0.1, layer="1",
+ reference=dict(name=self.test_vinfo_with_db_3d,
+ num_dblinks=1,
+ attribute_layer_name=self.test_vinfo_with_db_3d,
+ attribute_layer_number=1,
+ attribute_database_driver="sqlite",
+ attribute_table=self.test_vinfo_with_db_3d,
+ attribute_primary_key="cat",
+ map3d=1, timestamp='15 Jan 1994'))
+
+ def test_database_table(self):
+ """Test the database table column and type of the two vector maps with attribute data
+ """
+ self.assertModuleKeyValue('v.info', map=self.test_vinfo_with_db, flags='c',
+ sep="|", precision=0.1,
+ reference={"INTEGER":"cat", "DOUBLE PRECISION":"elevation"})
+
+ self.assertModuleKeyValue('v.info', map=self.test_vinfo_with_db, flags='c',
+ sep="|", precision=0.1,
+ reference={"INTEGER":"cat", "DOUBLE PRECISION":"elevation"})
+
+if __name__ == '__main__':
+ test()
More information about the grass-commit
mailing list