test_db_dropcolumn.py 1.6 KB

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