def test_valid_session_timeout(default_command): """Make session timeout valid and verify INTERRUPTED.""" default_command += "--session-timeout=0.00001" try: run_python_with_command(default_command) assert 0, "Should not hit here. Should timeout" except SystemExit as err: assert err.code == pytest.ExitCode.INTERRUPTED
def test_config_value(default_command, set_value, config, expected_value): """Override specific value with key="value", xml files or param=value with. --config The 3 kinds of values (key, xml file and param) can be at the beginning, in the middle or at the end of --config, separated with comma Or --config can be used several times. """ full_path_value_list = [ "--path %s --expected_value %s" % (value[0], value[1]) for value in expected_value ] check_values = " ".join(full_path_value_list) # Check with value at the beginning of --config cmd = ( "%s " "--config %s,%s" " %s" % (default_command, set_value, config, check_values) ) print("Start command:\n%s" % cmd) assert run_python_with_command(cmd) # Check with value at the end of --config cmd = ( "%s " "--config %s,%s" " %s" % (default_command, config, set_value, check_values) ) print("Start command:\n%s" % cmd) assert run_python_with_command(cmd) # Check with multiple --config before value split_config = " --config ".join(config.split(",")) cmd = ( "%s " "--config %s --config %s" " %s" % (default_command, split_config, set_value, check_values) ) print("Start command:\n%s" % cmd) assert run_python_with_command(cmd) # Check with multiple --config after value cmd = ( "%s " "scenario/command/test_config_stub.py::test_config_value " "--config %s --config %s" " %s" % (default_command, set_value, split_config, check_values) ) print("Start command:\n%s" % cmd) assert run_python_with_command(cmd) # Check with value not at the start or at the beginning of the --config cfg = config.split(",") cfg.insert(1, set_value) split_config = " --config ".join(cfg) cmd = "%s " "--config %s %s" % (default_command, split_config, check_values) print("Start command:\n%s" % cmd) assert run_python_with_command(cmd)
def test_default_value(default_command): """Ensure the default value used in the tests.""" # list with the following: [parameter, value] checklist = [ ["module/slink1/name", "/dev/ttyUSB0"], ["module/ssh/ip_address", "192.168.2.2"], ["module/ssh/network_if", "ecm0"], ] for path, expected_value in checklist: # Check that default value is 0 cmd = "{} --path {} --expected_value {}".format( default_command, path, expected_value ) print("Start command:\n%s" % cmd) run_python_with_command(cmd)
def test_config_same_test_with_2_cfg(letp_cmd, json_file): """Test two xml file with json file.""" expected_tests = 2 cmd = "{} run {}".format(letp_cmd, json_file) print("Start command:\n%s" % cmd) output = run_python_with_command(cmd) util.check_letp_nb_tests(output, expected_tests)
def test_config_two_xml_with_json_file(letp_cmd): """Execute one json file with two different .xml configs.""" expected_tests = 2 json_file = "scenario/command/runtest/targets_test.json" cmd = "%s run %s " % (letp_cmd, json_file) output = run_python_with_command(cmd) util.check_letp_nb_tests(output, expected_tests)
def test_debug_html(letp_cmd): """Run test and generate html based report.""" cmd = "{} run ../letp/scenario/command/test_logging_stub.py --html".format( letp_cmd) output = run_python_with_command(cmd) res = get_log_file_name(output, file_type="html") assert res, "html file is not found %s" % res
def test_slink_default_val(letp_cmd): """Test default slink config val.""" cmd = ( "%s run " "scenario/command/test_config_stub.py::test_slink_default_val " "--config module/slink3/name=/dev/ttyUSB6" % (letp_cmd) ) assert run_python_with_command(cmd)
def test_debug_log(letp_cmd): """Run test and generate a new letp based report.""" temp_log = "log/letp.log" cmd = ("{} run --log-file {} ".format(letp_cmd, temp_log) + "../letp/scenario/command/test_logging_stub.py " "--config config/module/wp85.xml " "--capture=sys") assert run_python_with_command(cmd) assert os.path.isfile(temp_log), "{} file does not exists".format(temp_log)
def _test_letp_command(letp_cmd, letp_option, expected_test_nb, test_names=None): """Test letp command with specific option.""" cmd = "{} run {}".format(letp_cmd, letp_option) print("Start command:\n%s" % cmd) output = run_python_with_command(cmd) print(output) util.check_letp_nb_tests(output, expected_test_nb, test_names)
def test_config_xml_with_json_file(letp_cmd, json_file, expected_value): """Test configs in "config" or "main_config" section of the json.""" full_path_value_list = [ "--path %s --expected_value %s" % (value[0], value[1]) for value in expected_value ] check_values = " ".join(full_path_value_list) cmd = "%s run %s %s" % (letp_cmd, json_file, check_values) print("Start command:\n%s" % cmd) assert run_python_with_command(cmd)
def test_custom_config_attri_only(letp_cmd): """Test custom config arguments attribute only.""" cmd = ( "%s run " "scenario/command/test_config_stub.py::test_custom_config_attri_only " "--config module/slink3(used)=1 " "--config capability/avc(used)=1 " "--config custom/new/tag(attri)=1 " % (letp_cmd) ) assert run_python_with_command(cmd)
def _run_test_define_target_with_only_at(letp_cmd, module_name): cmd = ("{} run --dbg-lvl 0 ".format(letp_cmd) + "scenario/command/test_target_fixtures_stub.py::" "test_define_target_with_only_at " "--config module/slink2(used)=1 " "--config host/ip_address=10.1.4.59 " "--config module/ssh(used)=0 " "--config module/name={} ".format(module_name)) output = run_python_with_command(cmd) swilog.debug(output) check_letp_nb_tests(output, number_of_passed=1)
def test_custom_config_tag_only(letp_cmd): """Test custom config arguments tag only.""" cmd = ( "%s run " "scenario/command/test_config_stub.py::test_custom_config_tag_only " "--config module/slink1/name/new_tag=new_val " "--config module/slink3/name=/dev/ttyUSB6 " "--config custom/new/tag=foo " "--config module/slink3/desc=mcu " % (letp_cmd) ) assert run_python_with_command(cmd)
def test_config_with_json_env_vari(letp_cmd): """Test json file having environment variables.""" json_file = "scenario/command/runtest/env_variable.json" cmd = "%s run %s -s" % (letp_cmd, json_file) print("Start command:\n%s" % cmd) output = run_python_with_command(cmd) log_filename = util.get_log_file_name(output) with open(log_filename, "r") as f: content = f.read() assert ( "env variable was found" in content ), "The target function was not executed"
def test_config_ssh_key_value(default_command): """Override specific value key="value".""" path = "module/ssh(used)" # Override key with --config expected_value = "1" cmd = ( "%s " "--config %s=%s" " --path %s --expected_value %s" % (default_command, path, expected_value, path, expected_value) ) print("Start command:\n%s" % cmd) assert run_python_with_command(cmd)
def test_custom_config_tag_with_attri(letp_cmd): """Test custom config arguments tag with attribute.""" cmd = ( "%s run " "scenario/command/test_config_stub.py::test_custom_config_tag_with_attri " "--config module/slink1/name/new_tag=new_val " "--config module/slink3(used)=1 " "--config module/slink3/name=/dev/ttyUSB6 " "--config module/slink1/name/new_tag(new_attri)=new_attri_val " "--config module/slink3/desc=mcu " "--config custom/new/tag=foo" % (letp_cmd) ) assert run_python_with_command(cmd)
def test_config_with_json_file_included_by_another_json_file( letp_cmd, path, expected_value ): """Test xml file with inclusion of json into another json.""" json_file = "scenario/command/runtest/target_json.json" cmd = "%s run %s --path %s --expected_value %s" % ( letp_cmd, json_file, path, expected_value, ) print("Start command:\n%s" % cmd) assert run_python_with_command(cmd)
def test_config_with_xml_associated_in_test(letp_cmd): """Test xml file associated in the test.""" path = "module/slink1/name" expected_value = "/dev/ttyUSB40" path2 = "module/name" expected_value2 = "wp750x" cmd = ( "%s run scenario/command/test_config_stub.py::test_config_value_xml" " --path %s --expected_value %s --path %s --expected_value %s" % (letp_cmd, path, expected_value, path2, expected_value2) ) print("Start command:\n%s" % cmd) assert run_python_with_command(cmd)
def test_module_init(letp_cmd, test_case): with patch("pytest_letp.lib.com.target_serial_qct", autospec=True), patch("pytest_letp.lib.com.ComPortDevice", autospec=True): cmd = ("{} run --dbg-lvl 0 " "scenario/command/test_target_fixtures_stub.py::" "{} ".format(letp_cmd, test_case) + "--config module/slink1(used)=1") print("Start command:\n%s" % cmd) output = run_python_with_command(cmd) print("*After pexpect ****") log_file_name = get_log_file_name(output) print("Found log file: %s ", log_file_name)
def test_letp_new_log_folder(letp_cmd): """Test new log folder can be created correctly.""" new_folder_name = "log/new_folder/new_folder" cmd = ("{} run --dbg-lvl 0 ".format(letp_cmd) + "--log-file {new_folder}/test_json_report.log " "scenario/command/test.py " "--capture=sys " "--json-report " "--json-report-file={new_folder}/json_report.json " "--junitxml {new_folder}/test_results_letp.qa.xml " "--html " "--html-file {new_folder}/test_report.html ".format( new_folder=new_folder_name)) assert run_python_with_command(cmd + " --ci")
def test_config_xml_associated_in_test_module_scope(letp_cmd): """Test xml file associated with entire file.""" path = "module/name" expected_value = "wp750x" path2 = "foo/bar" expected_value2 = "test" cmd = ( "%s run" " scenario/command/test_config_associated.py::test_config_xml_module_scope" " --path %s --expected_value %s --path %s --expected_value %s " % (letp_cmd, path, expected_value, path2, expected_value2) ) print("Start command:\n%s" % cmd) assert run_python_with_command(cmd)
def test_debug_changefilename_html(letp_cmd): """Run test and generate a new html based report.""" expect_html_file = "log/my_html_report.html" cmd = "{} run ../letp/scenario/command/test_logging_stub.py ".format( letp_cmd) + "--html --html-file {} --capture=sys".format( expect_html_file) print("Start command:\n%s" % cmd) output = run_python_with_command(cmd) res = get_html_change_file_name(output) assert res, "new html file is not found %s" % res assert os.path.isfile(expect_html_file), "{} file does not exists".format( expect_html_file)
def test_config_module(default_command, module_name): """Change the value of a parameter.""" path = "module/name" expected_value = module_name cmd = ( "%s --config %s=%s" " --path %s --expected_value %s --path %s --expected_value %s" % ( default_command, path, expected_value, path, expected_value, "module/generic_name", expected_value, ) ) print("Start command:\n%s" % cmd) assert run_python_with_command(cmd)
def test_debug_level_function(letp_cmd, debug_level, expected_msg_sequences, not_expected): """Test debug level. No capture is done. The log file will include the log printings. """ cmd = ("{} run --dbg-lvl {} " "scenario/command/test_logging_stub.py::test_debug_level -s".format( letp_cmd, debug_level)) print("Start command:\n%s" % cmd) output = run_python_with_command(cmd) print("*After pexpect ****") log_file_name = get_log_file_name(output) print("Found log file: %s ", log_file_name) with open(log_file_name, "r") as myfile: content = myfile.read() print("Validating log file {}".format(log_file_name)) assert validate_expected_message_in_str(expected_msg_sequences, content) assert validate_no_messages_in_str(not_expected, content)
def test_log_capture_function(letp_cmd): """Test logging capture=sys works. log file has test running summary only while detailed logs are stored in junit.xml. """ junit_xml_file = "log/test_log_capture.qa.xml" cmd = ("{} run --dbg-lvl 0 " "scenario/command/test_logging_stub.py::test_log_capture " "--capture=sys --junitxml {} ".format(letp_cmd, junit_xml_file)) expected_msg_sequences = [ "test capture starts", "critical level message", "test capture ends", ] print("Start command:\n%s" % cmd) output = run_python_with_command(cmd) assert validate_no_messages_in_str(expected_msg_sequences, output) print(f"Validate messages in {junit_xml_file}") with open(junit_xml_file, "r") as junit_file: print("Validating junit file {}".format(junit_xml_file)) content = junit_file.read() assert validate_expected_message_in_str(expected_msg_sequences, content)
def test_letp_test_folder_arg(letp_cmd): """Test letp with a test folder as the argument.""" cmd = ("{} run --dbg-lvl 0 ".format(letp_cmd) + "--log-file log/test_letp_test_folder_arg.log " ". ") assert run_python_with_command(cmd + " --ci")