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 08b640
import os
Pierre-Yves Chibon 08b640
import subprocess
Pierre-Yves Chibon 08b640
import unittest
Pierre-Yves Chibon 08b640
Pierre-Yves Chibon 08b640
Pierre-Yves Chibon 08b640
REPO_PATH = os.path.abspath(
Pierre-Yves Chibon 08b640
    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 08b640
            ['alembic', 'history'],
Pierre-Yves Chibon 08b640
            cwd=REPO_PATH, stdout=subprocess.PIPE)
Pierre-Yves Chibon 08b640
        proc2 = subprocess.Popen(
Pierre-Yves Chibon 08b640
            ['grep', ' (head), '],
Pierre-Yves Chibon 08b640
            stdin=proc1.stdout, stdout=subprocess.PIPE)
Pierre-Yves Chibon 08b640
        stdout = proc2.communicate()[0]
Pierre-Yves Chibon 08b640
        stdout = stdout.strip().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 08b640
if __name__ == '__main__':
Pierre-Yves Chibon 08b640
    unittest.main(verbosity=2)