test_db_univar.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """
  2. Created on Sun Jun 07 21:01:34 2018
  3. @author: Sanjeet Bhatti
  4. @author: Vaclav Petras
  5. """
  6. from grass.gunittest.case import TestCase
  7. from grass.gunittest.main import test
  8. from grass.gunittest.gmodules import SimpleModule
  9. class TestDbUnivar(TestCase):
  10. """Test running db.univar script with NULL values and extended stats"""
  11. column_name = "heights"
  12. map_name = "samples"
  13. @classmethod
  14. def setUpClass(cls): # pylint: disable=invalid-name
  15. """Generate vector points in extend larger than raster with values"""
  16. cls.use_temp_region()
  17. cls.runModule("g.region", raster="elevation")
  18. cls.runModule("g.region", e="e+5000", w="w-5000", s="s-5000", n="n+5000")
  19. cls.runModule("v.random", output=cls.map_name, npoints=100, seed=42)
  20. cls.runModule(
  21. "v.db.addtable",
  22. map=cls.map_name,
  23. columns="{} double precision".format(cls.column_name),
  24. )
  25. cls.runModule(
  26. "v.what.rast", map=cls.map_name, raster="elevation", column=cls.column_name
  27. )
  28. @classmethod
  29. def tearDownClass(cls): # pylint: disable=invalid-name
  30. """Remove temporary region and vector"""
  31. cls.del_temp_region()
  32. cls.runModule("g.remove", flags="f", type="vector", name=cls.map_name)
  33. def test_calculate(self):
  34. """Check that db.univar runs"""
  35. module = SimpleModule("db.univar", table=self.map_name, column=self.column_name)
  36. self.assertModule(module)
  37. def test_calculate_extended(self):
  38. """Check that db.univar -e runs"""
  39. module = SimpleModule(
  40. "db.univar", table=self.map_name, flags="e", column=self.column_name
  41. )
  42. self.assertModule(module)
  43. if __name__ == "__main__":
  44. test()