test_db_dropcolumn.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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, flags="f")
  22. def test_drop_column_check(self):
  23. """Drop column check, the column should still be in the table"""
  24. module = SimpleModule("db.dropcolumn", table=self.mapName, column=self.colName)
  25. self.assertModule(module)
  26. m = SimpleModule("db.columns", table=self.mapName)
  27. self.assertModule(m)
  28. self.assertRegexpMatches(decode(m.outputs.stdout), self.colName)
  29. def test_drop_column_with_force(self):
  30. """Drop column with force, the column should not be in the table"""
  31. module = SimpleModule(
  32. "db.dropcolumn", table=self.mapName, column=self.colName, flags="f"
  33. )
  34. self.assertModule(module)
  35. m = SimpleModule("db.columns", table=self.mapName)
  36. self.assertModule(m)
  37. self.assertNotRegexpMatches(decode(m.outputs.stdout), self.colName)
  38. if __name__ == "__main__":
  39. test()