Blame tests/test_alembic.py

Pierre-Yves Chibon 08b640
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 08b640
Pierre-Yves Chibon 08b640
"""
Pierre-Yves Chibon 08b640
 (c) 2017 - Copyright Red Hat Inc
Pierre-Yves Chibon 08b640
Pierre-Yves Chibon 08b640
 Authors:
Pierre-Yves Chibon 08b640
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 08b640
Pierre-Yves Chibon 08b640
"""
Pierre-Yves Chibon 08b640
Pierre-Yves Chibon 67d1cc
from __future__ import unicode_literals, absolute_import
Aurélien Bompard dcf6f6
Pierre-Yves Chibon 08b640
import os
Pierre-Yves Chibon 08b640
import subprocess
Pierre-Yves Chibon 08b640
import unittest
Pierre-Yves Chibon 08b640
Pierre-Yves Chibon 73d120
import six
Pierre-Yves Chibon 08b640
Pierre-Yves Chibon 73d120
Pierre-Yves Chibon 73d120
REPO_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
Pierre-Yves Chibon 08b640
Pierre-Yves Chibon 08b640
Pierre-Yves Chibon 08b640
class TestAlembic(unittest.TestCase):
Pierre-Yves Chibon 08b640
    """This test class contains tests pertaining to alembic."""
Pierre-Yves Chibon 08b640
Pierre-Yves Chibon 08b640
    def test_alembic_history(self):
Pierre-Yves Chibon 08b640
        """Enforce a linear alembic history.
Pierre-Yves Chibon 08b640
Pierre-Yves Chibon 08b640
        This test runs the `alembic history | grep ' (head), '` command,
Pierre-Yves Chibon 08b640
        and ensure it returns only one line.
Pierre-Yves Chibon 08b640
        """
Pierre-Yves Chibon 08b640
Pierre-Yves Chibon 08b640
        proc1 = subprocess.Popen(
Pierre-Yves Chibon 73d120
            ["alembic", "history"], cwd=REPO_PATH, stdout=subprocess.PIPE
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 08b640
        proc2 = subprocess.Popen(
Pierre-Yves Chibon 73d120
            ["grep", " (head), "], stdin=proc1.stdout, stdout=subprocess.PIPE
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 08b640
        stdout = proc2.communicate()[0]
Pierre-Yves Chibon 73d120
        stdout = stdout.strip().decode("utf-8").split("\n")
Pierre-Yves Chibon 08b640
Pierre-Yves Chibon 08b640
        self.assertEqual(len(stdout), 1)
Pierre-Yves Chibon 08b640
Pierre-Yves Chibon 08b640
Pierre-Yves Chibon 73d120
if __name__ == "__main__":
Pierre-Yves Chibon 08b640
    unittest.main(verbosity=2)