<commit_before>sdkman_dir = '/home/jenkins/.sdkman'


def script_wrap(cmds):
    # run as interactive shell to ensure .bashrc is sourced
    return "/bin/bash -i -c '{0}'".format('; '.join(cmds))


def check_run_for_rc_and_result(cmds, expected, host, check_stderr=False):
    result = host.run(script_wrap(cmds))
    assert result.rc == 0
    if check_stderr:
        assert result.stderr.find(expected) != -1
    else:
        assert result.stdout.find(expected) != -1


def test_config_file(host):
    f = host.file(sdkman_dir + '/etc/config')
    assert f.exists
    assert f.is_file
    assert f.mode in [0o644, 0o654, 0o655]
    assert f.user == 'jenkins'
    assert f.group == 'jenkins'
    assert f.contains('sdkman_auto_answer=true')


def test_gradle_installed(host):
    cmds = ['gradle --version']
    expected = 'Gradle 4.6'
    check_run_for_rc_and_result(cmds, expected, host)

<commit_msg>Fix tests - run as user defined in test.yml<commit_after>sdkman_user = 'jenkins'
sdkman_group = 'jenkins'


def script_wrap(cmds):
    # run as interactive shell under user to ensure .bashrc is sourced
    return "sudo -H -u {0} /bin/bash -i -c '{1}'".format(
        sdkman_user,
        '; '.join(cmds)
    )


def check_run_for_rc_and_result(cmds, expected, host, check_stderr=False):
    result = host.run(script_wrap(cmds))
    assert result.rc == 0
    if check_stderr:
        assert result.stderr.find(expected) != -1
    else:
        assert result.stdout.find(expected) != -1


def test_config_file(host):
    result = host.run(script_wrap(['echo $HOME']))
    config_file_path = "{0}/.sdkman/etc/config".format(result.stdout)

    f = host.file(config_file_path)
    assert f.exists
    assert f.is_file
    assert f.mode in [0o644, 0o654, 0o655]
    assert f.user == sdkman_user
    assert f.group == sdkman_group
    assert f.contains('sdkman_auto_answer=true')


def test_gradle_installed(host):
    cmds = ['gradle --version']
    expected = 'Gradle 4.6'
    check_run_for_rc_and_result(cmds, expected, host)


{'fraction_non_alphanumeric': 0.12758620689655173, 'fraction_numerical': 0.0187192118226601, 'mean_word_length': 3.33974358974359, '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': '2720377', 'n_tokens_mistral': 755, 'n_tokens_neox': 708, 'n_words': 164}