def test_code_qa(cookies, context): """Generated project should pass flake8 and py.test.""" context['create_virtualenv'] = 'Yes' result = cookies.bake(extra_context=context) base_path = str(result.project) # Run Flake 8 try: sh.flake8('{path}/setup.py {path}/{namespace}'.format( path=base_path, namespace=context['namespace'] ) ) except sh.ErrorReturnCode as e: pytest.fail(e) # Run tests try: ls = sh.ls('{path}/env/bin/'.format(path=base_path)) cmd = 'pytest' if 'pytest' in str(ls.stdout): cmd = './env/bin/pytest' proc = subprocess.Popen( [cmd], shell=sys.platform.startswith('win'), cwd=base_path ) proc.wait() except Exception as e: print(ls.stdout) pytest.fail(e)
def test_flake8_complaince(self): """generated project should pass flake8""" self.generate_project() try: sh.flake8(self.destpath) except sh.ErrorReturnCode as e: raise AssertionError(e)
def test_flake8_compliance(self): """generated project should pass flake8""" self.generate_project() try: sh.flake8(self.destpath) except sh.ErrorReturnCode as e: raise AssertionError(e)
def test_flake8_compliance(cookies): """generated project should pass flake8""" result = cookies.bake() try: sh.flake8(str(result.project)) except sh.ErrorReturnCode as e: pytest.fail(e)
def test_generation(cookies, context): """Generated project should replace all variables.""" result = cookies.bake(extra_context=context) assert result.exception is None assert result.exit_code == 0 assert result.project.basename == context['repo_name'] assert result.project.isdir() paths = build_files_list(str(result.project)) assert paths check_paths(paths) base_path = str(result.project) # Run Flake 8 try: sh.flake8('{path}/setup.py {path}/{namespace}'.format( path=base_path, namespace=context['namespace'])) except sh.ErrorReturnCode as e: pytest.fail(e) # Run tests try: ls = sh.ls('{path}/env/bin/'.format(path=base_path)) cmd = 'pytest' if 'pytest' in str(ls.stdout): cmd = './env/bin/pytest' proc = subprocess.Popen([cmd], shell=sys.platform.startswith('win'), cwd=base_path) proc.wait() except Exception as e: print(ls.stdout) pytest.fail(e)
def test_flake8_complaince(self): """generated project should pass flake8""" self.generate_project() try: #sh.flake8(self.destpath, "--max-line-length=120") sh.flake8(self.destpath) except sh.ErrorReturnCode as e: raise AssertionError(e)
def test_flake8_passes(cookies, context_override): """Generated project should pass flake8.""" result = cookies.bake(extra_context=context_override) try: sh.flake8(_cwd=str(result.project)) except sh.ErrorReturnCode as e: pytest.fail(e.stdout.decode())
def test_flake8_compliance(cookies): """Generated project should pass flake8.""" result = cookies.bake() base_path = str(result.project) paths = ['setup.py', 'src'] for path in paths: try: sh.flake8('{0}/{1}'.format(base_path, path)) except sh.ErrorReturnCode as e: pytest.fail(e)
def test_flake8_passes(cookies, context): """ Generated project should pass flake8. """ result = cookies.bake() try: sh.flake8("--config=.flake8", str(result.project)) except sh.ErrorReturnCode as e: pytest.fail(e)
def check(result): assert result.exit_code == 0 assert result.exception is None assert result.project.isdir() # Check project with flake8 try: sh.flake8(str(result.project)) except sh.ErrorReturnCode as e: pytest.fail(e)
def test_flake8_passes(cookies, context_combination): """ Generated project should pass flake8. This is parametrized for each combination from ``context_combination`` fixture """ result = cookies.bake(extra_context=context_combination) try: sh.flake8(str(result.project)) except sh.ErrorReturnCode as e: pytest.fail(e)
def test_flake8_compliance(cookies): """generated project should pass flake8""" extra_context = dict(QUICK_CONTEXT, ) with bake_in_temp_dir(cookies, extra_context=extra_context) as result: for file_obj in result.project.listdir(): name = os.path.join(file_obj.dirname, file_obj.basename) if not name.endswith('.py'): continue try: sh.flake8(name) except sh.ErrorReturnCode as e: pytest.fail(str(e))
def check_project_result(result): """ Method to common project baking verification """ assert result.exit_code == 0 assert result.exception is None assert result.project.isdir() # Check project with flake8 try: sh.flake8(str(result.project)) except sh.ErrorReturnCode as e: pytest.fail(e)
def test_flake8_compliance(cookies): """generated project should pass flake8""" extra_context = {'create_example_project': 'Y'} with bake_in_temp_dir(cookies, extra_context=extra_context) as result: for file_obj in result.project.listdir(): name = os.path.join( file_obj.dirname, file_obj.basename ) if not name.endswith('.py'): continue try: sh.flake8(name) except sh.ErrorReturnCode as e: pytest.fail(str(e))
def test_linting_passes(cookies, context_combination): """ Generated project should pass flake8 & black. This is parametrized for each combination from ``context_combination`` fixture """ result = cookies.bake(extra_context=context_combination) try: sh.flake8(str(result.project)) except sh.ErrorReturnCode as e: pytest.fail(e) try: sh.black("--check", "--diff", "--exclude", "migrations", f"{result.project}/") except sh.ErrorReturnCode as e: pytest.fail(e)
def _flake8(self, tests, out=LOG.info, err=LOG.error): """ Executes flake8 against specified tests, and returns a :func:`sh` response object. :param tests: A list of testinfra tests. :param out: An optional function to process STDOUT for underlying :func:`sh` call. :param err: An optional function to process STDERR for underlying :func:`sh` call. :return: :func:`sh` response object. """ msg = 'Executing flake8 on *.py files found in {}/.'.format( self._testinfra_dir) util.print_info(msg) return sh.flake8(tests)