<commit_before>*** Settings ***
Library           Process
Library           OperatingSystem

*** Keywords ***
Some process
    [Arguments]    ${alias}=${null}
    ${handle}=    Start Python Process    raw_input()    alias=${alias}
    Process should be running
    [Return]    ${handle}

Stop some process
    [Arguments]    ${alias}=${null}
    ${running}=    Is Process Running    ${alias}
    Return From Keyword If    not ${running}
    ${process}=    Get Process Object    ${alias}
    Call Method    ${process}    communicate    stop\n

Result should equal
    [Arguments]    ${result}    ${stdout}=    ${stderr}=    ${rc}=0
    Should Be Equal    ${result.stdout}    ${stdout}
    Should Be Equal    ${result.stderr}    ${stderr}
    Should Be Equal As Integers    ${result.rc}    ${rc}

Result should match
    [Arguments]    ${result}    ${stdout}=    ${stderr}=    ${rc}=0
    Should Match    ${result.stdout}    ${stdout}
    Should Match    ${result.stderr}    ${stderr}
    Should Be Equal As Integers    ${result.rc}    ${rc}

Start Python Process
    [Arguments]    ${command}    ${alias}=${NONE}    ${stdout}=${NONE}    ${stderr}=${NONE}
    ${handle}=    Start Process    python    -c    ${command}
    ...    alias=${alias}    stdout=${stdout}    stderr=${stderr}
    [Return]    ${handle}

Run Python Process
    [Arguments]    ${command}    ${alias}=${NONE}    ${stdout}=${NONE}    ${stderr}=${NONE}
    ${result}=    Run Process    python    -c    ${command}
    ...    alias=${alias}    stdout=${stdout}    stderr=${stderr}
    [Return]    ${result}

Safe Remove File
    [Documentation]    Ignore errors caused by process being locked.
    ...                That happens at least with IronPython.
    [Arguments]    ${path}
    Run Keyword And Ignore Error    Remove File    ${path}

Safe Remove Directory
    [Arguments]    ${path}
    Run Keyword And Ignore Error    Remove Directory    ${path}    recursive=yep

Check Precondition
    [Arguments]    ${precondition}
    ${nok}=    Evaluate    not (${precondition})    modules=sys,os
    Run Keyword If  ${nok}    Set Suite Metadata  info   precondition_fail
    Run Keyword If  ${nok}    Fail    ${precondition} was not true
<commit_msg>[python3] atest: process/resource: Use input() instead of raw_input() in Python 3.<commit_after>*** Settings ***
Library           Process
Library           OperatingSystem

*** Keywords ***
Some process
    [Arguments]    ${alias}=${null}
    ${handle}=    Start Python Process
    ...    __import__('sys').version_info[0] == 3 and input() or raw_input()
    ...    alias=${alias}
    Process should be running
    [Return]    ${handle}

Stop some process
    [Arguments]    ${alias}=${null}
    ${running}=    Is Process Running    ${alias}
    Return From Keyword If    not ${running}
    ${process}=    Get Process Object    ${alias}
    Call Method    ${process}    communicate    stop\n

Result should equal
    [Arguments]    ${result}    ${stdout}=    ${stderr}=    ${rc}=0
    Should Be Equal    ${result.stdout}    ${stdout}
    Should Be Equal    ${result.stderr}    ${stderr}
    Should Be Equal As Integers    ${result.rc}    ${rc}

Result should match
    [Arguments]    ${result}    ${stdout}=    ${stderr}=    ${rc}=0
    Should Match    ${result.stdout}    ${stdout}
    Should Match    ${result.stderr}    ${stderr}
    Should Be Equal As Integers    ${result.rc}    ${rc}

Start Python Process
    [Arguments]    ${command}    ${alias}=${NONE}    ${stdout}=${NONE}    ${stderr}=${NONE}
    ${handle}=    Start Process    python    -c    ${command}
    ...    alias=${alias}    stdout=${stdout}    stderr=${stderr}
    [Return]    ${handle}

Run Python Process
    [Arguments]    ${command}    ${alias}=${NONE}    ${stdout}=${NONE}    ${stderr}=${NONE}
    ${result}=    Run Process    python    -c    ${command}
    ...    alias=${alias}    stdout=${stdout}    stderr=${stderr}
    [Return]    ${result}

Safe Remove File
    [Documentation]    Ignore errors caused by process being locked.
    ...                That happens at least with IronPython.
    [Arguments]    ${path}
    Run Keyword And Ignore Error    Remove File    ${path}

Safe Remove Directory
    [Arguments]    ${path}
    Run Keyword And Ignore Error    Remove Directory    ${path}    recursive=yep

Check Precondition
    [Arguments]    ${precondition}
    ${nok}=    Evaluate    not (${precondition})    modules=sys,os
    Run Keyword If  ${nok}    Set Suite Metadata  info   precondition_fail
    Run Keyword If  ${nok}    Fail    ${precondition} was not true

{'fraction_non_alphanumeric': 0.1381650974381432, 'fraction_numerical': 0.0017516969564265383, 'mean_word_length': 2.4870229007633586, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3951145', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1297, 'n_words': 421}