From 08b640c3de3c33c8682d35755d00c448c628809b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 19 2017 08:14:14 +0000 Subject: Add a unit-test test enforcing the linearity of the alembic history Signed-off-by: Pierre-Yves Chibon --- diff --git a/tests/test_alembic.py b/tests/test_alembic.py new file mode 100644 index 0000000..6aec50c --- /dev/null +++ b/tests/test_alembic.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- + +""" + (c) 2017 - Copyright Red Hat Inc + + Authors: + Pierre-Yves Chibon + +""" + +import os +import subprocess +import unittest + + +REPO_PATH = os.path.abspath( + os.path.join(os.path.dirname(__file__), '..')) + + +class TestAlembic(unittest.TestCase): + """This test class contains tests pertaining to alembic.""" + + def test_alembic_history(self): + """Enforce a linear alembic history. + + This test runs the `alembic history | grep ' (head), '` command, + and ensure it returns only one line. + """ + + proc1 = subprocess.Popen( + ['alembic', 'history'], + cwd=REPO_PATH, stdout=subprocess.PIPE) + proc2 = subprocess.Popen( + ['grep', ' (head), '], + stdin=proc1.stdout, stdout=subprocess.PIPE) + stdout = proc2.communicate()[0] + stdout = stdout.strip().split('\n') + + self.assertEqual(len(stdout), 1) + + +if __name__ == '__main__': + unittest.main(verbosity=2)