From 93f85f6350dea03780abef11ab2b3c648e460529 Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Mon, 7 Dec 2020 19:34:40 +0000 Subject: [PATCH] updating the test directories. Will change to the following now; all off the different files in utils more or less get their own test_.py, nothing more --- .../tests/c_bindings/test_ensemble.py | 48 +++++++++++++------ binarycpython/tests/python_API_test.py | 2 - setup.py | 15 +++--- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/binarycpython/tests/c_bindings/test_ensemble.py b/binarycpython/tests/c_bindings/test_ensemble.py index cf05dd1a8..3fe9ab111 100644 --- a/binarycpython/tests/c_bindings/test_ensemble.py +++ b/binarycpython/tests/c_bindings/test_ensemble.py @@ -59,6 +59,38 @@ 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 + """ + + m1 = 2 # Msun + m2 = 0.1 # Msun + + ############################################################################################# + # The 2 runs below use the ensemble but do not defer the output to anything else, so that the + # results are returned directly after the run + + # Direct output commands + argstring_1 = return_argstring( + m1=m1, m2=m2, ensemble_filter="STELLAR_TYPE_COUNTS", defer_ensemble=0 + ) + # Get outputs + output_1 = _binary_c_bindings.run_system(argstring=argstring_1) + + test_ensemble_jsons_string = [ + line for line in output_1.splitlines() if line.startswith("ENSEMBLE_JSON") + ] + + test_json = handle_ensemble_string_to_json( + test_ensemble_jsons_string[0][len("ENSEMBLE_JSON ") :] + ) + + 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" def test_return_persistent_data_memaddr(): """ @@ -126,20 +158,6 @@ def test_passing_persistent_data_to_run_system(): ), "The output of the deferred two systems should not be the same as the first undeferred output" -import pickle - - -def pickle_n_checksize(obj): - - name = os.path.join(TMP_DIR, "test", "pickle") - - with open(name, "wb") as file: - pickle.dump(obj, file) - - file_stats = os.stat(name) - print("size: {}mb".format(file_stats.st_size / (1024 * 1024))) - os.remove(name) - def test_adding_ensemble_output(): """ Function that adds the output of 2 ensembles and compares it to the output that we get by deferring the first output @@ -367,6 +385,7 @@ def test_full_ensemble_output(): assert "scalars" in json_1.keys() def all(): + test_minimal_ensemble_output() test_return_persistent_data_memaddr() test_passing_persistent_data_to_run_system() test_full_ensemble_output() @@ -377,6 +396,7 @@ def all(): #### if __name__ == "__main__": + # test_minimal_ensemble_output() # test_return_persistent_data_memaddr() # test_passing_persistent_data_to_run_system() # test_full_ensemble_output() diff --git a/binarycpython/tests/python_API_test.py b/binarycpython/tests/python_API_test.py index d38dbac31..8bbe87204 100755 --- a/binarycpython/tests/python_API_test.py +++ b/binarycpython/tests/python_API_test.py @@ -36,14 +36,12 @@ def test_run_system(): metallicity, max_evolution_time, ) - output = _binary_c_bindings.run_system(argstring=argstring) print("function: 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 diff --git a/setup.py b/setup.py index a02b81944..4d31149f7 100644 --- a/setup.py +++ b/setup.py @@ -235,18 +235,19 @@ class CustomBuildCommand(distutils.command.build.build): distutils.command.build.build.run(self) +# It is tested and designed to work for versions {}, we can't guarantee proper functioning for other versions + +# If you want to use a different version of binary_c, download and install a different version of this package + + setup( name="binarycpython", version="0.2.1", description=""" -This is a python API for binary_c (versions {}) by David Hendriks, Rob Izzard and collaborators. -Based on the initial set up by Jeff andrews. -It is tested and designed to work for versions {}, we can't guarantee proper functioning for other versions - -If you want to use a different version of binary_c, download and install a different version of this package +This is a python API for binary_c (versions {}) by David Hendriks, Rob Izzard and collaborators. Based on the initial set up by Jeff andrews. """.format( - ",".join(str(REQUIRED_BINARY_C_VERSIONS)), - ",".join(str(REQUIRED_BINARY_C_VERSIONS)), + ",".join(REQUIRED_BINARY_C_VERSIONS), + ",".join(REQUIRED_BINARY_C_VERSIONS), ), author="David Hendriks", author_email="davidhendriks93@gmail.com", -- GitLab