Commit 08b640c Add a unit-test test enforcing the linearity of the alembic history

1 file Authored and Committed by pingou 3 months ago
Add a unit-test test enforcing the linearity of the alembic history

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>

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