test_db_droptable.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """
  2. Created on Sun Jun 07 19:38:12 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. class TestDbDropTable(TestCase):
  11. """Test db.droptable script"""
  12. mapName = 'myroads'
  13. @classmethod
  14. def setUpClass(cls):
  15. """Copy vector."""
  16. run_command('g.copy', vector='roadsmajor,myroads')
  17. @classmethod
  18. def tearDownClass(cls):
  19. """Remove copied vector"""
  20. run_command('g.remove', type='vector', name=cls.mapName,
  21. flags='f')
  22. def test_drop_table_check(self):
  23. """Drop table check, the column should still be in the table"""
  24. module = SimpleModule('db.droptable', table=self.mapName)
  25. self.assertModule(module)
  26. m = SimpleModule('db.tables', flags='p')
  27. self.assertModule(m)
  28. self.assertRegexpMatches(decode(m.outputs.stdout), self.mapName)
  29. def test_drop_table_with_force(self):
  30. """Drop table with force, the column should not be in the table"""
  31. module = SimpleModule('db.droptable', table=self.mapName, flags='f')
  32. self.assertModule(module)
  33. m = SimpleModule('db.tables', flags='p')
  34. self.assertModule(m)
  35. self.assertNotRegexpMatches(decode(m.outputs.stdout), self.mapName)
  36. if __name__ == '__main__':
  37. test()