How to use assert_exit_code method in lisa

Best Python code snippet using lisa_python

test_native.py

Source:test_native.py Github

copy

Full Screen

...5OPENQUALITYCHECKER_BASE_URL = 'http://localhost:3031/backend'6def test_no_parameters(capsys):7 result, wrapped_error = run_the_pipe(capsys)8 print(f'\n{result.out}')9 assert_exit_code(wrapped_error, 1)10 assert_output(result, 'BITBUCKET_BRANCH')11 assert_output(result, 'BITBUCKET_COMMIT')12 assert_output(result, 'BITBUCKET_REPOSITORY')13 assert_output(result, 'BITBUCKET_USERNAME')14 assert_output(result, 'OPENQUALITYCHECKER_ACCESS_TOKEN')15 assert_output(result, 'OPENQUALITYCHECKER_PROJECT_NAME')16def test_OpenQualityChecker_not_available(capsys):17 os.environ["OPENQUALITYCHECKER_BASE_URL"] = f"http://dummy_OpenQualityChecker_hostname"18 os.environ["BITBUCKET_USERNAME"] = f"dummy_user"19 os.environ["BITBUCKET_PASSWORD"] = f"dummy_password"20 os.environ["BITBUCKET_REPOSITORY"] = f"dummy_repository"21 os.environ["BITBUCKET_BRANCH"] = f"dummy-branch"22 os.environ["BITBUCKET_COMMIT"] = f"dummy-commit"23 os.environ["OPENQUALITYCHECKER_ACCESS_TOKEN"] = f"dummy_oqcp_token"24 os.environ["OPENQUALITYCHECKER_PROJECT_NAME"] = f"dummy_oqcp_project"25 os.environ["DEBUG"] = f"True"26 result, wrapped_error = run_the_pipe(capsys)27 print(f'\n{result.out}')28 assert_exit_code(wrapped_error, 1)29 assert_output(result, 'OpenQualityChecker not available, please try again later')30def test_with_invalid_api_token(capsys):31 os.environ["OPENQUALITYCHECKER_BASE_URL"] = f"{OPENQUALITYCHECKER_BASE_URL}"32 os.environ["BITBUCKET_USERNAME"] = f"dummy_user"33 os.environ["BITBUCKET_PASSWORD"] = f"dummy_password"34 os.environ["BITBUCKET_REPOSITORY"] = f"dummy_repository"35 os.environ["BITBUCKET_BRANCH"] = f"dummy-branch"36 os.environ["BITBUCKET_COMMIT"] = f"dummy-commit"37 os.environ["OPENQUALITYCHECKER_ACCESS_TOKEN"] = f"invalid_oqcp_token"38 os.environ["OPENQUALITYCHECKER_PROJECT_NAME"] = f"dummy_oqcp_project"39 os.environ["DEBUG"] = f"True"40 result, wrapped_error = run_the_pipe(capsys)41 print(f'\n{result.out}')42 assert_exit_code(wrapped_error, 1)43 assert_output(result, "Request not authorized, possible invalid API token")44def test_not_existing_project(capsys):45 os.environ["OPENQUALITYCHECKER_BASE_URL"] = f"{OPENQUALITYCHECKER_BASE_URL}"46 os.environ["BITBUCKET_USERNAME"] = f"dummy_user"47 os.environ["BITBUCKET_PASSWORD"] = f"dummy_password"48 os.environ["BITBUCKET_REPOSITORY"] = f"dummy_repository"49 os.environ["BITBUCKET_BRANCH"] = f"dummy-branch"50 os.environ["BITBUCKET_COMMIT"] = f"dummy-commit"51 os.environ["OPENQUALITYCHECKER_ACCESS_TOKEN"] = f"dummy_oqcp_token"52 os.environ["OPENQUALITYCHECKER_PROJECT_NAME"] = f"dummy_oqcp_project"53 os.environ["DEBUG"] = f"True"54 result, wrapped_error = run_the_pipe(capsys)55 print(f'\n{result.out}')56 assert_exit_code(wrapped_error, 1)57 assert_output(result, "[dummy_oqcp_project] Project id NOT found for project name")58def test_not_existing_branch(capsys):59 os.environ["OPENQUALITYCHECKER_BASE_URL"] = f"{OPENQUALITYCHECKER_BASE_URL}"60 os.environ["BITBUCKET_USERNAME"] = f"dummy_user"61 os.environ["BITBUCKET_PASSWORD"] = f"dummy_password"62 os.environ["BITBUCKET_REPOSITORY"] = f"dummy_repository"63 os.environ["BITBUCKET_BRANCH"] = f"not-existing-branch"64 os.environ["BITBUCKET_COMMIT"] = f"dummy-commit"65 os.environ["OPENQUALITYCHECKER_ACCESS_TOKEN"] = f"dummy_oqcp_token"66 os.environ["OPENQUALITYCHECKER_PROJECT_NAME"] = f"process-metrics"67 os.environ["DEBUG"] = f"True"68 result, wrapped_error = run_the_pipe(capsys)69 print(f'\n{result.out}')70 assert_exit_code(wrapped_error, 1)71 assert_output(result, "Branch not found: 'not-existing-branch'")72def test_not_existing_version(capsys):73 os.environ["OPENQUALITYCHECKER_BASE_URL"] = f"{OPENQUALITYCHECKER_BASE_URL}"74 os.environ["BITBUCKET_USERNAME"] = f"dummy_user"75 os.environ["BITBUCKET_PASSWORD"] = f"dummy_password"76 os.environ["BITBUCKET_REPOSITORY"] = f"dummy_repository"77 os.environ["BITBUCKET_BRANCH"] = f"master"78 os.environ["BITBUCKET_COMMIT"] = f"not-existing-version-commit-hash"79 os.environ["OPENQUALITYCHECKER_ACCESS_TOKEN"] = f"dummy_oqcp_token"80 os.environ["OPENQUALITYCHECKER_PROJECT_NAME"] = f"process-metrics"81 os.environ["DEBUG"] = f"True"82 result, wrapped_error = run_the_pipe(capsys)83 print(f'\n{result.out}')84 assert_exit_code(wrapped_error, 1)85 assert_output(result,86 "Version not found for branch id: '285' and hash: 'not-existing-version-commit-hash'")87def test_not_existing_quality_profile(capsys):88 os.environ["OPENQUALITYCHECKER_BASE_URL"] = f"{OPENQUALITYCHECKER_BASE_URL}"89 os.environ["BITBUCKET_USERNAME"] = f"dummy_user"90 os.environ["BITBUCKET_PASSWORD"] = f"dummy_password"91 os.environ["BITBUCKET_REPOSITORY"] = f"dummy_repository"92 os.environ["BITBUCKET_BRANCH"] = f"master"93 os.environ["BITBUCKET_COMMIT"] = f"not-existing-quality-commit-hash"94 os.environ["OPENQUALITYCHECKER_ACCESS_TOKEN"] = f"dummy_oqcp_token"95 os.environ["OPENQUALITYCHECKER_PROJECT_NAME"] = f"process-metrics"96 os.environ["DEBUG"] = f"True"97 result, wrapped_error = run_the_pipe(capsys)98 print(f'\n{result.out}')99 assert_exit_code(wrapped_error, 1)100 assert_output(result, "No quality profile found for version: '327'")101def test_failed_project(capsys):102 os.environ["OPENQUALITYCHECKER_BASE_URL"] = f"{OPENQUALITYCHECKER_BASE_URL}"103 os.environ["BITBUCKET_USERNAME"] = f"dummy_user"104 os.environ["BITBUCKET_PASSWORD"] = f"dummy_password"105 os.environ["BITBUCKET_REPOSITORY"] = f"dummy_repository"106 os.environ["BITBUCKET_BRANCH"] = f"master"107 os.environ["BITBUCKET_COMMIT"] = f"failed-quality-commit-hash"108 os.environ["OPENQUALITYCHECKER_ACCESS_TOKEN"] = f"oqc_token"109 os.environ["OPENQUALITYCHECKER_PROJECT_NAME"] = f"process-metrics"110 os.environ["DEBUG"] = f"True"111 result, wrapped_error = run_the_pipe(capsys)112 print(f'\n{result.out}')113 assert_exit_code(wrapped_error, 1)114 assert_output(result, "The commit for project 'process-metrics' is FAILED the analysis")115 assert_output(result, 'The Code complexity (2.63) should be LE 10.0')116 assert_output(result, 'The csharpsquid:S3431 should be GT 100.0')117 assert_output(result, 'The AVGNODL should be GT 0.0')118 assert_output(result, 'The Maintainability (2.55) should be GT 5.0')119 assert_output(result, 'Fail')120def test_failed_projects(capsys):121 os.environ["OPENQUALITYCHECKER_BASE_URL"] = f"{OPENQUALITYCHECKER_BASE_URL}"122 os.environ["BITBUCKET_USERNAME"] = f"dummy_user"123 os.environ["BITBUCKET_PASSWORD"] = f"dummy_password"124 os.environ["BITBUCKET_REPOSITORY"] = f"dummy_repository"125 os.environ["BITBUCKET_BRANCH"] = f"master"126 os.environ["BITBUCKET_COMMIT"] = f"failed-quality-commit-hash"127 os.environ["OPENQUALITYCHECKER_ACCESS_TOKEN"] = f"oqc_token"128 os.environ["OPENQUALITYCHECKER_PROJECT_NAME"] = f"process-metrics, Qualityprofiletest"129 os.environ["DEBUG"] = f"True"130 result, wrapped_error = run_the_pipe(capsys)131 print(f'\n{result.out}')132 assert_exit_code(wrapped_error, 1)133 assert_output(result, "The commit for project 'process-metrics' is FAILED the analysis")134 assert_output(result, "The commit for project 'Qualityprofiletest' is FAILED the analysis")135 assert_output(result, 'The Code complexity (2.63) should be LE 10.0')136 assert_output(result, 'The csharpsquid:S3431 should be GT 100.0')137 assert_output(result, 'The AVGNODL should be GT 0.0')138 assert_output(result, 'The Maintainability (2.55) should be GT 5.0')139 assert_output(result, 'The Code complexity (3.76) should be LE 10.0')140 assert_output(result, 'The Maintainability (4.67) should be GT 5.0')141 assert_output(result, 'Fail')142def test_partial_failed_projects(capsys):143 os.environ["OPENQUALITYCHECKER_BASE_URL"] = f"{OPENQUALITYCHECKER_BASE_URL}"144 os.environ["BITBUCKET_USERNAME"] = f"dummy_user"145 os.environ["BITBUCKET_PASSWORD"] = f"dummy_password"146 os.environ["BITBUCKET_REPOSITORY"] = f"dummy_repository"147 os.environ["BITBUCKET_BRANCH"] = f"master"148 os.environ["BITBUCKET_COMMIT"] = f"failed-quality-commit-hash"149 os.environ["OPENQUALITYCHECKER_ACCESS_TOKEN"] = f"oqc_token"150 os.environ[151 "OPENQUALITYCHECKER_PROJECT_NAME"] = f"process-metrics, Qualityprofiletest, analyzer-client"152 os.environ["DEBUG"] = f"True"153 result, wrapped_error = run_the_pipe(capsys)154 print(f'\n{result.out}')155 assert_exit_code(wrapped_error, 1)156 assert_output(result, "The commit for project 'process-metrics' is FAILED the analysis")157 assert_output(result, "The commit for project 'Qualityprofiletest' is FAILED the analysis")158 assert_output(result, "The commit for project 'analyzer-client' is PASSED the analysis")159 assert_output(result, 'The Code complexity (2.63) should be LE 10.0')160 assert_output(result, 'The csharpsquid:S3431 should be GT 100.0')161 assert_output(result, 'The AVGNODL should be GT 0.0')162 assert_output(result, 'The Maintainability (2.55) should be GT 5.0')163 assert_output(result, 'The Code complexity (3.76) should be LE 10.0')164 assert_output(result, 'The Maintainability (4.67) should be GT 5.0')165 assert_output(result, 'Fail')166def test_passed_project(capsys):167 os.environ["OPENQUALITYCHECKER_BASE_URL"] = f"{OPENQUALITYCHECKER_BASE_URL}"168 os.environ["BITBUCKET_USERNAME"] = f"dummy_user"169 os.environ["BITBUCKET_PASSWORD"] = f"dummy_password"170 os.environ["BITBUCKET_REPOSITORY"] = f"dummy_repository"171 os.environ["BITBUCKET_BRANCH"] = f"master"172 os.environ["BITBUCKET_COMMIT"] = f"successful-quality-commit-hash"173 os.environ["OPENQUALITYCHECKER_ACCESS_TOKEN"] = f"oqc_token"174 os.environ["OPENQUALITYCHECKER_PROJECT_NAME"] = f"process-metrics"175 os.environ["DEBUG"] = f"True"176 result, wrapped_error = run_the_pipe(capsys)177 print(f'\n{result.out}')178 assert_exit_code(wrapped_error, 0)179 assert_output(result, "The commit for project 'process-metrics' is PASSED the analysis")180 assert_output(result, 'Success')181def test_passed_projects(capsys):182 os.environ["OPENQUALITYCHECKER_BASE_URL"] = f"{OPENQUALITYCHECKER_BASE_URL}"183 os.environ["BITBUCKET_USERNAME"] = f"dummy_user"184 os.environ["BITBUCKET_PASSWORD"] = f"dummy_password"185 os.environ["BITBUCKET_REPOSITORY"] = f"dummy_repository"186 os.environ["BITBUCKET_BRANCH"] = f"master"187 os.environ["BITBUCKET_COMMIT"] = f"successful-quality-commit-hash"188 os.environ["OPENQUALITYCHECKER_ACCESS_TOKEN"] = f"oqc_token"189 os.environ["OPENQUALITYCHECKER_PROJECT_NAME"] = f"process-metrics, analyzer-client"190 os.environ["DEBUG"] = f"True"191 result, wrapped_error = run_the_pipe(capsys)192 print(f'\n{result.out}')193 assert_exit_code(wrapped_error, 0)194 assert_output(result, "The commit for project 'process-metrics' is PASSED the analysis")195 assert_output(result, "The commit for project 'analyzer-client' is PASSED the analysis")196 assert_output(result, 'Success')197def run_the_pipe(capsys):198 with pytest.raises(SystemExit) as pytest_wrapped_e:199 pipe = OpenQualityCheckerPipe(schema=parameter_schema)200 pipe.run()201 return capsys.readouterr(), pytest_wrapped_e202def assert_exit_code(pytest_wrapped_e, expected):203 assert pytest_wrapped_e.type == SystemExit204 assert pytest_wrapped_e.value.code == expected205def assert_output(result, expected):...

Full Screen

Full Screen

test_equal.py

Source:test_equal.py Github

copy

Full Screen

...5from nose import with_setup6from contextlib import contextmanager7from tests.utils import *8@contextmanager9def assert_exit_code(status_code):10 """11 Assert that the with block yields a subprocess.CalledProcessError12 with a certain return code. If nothing is thrown, status_code13 is required to be 0 to survive the test.14 """15 try:16 yield17 except subprocess.CalledProcessError as exc:18 assert exc.returncode == status_code19 else:20 # No exception? status_code should be fine.21 assert status_code == 022@with_setup(usual_setup_func, usual_teardown_func)23def test_equal_files():24 path_a = create_file('1234', 'a')25 path_b = create_file('1234', 'b')26 with assert_exit_code(0):27 head, *data, footer = run_rmlint(28 '--equal', path_a, path_b,29 use_default_dir=False30 )31 with assert_exit_code(0):32 head, *data, footer = run_rmlint(33 '-p', '--equal', path_a, path_b,34 use_default_dir=False35 )36 # If --equal finds that both files are not equal,37 # it would return 1 as exit code which would cause38 # a CalledProcessError in run_rmlint39 assert data[0]['path'].endswith('a')40 assert data[1]['path'].endswith('b')41 path_c = create_file('1234', 'c')42 with assert_exit_code(0):43 head, *data, footer = run_rmlint(44 '--equal', path_a, path_b, path_c,45 use_default_dir=False46 )47 path_d = create_file('diff', 'd')48 with assert_exit_code(1):49 head, *data, footer = run_rmlint(50 '--equal', path_a, path_b, path_d, path_c,51 use_default_dir=False52 )53@with_setup(usual_setup_func, usual_teardown_func)54def test_no_arguments():55 with assert_exit_code(1):56 head, *data, footer = run_rmlint(57 '--equal',58 use_default_dir=False59 )60@with_setup(usual_setup_func, usual_teardown_func)61def test_one_arguments():62 path = create_file('1234', 'a')63 with assert_exit_code(1):64 head, *data, footer = run_rmlint(65 '--equal', path,66 use_default_dir=False67 )68 with assert_exit_code(1):69 head, *data, footer = run_rmlint(70 '--equal', path, "//",71 use_default_dir=False72 )73 with assert_exit_code(1):74 head, *data, footer = run_rmlint(75 '--equal', "//", path,76 use_default_dir=False77 )78@with_setup(usual_setup_func, usual_teardown_func)79def test_equal_directories():80 path_a = os.path.dirname(create_file('xxx', 'dir_a/x'))81 path_b = os.path.dirname(create_file('xxx', 'dir_b/x'))82 with assert_exit_code(0):83 head, *data, footer = run_rmlint(84 '--equal', path_a, path_b,85 use_default_dir=False86 )87 with assert_exit_code(0):88 head, *data, footer = run_rmlint(89 '-p', '--equal', path_a, path_b,90 use_default_dir=False91 )92@with_setup(usual_setup_func, usual_teardown_func)93def test_dir_and_file():94 path_a = os.path.dirname(create_file('xxx', 'dir_a/x'))95 path_b = create_file('xxx', 'x')96 # This should fail since we should not mix directories with files,97 # even if they have the same content.98 with assert_exit_code(1):99 head, *data, footer = run_rmlint(100 '--equal', path_a, path_b,101 use_default_dir=False,102 )103# Regression test for Issue #233104@with_setup(usual_setup_func, usual_teardown_func)105def test_equal_hidden_dirs():106 path_a = os.path.dirname(create_file('xxx', 'dir_a/x'))107 path_b = os.path.dirname(create_file('xxx', '.dir_b/.x'))108 # This should fail since we should not mix directories with files,109 # even if they have the same content.110 with assert_exit_code(0):111 head, *data, footer = run_rmlint(112 '--equal', path_a, path_b,113 use_default_dir=False,114 )115# Regression test for Issue #234116@with_setup(usual_setup_func, usual_teardown_func)117def test_equal_empty_files_or_other_lint():118 path_a = create_file('', 'x')119 path_b = create_file('', 'y')120 # This should fail since we should not mix directories with files,121 # even if they have the same content.122 with assert_exit_code(0):123 head, *data, footer = run_rmlint(124 '--equal', path_a, path_b,125 use_default_dir=False,...

Full Screen

Full Screen

conftest.py

Source:conftest.py Github

copy

Full Screen

1import os2import shlex3import uuid4import pytest5from click.testing import CliRunner6from awsflock import cli7from awsflock.common import get_dynamo_client8_tablename = f"awsflock-{uuid.uuid4().hex}"9os.environ["AWSFLOCK_TABLE"] = _tablename10if not os.getenv("DYANMO_ENDPOINT_URL"):11 os.environ["DYNAMO_ENDPOINT_URL"] = "http://localhost:8000"12# tests run with the default region and dummy credentials set13os.environ["AWS_DEFAULT_REGION"] = "us-east-1"14os.environ["AWS_ACCESS_KEY_ID"] = "fooAccessKey"15os.environ["AWS_SECRET_ACCESS_KEY"] = "fooSecretKey"16@pytest.fixture(scope="session")17def tablename():18 return _tablename19@pytest.fixture20def run_cmd():21 def func(line, assert_exit_code=0):22 args = shlex.split(line)23 assert args[0] == "awsflock"24 result = CliRunner().invoke(25 cli, args[1:], catch_exceptions=bool(assert_exit_code)26 )27 if result.exit_code != assert_exit_code:28 raise Exception(29 f"Failed to run '{line}'.\n"30 f"result.exit_code={result.exit_code} (expected {assert_exit_code})\n"31 f"Output:\n{result.output}"32 )33 return result34 return func35@pytest.fixture36def with_table(tablename, run_cmd):37 result = run_cmd("awsflock create-table")38 assert result.exit_code == 039 yield40 client = get_dynamo_client()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful