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