test that we conform to pep8 style pycodestyle styleguidequietfalse ignore e501 w605 if exists transitions when run from root directory e g tox style inputdir transitions style inputdir tests else when run from test directory e g pycharm style inputdir transitions style inputdir result style checkfiles self assertequalresult totalerrors 0 found code style errors and warnings unittest skipifmypy is none mypy not found def testmypypackageself call mypy configfile mypy ini transitions when run from root directory e g tox else when run from test directory e g pycharm projectroot if exists transitions else subprocess checkcallcall cwdprojectroot unittest skipifmypy is none mypy not found def testmypytestsself call mypy tests disableerrorcode attrdefined disableerrorcode nountypeddef when run from root directory e g tox else when run from test directory e g pycharm projectroot if exists transitions else subprocess checkcallcall cwdprojectroot type ignore test that we conform to pep 8 when run from root directory e g tox when run from test directory e g pycharm when run from root directory e g tox else when run from test directory e g pycharm when run from root directory e g tox else when run from test directory e g pycharm
import unittest
import subprocess
from os.path import exists

import pycodestyle

try:
    import mypy
except ImportError:
    mypy = None  


class TestCodeFormat(unittest.TestCase):
    def test_conformance(self):
        
        style = pycodestyle.StyleGuide(quiet=False, ignore=['E501', 'W605'])
        if exists('transitions'):  
            style.input_dir('transitions')
            style.input_dir('tests')
        else:  
            style.input_dir('../transitions')
            style.input_dir('.')
        result = style.check_files()
        self.assertEqual(result.total_errors, 0,
                         "Found code style errors (and warnings).")

    @unittest.skipIf(mypy is None, "mypy not found")
    def test_mypy_package(self):
        call = ['mypy', '--config-file', 'mypy.ini', 'transitions']

        
        project_root = '.' if exists('transitions') else '..'
        subprocess.check_call(call, cwd=project_root)

    @unittest.skipIf(mypy is None, "mypy not found")
    def test_mypy_tests(self):
        call = ['mypy', 'tests',
                '--disable-error-code', 'attr-defined',
                '--disable-error-code', 'no-untyped-def']
        
        project_root = '.' if exists('transitions') else '..'
        subprocess.check_call(call, cwd=project_root)