test_alembic.py 1.0 KB

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