1
0

test_alembic.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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, absolute_import
  8. import os
  9. import subprocess
  10. import unittest
  11. import six
  12. REPO_PATH = os.path.abspath(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"], cwd=REPO_PATH, stdout=subprocess.PIPE
  22. )
  23. proc2 = subprocess.Popen(
  24. ["grep", " (head), "], stdin=proc1.stdout, stdout=subprocess.PIPE
  25. )
  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)