test_alembic.py 1000 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2017 - Copyright Red Hat Inc
  4. Authors:
  5. Pierre-Yves Chibon <pingou@pingoured.fr>
  6. """
  7. import os
  8. import subprocess
  9. import unittest
  10. REPO_PATH = os.path.abspath(
  11. os.path.join(os.path.dirname(__file__), '..'))
  12. class TestAlembic(unittest.TestCase):
  13. """This test class contains tests pertaining to alembic."""
  14. def test_alembic_history(self):
  15. """Enforce a linear alembic history.
  16. This test runs the `alembic history | grep ' (head), '` command,
  17. and ensure it returns only one line.
  18. """
  19. proc1 = subprocess.Popen(
  20. ['alembic', 'history'],
  21. cwd=REPO_PATH, stdout=subprocess.PIPE)
  22. proc2 = subprocess.Popen(
  23. ['grep', ' (head), '],
  24. stdin=proc1.stdout, stdout=subprocess.PIPE)
  25. stdout = proc2.communicate()[0]
  26. stdout = stdout.strip().split('\n')
  27. self.assertEqual(len(stdout), 1)
  28. if __name__ == '__main__':
  29. unittest.main(verbosity=2)