test_db_in_ogr.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """
  2. Created on Sun Jun 07 20:14:04 2018
  3. @author: Sanjeet Bhatti
  4. """
  5. from grass.gunittest.case import TestCase
  6. from grass.gunittest.main import test
  7. from grass.gunittest.gmodules import SimpleModule
  8. from grass.script.core import run_command
  9. from grass.script.utils import decode
  10. import os
  11. class TestDbInOgr(TestCase):
  12. """Test db.in.ogr script"""
  13. csvFile = 'sample_data.csv'
  14. dbfFile = 'sample_data.dbf'
  15. tableName1 = 'sample_table1'
  16. tableName2 = 'sample_table2'
  17. @classmethod
  18. def setUpClass(cls):
  19. """Create temporary files. Remove if the tables already exists."""
  20. cls.runModule('db.out.ogr', input='geology', output=cls.csvFile)
  21. cls.runModule('db.out.ogr', input='geology', output=cls.dbfFile,
  22. format='DBF')
  23. cls.runModule('db.droptable', table=cls.tableName1, flags='f')
  24. cls.runModule('db.droptable', table=cls.tableName2, flags='f')
  25. @classmethod
  26. def tearDownClass(cls):
  27. """Remove the created files and the created table"""
  28. os.remove(cls.csvFile)
  29. os.remove(cls.dbfFile)
  30. cls.runModule('db.droptable', table=cls.tableName1, flags='f')
  31. cls.runModule('db.droptable', table=cls.tableName2, flags='f')
  32. def test_import_csv_file(self):
  33. """import csv table"""
  34. module = SimpleModule('db.in.ogr', input=self.csvFile,
  35. output=self.tableName1)
  36. self.assertModule(module)
  37. m = SimpleModule('db.tables', flags='p')
  38. self.assertModule(m)
  39. self.assertRegexpMatches(decode(m.outputs.stdout), self.tableName1)
  40. def test_import_dbf_file(self):
  41. """import dbf table"""
  42. module = SimpleModule('db.in.ogr', input=self.dbfFile,
  43. output=self.tableName2)
  44. self.assertModule(module)
  45. m = SimpleModule('db.tables', flags='p')
  46. self.assertModule(m)
  47. self.assertRegexpMatches(decode(m.outputs.stdout), self.tableName2)
  48. if __name__ == '__main__':
  49. test()