<commit_before>#!/usr/bin/env python

# Author:
#   <NAME> <<EMAIL>>
#
# This script aims to verify the evaluation of an xccdf_session
#

import os
from import_handler import oscap, result2str, get_path


print("opening ./samples/xccdf_sample.xml ...")
sess = oscap.xccdf.session_new(get_path("samples/xccdf_sample.xml"))

res = sess.load()

if not res == 0:
    raise ValueError("Return value of xccdf_session_load isn't 0 but {0} !".format(res))

'''
rules to test whith desired return value
'''

rules = {"R-SHOULD_PASS": oscap.common.XCCDF_RESULT_PASS,
         "R-SHOULD_FAIL": oscap.common.XCCDF_RESULT_FAIL}

res = sess.evaluate()

if not res == 0:
    raise ValueError("Return value of xccdf_session_evaluate isn't 0 but {0} !".format(res))

if sess.get_base_score() != 50:
    raise ValueError("base score should be 50 but is {0} ", sess.get_base_score())

for rs in sess.get_xccdf_policy().get_results():
    for rr in rs.get_rule_results():
        print("Rule {0} evaluated as {1}"
              .format(rr.get_idref(), result2str(rr.get_result())))

        if rules[rr.get_idref()] != rr.get_result():
                raise ValueError("Result value of {0} should be {1} but is {2}"
                                 .format(rr.get_idref(), rules[rr.get_idref()], rr.get_result()))

sess.free()
<commit_msg>fix pep8 mistake past under the radars :D<commit_after>#!/usr/bin/env python

# Author:
#   <NAME> <<EMAIL>>
#
# This script aims to verify the evaluation of an xccdf_session
#

import os
from import_handler import oscap, result2str, get_path


print("opening ./samples/xccdf_sample.xml ...")
sess = oscap.xccdf.session_new(get_path("samples/xccdf_sample.xml"))

res = sess.load()

if not res == 0:
    raise ValueError("Return value of xccdf_session_load isn't 0 but {0} !".format(res))

'''
rules to test whith desired return value
'''

rules = {"R-SHOULD_PASS": oscap.common.XCCDF_RESULT_PASS,
         "R-SHOULD_FAIL": oscap.common.XCCDF_RESULT_FAIL}

res = sess.evaluate()

if not res == 0:
    raise ValueError("Return value of xccdf_session_evaluate isn't 0 but {0} !".format(res))

if sess.get_base_score() != 50:
    raise ValueError("base score should be 50 but is {0} ", sess.get_base_score())

for rs in sess.get_xccdf_policy().get_results():
    for rr in rs.get_rule_results():
        print("Rule {0} evaluated as {1}"
              .format(rr.get_idref(), result2str(rr.get_result())))

        if rules[rr.get_idref()] != rr.get_result():
            raise ValueError("Result value of {0} should be {1} but is {2}"
                             .format(rr.get_idref(), rules[rr.get_idref()], rr.get_result()))

sess.free()

{'fraction_non_alphanumeric': 0.14258841234010533, 'fraction_numerical': 0.013920240782543265, 'mean_word_length': 3.537542662116041, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7577427', 'n_tokens_mistral': 971, 'n_tokens_neox': 935, 'n_words': 241}