def test_build_pylint_command_3_9_1_docker(): """Build Pylint command""" from demisto_sdk.commands.lint.commands_builder import build_pylint_command NamedFile = namedtuple('File', 'name') files = [NamedFile('file1')] output = build_pylint_command(files, '3.9.1') assert output.endswith(files[0].name) assert 'disable=bad-option-value,unsubscriptable-object' in output
def test_build_pylint_command(files): """Build Pylint command""" from demisto_sdk.commands.lint.commands_builder import build_pylint_command output = build_pylint_command(files) files = [str(file) for file in files] expected = "python -m pylint --ignore=CommonServerPython.py,demistomock.py,CommonServerUserPython.py," \ "conftest.py,venv -E -d duplicate-string-formatting-argument" \ f" --generated-members=requests.packages.urllib3,requests.codes.ok {' '.join(files)}" assert expected == output
def test_build_pylint_command(files): """Build Pylint command""" from demisto_sdk.commands.lint.commands_builder import build_pylint_command output = build_pylint_command(files) files = [str(file) for file in files] expected = "python -m pylint --ignore=CommonServerPython.py,demistomock.py,CommonServerUserPython.py," \ "conftest.py,venv -E --disable=bad-option-value -d duplicate-string-formatting-argument " \ "--msg-template='{abspath}:{line}:{column}: {msg_id} {obj}: {msg}'" \ f" --generated-members=requests.packages.urllib3,requests.codes.ok {' '.join(files)}" assert expected == output
def _docker_run_pylint(self, test_image: str, keep_container: bool) -> Tuple[int, str]: """ Run Pylint in created test image Args: test_image(str): test image id/name keep_container(bool): True if to keep container after execution finished Returns: int: 0 on successful, errors 1, need to retry 2 str: Container log """ log_prompt = f'{self._pack_name} - Pylint - Image {test_image}' logger.info(f"{log_prompt} - Start") container_name = f"{self._pack_name}-pylint" # Check if previous run left container a live if it do, we remove it container_obj: docker.models.containers.Container try: container_obj = self._docker_client.containers.get(container_name) container_obj.remove(force=True) except docker.errors.NotFound: pass # Run container exit_code = SUCCESS output = "" try: container_obj = self._docker_client.containers.run( name=container_name, image=test_image, command=[build_pylint_command(self._facts["lint_files"])], user=f"{os.getuid()}:4000", detach=True, environment=self._facts["env_vars"]) stream_docker_container_output(container_obj.logs(stream=True)) # wait for container to finish container_status = container_obj.wait(condition="exited") # Get container exit code container_exit_code = container_status.get("StatusCode") # Getting container logs container_log = container_obj.logs().decode("utf-8") logger.info(f"{log_prompt} - exit-code: {container_exit_code}") if container_exit_code in [1, 2]: # 1-fatal message issued # 2-Error message issued exit_code = FAIL output = container_log logger.info(f"{log_prompt} - Finished errors found") elif container_exit_code in [4, 8, 16]: # 4-Warning message issued # 8-refactor message issued # 16-convention message issued logger.info( f"{log_prompt} - Successfully finished - warnings found") exit_code = SUCCESS elif container_exit_code == 32: # 32-usage error logger.critical(f"{log_prompt} - Finished - Usage error") exit_code = RERUN else: logger.info(f"{log_prompt} - Successfully finished") # Keeping container if needed or remove it if keep_container: print(f"{log_prompt} - container name {container_name}") else: try: container_obj.remove(force=True) except docker.errors.NotFound as e: logger.critical( f"{log_prompt} - Unable to delete container - {e}") except (docker.errors.ImageNotFound, docker.errors.APIError) as e: logger.critical(f"{log_prompt} - Unable to run pylint - {e}") exit_code = RERUN output = str(e) return exit_code, output