summaryrefslogtreecommitdiff
path: root/tests/testparseversions.py
blob: 1b633ba12b09f194fc3bf37af01fefeeae2e80ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python

import unittest
import subprocess

class TestParseVersions(unittest.TestCase):
    @staticmethod
    def get_output(args):
        subp = subprocess.Popen(args, stdout=subprocess.PIPE)
        output = subp.communicate()[0]
        if subp.returncode != 0:
            raise RuntimeError(subp.returncode)
        return output

    def pv_output(self, control):
        return TestParseVersions.get_output(["parseversions", "--pycentral", control])

    def test_regular(self):
        self.assertEqual(self.pv_output('testparseversions.regular.control'),
                         TestParseVersions.get_output(['pyversions', '--supported', '-v']))

    def test_nonexported(self):
        self.assertEqual(self.pv_output('testparseversions.nonexported.control'),
                         TestParseVersions.get_output(['pyversions', '--supported', '-v']))

    def test_leading_newline(self):
        self.assertEqual(self.pv_output('testparseversions.leading-newline.control'),
                         TestParseVersions.get_output(['pyversions', '--supported', '-v']))

    def test_missing(self):
        self.assertRaises(RuntimeError, self.pv_output, 'testparseversions.missing.control')

    def test_second_paragraph(self):
        self.assertRaises(RuntimeError, self.pv_output, 'testparseversions.second-paragraph.control')

    def test_spaces(self):
        self.assertRaises(RuntimeError, self.pv_output, 'testparseversions.spaces.control')

if __name__ == '__main__':
    unittest.main()