|
Pierre-Yves Chibon |
393f31 |
#!/usr/bin/env python
|
|
Pierre-Yves Chibon |
393f31 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
393f31 |
|
|
Pierre-Yves Chibon |
393f31 |
"""
|
|
Pierre-Yves Chibon |
393f31 |
(c) 2017 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
393f31 |
|
|
Pierre-Yves Chibon |
393f31 |
Authors:
|
|
Pierre-Yves Chibon |
393f31 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
393f31 |
|
|
Pierre-Yves Chibon |
393f31 |
Tests for flake8 compliance of the code
|
|
Pierre-Yves Chibon |
393f31 |
|
|
Pierre-Yves Chibon |
393f31 |
"""
|
|
Pierre-Yves Chibon |
393f31 |
|
|
Aurélien Bompard |
dcf6f6 |
from __future__ import unicode_literals
|
|
Aurélien Bompard |
dcf6f6 |
|
|
Pierre-Yves Chibon |
bd1fbf |
import os
|
|
Pierre-Yves Chibon |
bd1fbf |
import subprocess
|
|
Shengjing Zhu |
77a68b |
import sys
|
|
Pierre-Yves Chibon |
bd1fbf |
import unittest
|
|
Pierre-Yves Chibon |
bd1fbf |
|
|
Pierre-Yves Chibon |
d5959a |
import six
|
|
Pierre-Yves Chibon |
bd1fbf |
|
|
Pierre-Yves Chibon |
bd1fbf |
REPO_PATH = os.path.abspath(
|
|
Pierre-Yves Chibon |
bd1fbf |
os.path.join(os.path.dirname(__file__), '..', 'pagure'))
|
|
Pierre-Yves Chibon |
bd1fbf |
|
|
Pierre-Yves Chibon |
bd1fbf |
|
|
Pierre-Yves Chibon |
bd1fbf |
class TestStyle(unittest.TestCase):
|
|
Pierre-Yves Chibon |
bd1fbf |
"""This test class contains tests pertaining to code style."""
|
|
Pierre-Yves Chibon |
bd1fbf |
def test_code_with_flake8(self):
|
|
Pierre-Yves Chibon |
bd1fbf |
"""Enforce PEP-8 compliance on the codebase.
|
|
Pierre-Yves Chibon |
bd1fbf |
|
|
Pierre-Yves Chibon |
bd1fbf |
This test runs flake8 on the code, and will fail if it returns a non-zero exit code.
|
|
Pierre-Yves Chibon |
bd1fbf |
"""
|
|
Pierre-Yves Chibon |
bd1fbf |
# We ignore E712, which disallows non-identity comparisons with True and False
|
|
Pierre-Yves Chibon |
d5959a |
# We ignore W503, which disallows line break before binary operator
|
|
Pierre-Yves Chibon |
d28de1 |
flake8_command = [
|
|
Pierre-Yves Chibon |
d28de1 |
sys.executable, '-m', 'flake8',
|
|
Pierre-Yves Chibon |
d28de1 |
'--ignore=E712,W503,E203', REPO_PATH]
|
|
Pierre-Yves Chibon |
b18561 |
proc = subprocess.Popen(flake8_command, stdout=subprocess.PIPE)
|
|
Pierre-Yves Chibon |
b18561 |
print(proc.communicate())
|
|
Pierre-Yves Chibon |
bd1fbf |
|
|
Pierre-Yves Chibon |
b18561 |
self.assertEqual(proc.returncode, 0)
|
|
Pierre-Yves Chibon |
bd1fbf |
|
|
Pierre-Yves Chibon |
d5959a |
@unittest.skipIf(
|
|
Pierre-Yves Chibon |
d5959a |
not (six.PY3 and sys.version_info.minor >=6),
|
|
Pierre-Yves Chibon |
d5959a |
"Black is only available in python 3.6+")
|
|
Pierre-Yves Chibon |
d5959a |
def test_code_with_black(self):
|
|
Pierre-Yves Chibon |
d5959a |
"""Enforce black compliance on the codebase.
|
|
Pierre-Yves Chibon |
d5959a |
|
|
Pierre-Yves Chibon |
d5959a |
This test runs black on the code, and will fail if it returns a non-zero exit code.
|
|
Pierre-Yves Chibon |
d5959a |
"""
|
|
Pierre-Yves Chibon |
d5959a |
black_command = [sys.executable, '-m', 'black', '-l', '79', '--check', REPO_PATH]
|
|
Pierre-Yves Chibon |
d5959a |
proc = subprocess.Popen(
|
|
Pierre-Yves Chibon |
d5959a |
black_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
Pierre-Yves Chibon |
d5959a |
stdout, stderr = proc.communicate()
|
|
Pierre-Yves Chibon |
d5959a |
print('stdout: ')
|
|
Pierre-Yves Chibon |
d5959a |
print(stdout.decode('utf-8'))
|
|
Pierre-Yves Chibon |
d5959a |
print('stderr: ')
|
|
Pierre-Yves Chibon |
d5959a |
print(stderr.decode('utf-8'))
|
|
Pierre-Yves Chibon |
d5959a |
|
|
Pierre-Yves Chibon |
d5959a |
self.assertEqual(proc.returncode, 0)
|
|
Pierre-Yves Chibon |
d5959a |
|
|
Pierre-Yves Chibon |
bd1fbf |
|
|
Pierre-Yves Chibon |
bd1fbf |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
bd1fbf |
unittest.main(verbosity=2)
|