~ci-train-bot/ubuntu-system-settings/ubuntu-system-settings-ubuntu-zesty-1721

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
41
42
43
44
45
46
47
#!/usr/bin/python3

# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
# Copyright 2014 Canonical
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.

import subprocess
import sys
import unittest


class StaticCodeTests(unittest.TestCase):

    def _is_tool_installed(tool):
        return subprocess.call(['which', tool],
                               stdout=subprocess.PIPE)

    @unittest.skipIf(
        _is_tool_installed('pyflakes3') != 0, 'python-pyflakes3 not installed'
    )
    def test_pyflakes(self):
        pyflakes = subprocess.Popen(
            ['pyflakes3', '@CMAKE_CURRENT_SOURCE_DIR@', '@CMAKE_CURRENT_SOURCE_DIR@/../push-helper/'],
            stdout=subprocess.PIPE, universal_newlines=True
        )
        (out, err) = pyflakes.communicate()
        self.assertEqual(pyflakes.returncode, 0, out)

    @unittest.skipIf(
        _is_tool_installed('pep8') != 0, 'pep8 not installed'
    )
    def test_pep8(self):
        pep8 = subprocess.Popen(
            ['pep8', '@CMAKE_CURRENT_SOURCE_DIR@', '@CMAKE_CURRENT_SOURCE_DIR@/../push-helper/'],
            stdout=subprocess.PIPE, universal_newlines=True
        )
        (out, err) = pep8.communicate()
        self.assertEqual(pep8.returncode, 0, out)


if __name__ == '__main__':
    unittest.main(
        testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2)
    )