Commit 8040f3b7 authored by David Hendriks's avatar David Hendriks
Browse files

black-formatted

parent 91ebe2f6
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ def test_run_system():
    print("Binary_c output:")
    print(textwrap.indent(output, "\t"))


def test_run_system_with_log():
    m1 = 15.0  # Msun
    m2 = 14.0  # Msun
@@ -77,7 +78,9 @@ def test_run_system_with_custom_logging():
    # generate logging lines. Here you can choose whatever you want to have logged, and with what header
    # this generates working print statements
    logging_line = autogen_C_logging_code(
        {"MY_STELLAR_DATA": ["model.time", "star[0].mass"],}
        {
            "MY_STELLAR_DATA": ["model.time", "star[0].mass"],
        }
    )

    # Generate entire shared lib code around logging lines
+27 −9
Original line number Diff line number Diff line
@@ -45,10 +45,12 @@ def test_run_system():

    assert "SINGLE_STAR_LIFETIME" in output, "Run system not working properly"


#######################################################################################################################################################
### memaddr test
#######################################################################################################################################################


def test_return_store_memaddr():
    output = _binary_c_bindings.return_store_memaddr()

@@ -67,6 +69,7 @@ def test_unload_store_memaddr():
    _ = _binary_c_bindings.free_store_memaddr(output)
    print("freed store memaddr")


#######################################################################################################################################################
### ensemble tests
#######################################################################################################################################################
@@ -116,6 +119,7 @@ ensemble_filters_off {8} ensemble_filter_{9} 1 probability 0.1"

    return argstring


def test_minimal_ensemble_output():
    """
    Tase case to check if the ensemble output is correctly written to the buffer instead of printed
@@ -146,8 +150,13 @@ def test_minimal_ensemble_output():
    print(test_json.keys())
    print(test_json)

    assert test_json, "Ensemble output not correctly written passed to the buffer in _binary_c_bindings"
    assert "number_counts" in test_json.keys(), "Output doesn't contain the correct information"
    assert (
        test_json
    ), "Ensemble output not correctly written passed to the buffer in _binary_c_bindings"
    assert (
        "number_counts" in test_json.keys()
    ), "Output doesn't contain the correct information"


def test_return_persistent_data_memaddr():
    """
@@ -298,9 +307,11 @@ def test_adding_ensemble_output():
    )

    # Have the persistent_memory adress be released and have the json outputted
    test_2_output = _binary_c_bindings.free_persistent_data_memaddr_and_return_json_output(
    test_2_output = (
        _binary_c_bindings.free_persistent_data_memaddr_and_return_json_output(
            test_2_persistent_data_memaddr
        )
    )
    test_2_ensemble_json = [
        line for line in test_2_output.splitlines() if line.startswith("ENSEMBLE_JSON")
    ]
@@ -365,6 +376,7 @@ def test_adding_ensemble_output():
    ), assert_message_1
    # assert inspect_dict(test_1_merged_dict, print_structure=False) == inspect_dict(test_3_json, print_structure=False), assert_message_2


def test_free_and_json_output():
    """
    Function that tests the freeing of the memory adress and the output of the json
@@ -387,9 +399,11 @@ def test_free_and_json_output():
    )

    # Free memory adress
    json_output_by_freeing = _binary_c_bindings.free_persistent_data_memaddr_and_return_json_output(
    json_output_by_freeing = (
        _binary_c_bindings.free_persistent_data_memaddr_and_return_json_output(
            persistent_data_memaddr
        )
    )
    # print(textwrap.indent(str(json_output_by_freeing), "\t"))

    parsed_json = handle_ensemble_string_to_json(
@@ -398,6 +412,7 @@ def test_free_and_json_output():

    assert "number_counts" in parsed_json.keys(), "Output not correct"


def test_combine_with_empty_json():
    """
    Test for merging with an empty dict
@@ -412,12 +427,12 @@ def test_combine_with_empty_json():
        ensemble_jsons_1[0][len("ENSEMBLE_JSON ") :]
    )


    assert_message = (
        "combining output json with empty dict should give same result as initial json"
    )
    assert merge_dicts(json_1, {}) == json_1, assert_message


#############
def test_full_ensemble_output():
    """
@@ -431,7 +446,9 @@ def test_full_ensemble_output():
    ensemble_jsons_1 = [
        line for line in output_1.splitlines() if line.startswith("ENSEMBLE_JSON")
    ]
    json_1 = handle_ensemble_string_to_json(ensemble_jsons_1[0][len("ENSEMBLE_JSON ") :])
    json_1 = handle_ensemble_string_to_json(
        ensemble_jsons_1[0][len("ENSEMBLE_JSON ") :]
    )

    # assert statements:
    assert "number_counts" in json_1.keys()
@@ -441,6 +458,7 @@ def test_full_ensemble_output():
    assert "distributions" in json_1.keys()
    assert "scalars" in json_1.keys()


def all():
    test_run_system()
    test_return_store_memaddr()
+0 −1
Original line number Diff line number Diff line
from binarycpython.utils.custom_logging_functions import *
+1 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ from binarycpython.utils.functions import *
#############################
# Script that contains unit tests for functions from the binarycpython.utils.functions file


def test_get_help_super():
    """
    Function to test the get_help_super function
+12 −9
Original line number Diff line number Diff line
@@ -256,7 +256,8 @@ def compile_shared_lib(code, sourcefile_name, outfile_name, verbose=0):
    compilation_dict = return_compilation_dict(verbose)

    # Construct full command
    command = "{cc} -fPIC {ccflags} {libs} -o {outfile_name} {sourcefile_name} {inc}".format(
    command = (
        "{cc} -fPIC {ccflags} {libs} -o {outfile_name} {sourcefile_name} {inc}".format(
            cc=compilation_dict["cc"],
            ccflags=compilation_dict["ccflags"],
            libs=compilation_dict["libs"],
@@ -264,6 +265,7 @@ def compile_shared_lib(code, sourcefile_name, outfile_name, verbose=0):
            sourcefile_name=sourcefile_name,
            inc=compilation_dict["inc"],
        )
    )

    # remove extra whitespaces:
    command = " ".join(command.split())
@@ -320,7 +322,8 @@ def create_and_load_logging_function(custom_logging_code, verbose=0):
    _ = ctypes.CDLL("libbinary_c.so", mode=ctypes.RTLD_GLOBAL)

    libcustom_logging = ctypes.CDLL(
        library_name, mode=ctypes.RTLD_GLOBAL,
        library_name,
        mode=ctypes.RTLD_GLOBAL,
    )  # loads the shared library

    # Get memory adress of function. mimicking a pointer
Loading