Loading binarycpython/tests/test_c_bindings.py +40 −7 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ from binarycpython.utils.functions import ( handle_ensemble_string_to_json, verbose_print, extract_ensemble_json_from_string, is_capsule, Capturing ) # https://docs.python.org/3/library/unittest.html Loading Loading @@ -63,12 +65,6 @@ ensemble_filters_off {8} ensemble_filter_{9} 1 probability 0.1" return argstring def is_capsule(o): t = type(o) return t.__module__ == 'builtins' and t.__name__ == 'PyCapsule' ####################################################################################################################################################### ### General run_system test ####################################################################################################################################################### Loading @@ -80,6 +76,10 @@ class test_run_system(unittest.TestCase): """ def test_output(self): with Capturing() as output: self._test_output() def _test_output(self): """ General test if run_system works """ Loading Loading @@ -123,10 +123,14 @@ class test_return_store_memaddr(unittest.TestCase): """ def test_return_store_memaddr(self): with Capturing() as output: self._test_return_store_memaddr() def _test_return_store_memaddr(self): """ Test to see if the memory adress is returned properly """ print(self.id()) output = _binary_c_bindings.return_store_memaddr() # print("function: test_return_store") Loading Loading @@ -159,6 +163,10 @@ class TestEnsemble(unittest.TestCase): super(TestEnsemble, self).__init__(*args, **kwargs) def test_return_persistent_data_memaddr(self): with Capturing() as output: self._test_return_persistent_data_memaddr() def _test_return_persistent_data_memaddr(self): """ Test case to check if the memory adress has been created succesfully """ Loading @@ -172,6 +180,10 @@ class TestEnsemble(unittest.TestCase): # ) def test_minimal_ensemble_output(self): with Capturing() as output: self._test_minimal_ensemble_output() def _test_minimal_ensemble_output(self): """ test_case to check if the ensemble output is correctly output """ Loading @@ -198,6 +210,10 @@ class TestEnsemble(unittest.TestCase): self.assertNotEqual(test_json["number_counts"], {}) def test_minimal_ensemble_output_defer(self): with Capturing() as output: self._test_minimal_ensemble_output_defer() def _test_minimal_ensemble_output_defer(self): """ test_case to check if the ensemble output is correctly output, by using defer command and freeing+outputting """ Loading Loading @@ -236,6 +252,10 @@ class TestEnsemble(unittest.TestCase): self.assertNotEqual(ensemble_json_output["number_counts"], {}) def test_add_ensembles_direct(self): with Capturing() as output: self._test_add_ensembles_direct() def _test_add_ensembles_direct(self): """ test_case to check if adding the ensemble outputs works. Many things should be caught by tests in the merge_dict test, but still good to test a bit here """ Loading Loading @@ -297,6 +317,10 @@ class TestEnsemble(unittest.TestCase): ) def test_compare_added_systems_with_double_deferred_systems(self): with Capturing() as output: self._test_compare_added_systems_with_double_deferred_systems() def _test_compare_added_systems_with_double_deferred_systems(self): """ test to run 2 systems without deferring, and merging them manually. Then run 2 systems with defer and then output them. """ Loading Loading @@ -384,6 +408,10 @@ class TestEnsemble(unittest.TestCase): ) def test_combine_with_empty_json(self): with Capturing() as output: self._test_combine_with_empty_json() def _test_combine_with_empty_json(self): """ Test for merging with an empty dict """ Loading @@ -408,6 +436,11 @@ class TestEnsemble(unittest.TestCase): self.assertEqual(merge_dicts(output_json_1, {}), output_json_1, assert_message) ############# # def test_full_ensemble_output(self): # with Capturing() as output: # self._test_full_ensemble_output() def _test_full_ensemble_output(self): """ Function to just output the whole ensemble Loading binarycpython/tests/test_custom_logging.py +31 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ Unittests for the custom_logging module import unittest from binarycpython.utils.custom_logging_functions import * from binarycpython.utils.functions import Capturing binary_c_temp_dir = temp_dir() Loading @@ -15,6 +16,11 @@ class test_custom_logging(unittest.TestCase): """ def test_autogen_C_logging_code(self): with Capturing() as output: self._test_autogen_C_logging_code() print("\n".join(output)) def _test_autogen_C_logging_code(self): """ Tests for the autogeneration of a print statement from a dictionary. and then checking if the output is correct """ Loading Loading @@ -43,6 +49,11 @@ class test_custom_logging(unittest.TestCase): self.assertEqual(output_3, None, msg="Output should be None") def test_binary_c_log_code(self): with Capturing() as output: self._test_binary_c_log_code() print("\n".join(output)) def _test_binary_c_log_code(self): """ Test to see if passing a print statement to the function results in correct binary_c output """ Loading @@ -61,6 +72,11 @@ class test_custom_logging(unittest.TestCase): ) def test_binary_c_write_log_code(self): with Capturing() as output: self._test_binary_c_write_log_code() print("\n".join(output)) def _test_binary_c_write_log_code(self): """ Tests to see if writing the code to a file and reading that out again is the same """ Loading @@ -85,6 +101,11 @@ class test_custom_logging(unittest.TestCase): self.assertEqual(repr(input_1), content_file, msg="Contents are not similar") def test_from_binary_c_config(self): with Capturing() as output: self._test_from_binary_c_config() print("\n".join(output)) def _test_from_binary_c_config(self): """ Tests for interfacing with binary_c-config """ Loading @@ -109,6 +130,11 @@ class test_custom_logging(unittest.TestCase): self.assertEqual(output_2, "2.1.7", msg="binary_c version doesnt match") def test_return_compilation_dict(self): with Capturing() as output: self._test_return_compilation_dict() print("\n".join(output)) def _test_return_compilation_dict(self): """ Tests to see if the compilation dictionary contains the correct keys """ Loading @@ -125,6 +151,11 @@ class test_custom_logging(unittest.TestCase): self.assertTrue("inc" in output) def test_create_and_load_logging_function(self): with Capturing() as output: self._test_create_and_load_logging_function() print("\n".join(output)) def _test_create_and_load_logging_function(self): """ Tests checking the output of create_and_load_logging_function. Should return a valid memory int and a correct filename """ Loading binarycpython/tests/test_distributions.py +77 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ import unittest from binarycpython.utils.distribution_functions import * from binarycpython.utils.useful_funcs import calc_sep_from_period from binarycpython.utils.functions import Capturing class TestDistributions(unittest.TestCase): """ Loading @@ -29,6 +29,10 @@ class TestDistributions(unittest.TestCase): self.tolerance = 1e-5 def test_setopts(self): with Capturing() as output: self._test_setopts() def _test_setopts(self): """ Unittest for function set_opts """ Loading @@ -45,6 +49,10 @@ class TestDistributions(unittest.TestCase): self.assertTrue(output_dict_2 == updated_dict) def test_flat(self): with Capturing() as output: self._test_flat() def _test_flat(self): """ Unittest for the function flat """ Loading @@ -55,6 +63,10 @@ class TestDistributions(unittest.TestCase): self.assertEqual(output_1, 1.0) def test_number(self): with Capturing() as output: self._test_number() def _test_number(self): """ Unittest for function number """ Loading @@ -65,6 +77,10 @@ class TestDistributions(unittest.TestCase): self.assertEqual(input_1, output_1) def test_const(self): with Capturing() as output: self._test_const() def _test_const(self): """ Unittest for function const """ Loading @@ -80,6 +96,10 @@ class TestDistributions(unittest.TestCase): ) def test_powerlaw(self): with Capturing() as output: self._test_powerlaw() def _test_powerlaw(self): """ unittest for the powerlaw test """ Loading Loading @@ -108,6 +128,10 @@ class TestDistributions(unittest.TestCase): self.assertRaises(ValueError, powerlaw, 1, 100, -1, 10) def test_three_part_power_law(self): with Capturing() as output: self._test_three_part_power_law() def _test_three_part_power_law(self): """ unittest for three_part_power_law """ Loading Loading @@ -142,6 +166,10 @@ class TestDistributions(unittest.TestCase): ) def test_Kroupa2001(self): with Capturing() as output: self._test_Kroupa2001() def _test_Kroupa2001(self): """ unittest for three_part_power_law """ Loading Loading @@ -173,6 +201,10 @@ class TestDistributions(unittest.TestCase): ) def test_ktg93(self): with Capturing() as output: self._test_ktg93() def _test_ktg93(self): """ unittest for three_part_power_law """ Loading Loading @@ -204,6 +236,10 @@ class TestDistributions(unittest.TestCase): ) def test_imf_tinsley1980(self): with Capturing() as output: self._test_imf_tinsley1980() def _test_imf_tinsley1980(self): """ Unittest for function imf_tinsley1980 """ Loading @@ -215,6 +251,10 @@ class TestDistributions(unittest.TestCase): ) def test_imf_scalo1986(self): with Capturing() as output: self._test_imf_scalo1986() def _test_imf_scalo1986(self): """ Unittest for function imf_scalo1986 """ Loading @@ -226,6 +266,10 @@ class TestDistributions(unittest.TestCase): ) def test_imf_scalo1998(self): with Capturing() as output: self._test_imf_scalo1998() def _test_imf_scalo1998(self): """ Unittest for function imf_scalo1986 """ Loading @@ -237,6 +281,10 @@ class TestDistributions(unittest.TestCase): ) def test_imf_chabrier2003(self): with Capturing() as output: self._test_imf_chabrier2003() def _test_imf_chabrier2003(self): """ Unittest for function imf_chabrier2003 """ Loading @@ -261,6 +309,10 @@ class TestDistributions(unittest.TestCase): ) def test_duquennoy1991(self): with Capturing() as output: self._test_duquennoy1991() def _test_duquennoy1991(self): """ Unittest for function duquennoy1991 """ Loading @@ -268,6 +320,10 @@ class TestDistributions(unittest.TestCase): self.assertEqual(duquennoy1991(4.2), gaussian(4.2, 4.8, 2.3, -2, 12)) def test_gaussian(self): with Capturing() as output: self._test_gaussian() def _test_gaussian(self): """ unittest for three_part_power_law """ Loading Loading @@ -299,6 +355,10 @@ class TestDistributions(unittest.TestCase): ) def test_Arenou2010_binary_fraction(self): with Capturing() as output: self._test_Arenou2010_binary_fraction() def _test_Arenou2010_binary_fraction(self): """ unittest for three_part_power_law """ Loading @@ -324,6 +384,10 @@ class TestDistributions(unittest.TestCase): self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) def test_raghavan2010_binary_fraction(self): with Capturing() as output: self._test_raghavan2010_binary_fraction() def _test_raghavan2010_binary_fraction(self): """ unittest for three_part_power_law """ Loading @@ -342,6 +406,10 @@ class TestDistributions(unittest.TestCase): self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) def test_Izzard2012_period_distribution(self): with Capturing() as output: self._test_Izzard2012_period_distribution() def _test_Izzard2012_period_distribution(self): """ unittest for three_part_power_law """ Loading Loading @@ -399,6 +467,10 @@ class TestDistributions(unittest.TestCase): self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) def test_flatsections(self): with Capturing() as output: self._test_flatsections() def _test_flatsections(self): """ unittest for three_part_power_law """ Loading Loading @@ -426,6 +498,10 @@ class TestDistributions(unittest.TestCase): self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) def test_sana12(self): with Capturing() as output: self._test_sana12() def _test_sana12(self): """ unittest for three_part_power_law """ Loading binarycpython/tests/test_functions.py +158 −0 Original line number Diff line number Diff line Loading @@ -45,13 +45,22 @@ class test_verbose_print(unittest.TestCase): Unittests for verbose_print """ def test_print(self): with Capturing() as output: self._test_print() def _test_print(self): """ Tests whether something gets printed """ verbose_print("test1", 1, 0) def test_not_print(self): with Capturing() as output: self._test_not_print() def _test_not_print(self): """ Tests whether nothing gets printed. """ Loading @@ -65,6 +74,10 @@ class test_remove_file(unittest.TestCase): """ def test_remove_file(self): with Capturing() as output: self._test_remove_file() def _test_remove_file(self): """ Test to remove a file """ Loading @@ -77,6 +90,10 @@ class test_remove_file(unittest.TestCase): remove_file(os.path.join(binary_c_temp_dir, "test_remove_file_file.txt")) def test_remove_nonexisting_file(self): with Capturing() as output: self._test_remove_nonexisting_file() def _test_remove_nonexisting_file(self): """ Test to try to remove a nonexistant file """ Loading @@ -92,6 +109,10 @@ class test_temp_dir(unittest.TestCase): """ def test_create_temp_dir(self): with Capturing() as output: self._test_create_temp_dir() def _test_create_temp_dir(self): """ Test making a temp directory and comparing that to what it should be """ Loading @@ -113,6 +134,10 @@ class test_create_hdf5(unittest.TestCase): """ def test_1(self): with Capturing() as output: self._test_1() def _test_1(self): """ Test that creates files, packs them in a hdf5 file and checks the contents """ Loading Loading @@ -146,6 +171,10 @@ class test_return_binary_c_version_info(unittest.TestCase): """ def test_not_parsed(self): with Capturing() as output: self._test_not_parsed() def _test_not_parsed(self): """ Test for the raw version_info output """ Loading @@ -158,6 +187,10 @@ class test_return_binary_c_version_info(unittest.TestCase): self.assertIn("SIGMA_THOMPSON", version_info) def test_parsed(self): with Capturing() as output: self._test_parsed() def _test_parsed(self): """ Test for the parssed version_info """ Loading @@ -182,6 +215,10 @@ class test_parse_binary_c_version_info(unittest.TestCase): """ def test_1(self): with Capturing() as output: self._test_1() def _test_1(self): """ Test for the parsed versio info, more detailed """ Loading Loading @@ -215,6 +252,10 @@ class test_output_lines(unittest.TestCase): """ def test_1(self): with Capturing() as output: self._test_1() def _test_1(self): """ Test to check if the shape and contents of output_lines is correct """ Loading @@ -234,6 +275,10 @@ class test_example_parse_output(unittest.TestCase): """ def test_normal_output(self): with Capturing() as output: self._test_normal_output() def _test_normal_output(self): """ Test checking if parsed output with a custom logging line works correctly """ Loading Loading @@ -263,6 +308,10 @@ class test_example_parse_output(unittest.TestCase): self.assertTrue(len(parsed_output["time"]) > 0) def test_mismatch_output(self): with Capturing() as output: self._test_mismatch_output() def _test_mismatch_output(self): """ Test checking if parsed output with a mismatching headerline doesnt have any contents """ Loading Loading @@ -294,6 +343,10 @@ class test_get_defaults(unittest.TestCase): """ def test_no_filter(self): with Capturing() as output: self._test_no_filter() def _test_no_filter(self): """ Test checking if the defaults without filtering contains non-filtered content """ Loading @@ -307,6 +360,10 @@ class test_get_defaults(unittest.TestCase): self.assertIn("use_fixed_timestep_%d", output_1.keys()) def test_filter(self): with Capturing() as output: self._test_filter() def _test_filter(self): """ Test checking filtering works correctly """ Loading @@ -326,7 +383,12 @@ class test_get_arg_keys(unittest.TestCase): Unittests for function get_arg_keys """ def test_1(self): with Capturing() as output: self._test_1() def _test_1(self): """ Test checking if some of the keys are indeed in the list """ Loading @@ -346,6 +408,10 @@ class test_create_arg_string(unittest.TestCase): """ def test_default(self): with Capturing() as output: self._test_default() def _test_default(self): """ Test checking if the argstring is correct """ Loading @@ -355,6 +421,10 @@ class test_create_arg_string(unittest.TestCase): self.assertEqual(argstring, "separation 40000 M_1 10") def test_sort(self): with Capturing() as output: self._test_sort() def _test_sort(self): """ Test checking if the argstring with a different ordered dict is also in a differnt order """ Loading @@ -364,6 +434,10 @@ class test_create_arg_string(unittest.TestCase): self.assertEqual(argstring, "M_1 10 separation 40000") def test_filtered(self): with Capturing() as output: self._test_filtered() def _test_filtered(self): """ Test if filtering works """ Loading @@ -379,6 +453,10 @@ class test_get_help(unittest.TestCase): """ def test_input_normal(self): with Capturing() as output: self._test_input_normal() def _test_input_normal(self): """ Function to test the get_help function """ Loading @@ -390,6 +468,10 @@ class test_get_help(unittest.TestCase): ) def test_no_input(self): with Capturing() as output: self._test_no_input() def _test_no_input(self): """ Test if the result is None if called without input """ Loading @@ -398,6 +480,10 @@ class test_get_help(unittest.TestCase): self.assertIsNone(output) def test_wrong_input(self): with Capturing() as output: self._test_wrong_input() def _test_wrong_input(self): """ Test if the result is None if called with an unknown input """ Loading @@ -415,6 +501,10 @@ class test_get_help_all(unittest.TestCase): """ def test_all_output(self): with Capturing() as output: self._test_all_output() def _test_all_output(self): """ Function to test the get_help_all function """ Loading @@ -441,6 +531,10 @@ class test_get_help_super(unittest.TestCase): """ def test_all_output(self): with Capturing() as output: self._test_all_output() def _test_all_output(self): """ Function to test the get_help_super function """ Loading @@ -467,6 +561,10 @@ class test_make_build_text(unittest.TestCase): """ def test_output(self): with Capturing() as output: self._test_output() def _test_output(self): """ Test checking the contents of the build_text """ Loading @@ -493,6 +591,10 @@ class test_write_binary_c_parameter_descriptions_to_rst_file(unittest.TestCase): """ def test_bad_outputname(self): with Capturing() as output: self._test_bad_outputname() def _test_bad_outputname(self): """ Test checking if None is returned when a bad input name is provided """ Loading @@ -505,6 +607,10 @@ class test_write_binary_c_parameter_descriptions_to_rst_file(unittest.TestCase): self.assertIsNone(output_1) def test_checkfile(self): with Capturing() as output: self._test_checkfile() def _test_checkfile(self): """ Test checking if the file is created correctly """ Loading @@ -523,6 +629,10 @@ class test_inspect_dict(unittest.TestCase): """ def test_compare_dict(self): with Capturing() as output: self._test_compare_dict() def _test_compare_dict(self): """ Test checking if inspect_dict returns the correct structure by comparing it to known value """ Loading @@ -545,6 +655,10 @@ class test_inspect_dict(unittest.TestCase): self.assertTrue(compare_dict == output_dict) def test_compare_dict_with_print(self): with Capturing() as output: self._test_compare_dict_with_print() def _test_compare_dict_with_print(self): """ Test checking output is printed """ Loading @@ -565,6 +679,10 @@ class test_merge_dicts(unittest.TestCase): """ def test_empty(self): with Capturing() as output: self._test_empty() def _test_empty(self): """ Test merging an empty dict """ Loading @@ -581,6 +699,10 @@ class test_merge_dicts(unittest.TestCase): self.assertTrue(output_dict == input_dict) def test_unequal_types(self): with Capturing() as output: self._test_unequal_types() def _test_unequal_types(self): """ Test merging unequal types: should raise valueError """ Loading @@ -591,6 +713,10 @@ class test_merge_dicts(unittest.TestCase): self.assertRaises(ValueError, merge_dicts, dict_1, dict_2) def test_bools(self): with Capturing() as output: self._test_bools() def _test_bools(self): """ Test merging dict with booleans """ Loading @@ -603,6 +729,10 @@ class test_merge_dicts(unittest.TestCase): self.assertTrue(output_dict["bool"]) def test_ints(self): with Capturing() as output: self._test_ints() def _test_ints(self): """ Test merging dict with ints """ Loading @@ -615,6 +745,10 @@ class test_merge_dicts(unittest.TestCase): self.assertEqual(output_dict["int"], 3) def test_floats(self): with Capturing() as output: self._test_floats() def _test_floats(self): """ Test merging dict with floats """ Loading @@ -626,6 +760,10 @@ class test_merge_dicts(unittest.TestCase): self.assertTrue(isinstance(output_dict["float"], float)) self.assertEqual(output_dict["float"], 9.1) def test_lists(self): with Capturing() as output: self._test_lists() def test_lists(self): """ Test merging dict with lists Loading @@ -639,6 +777,10 @@ class test_merge_dicts(unittest.TestCase): self.assertEqual(output_dict["list"], [1, 2, 3, 4]) def test_dicts(self): with Capturing() as output: self._test_dicts() def _test_dicts(self): """ Test merging dict with dicts """ Loading @@ -653,6 +795,10 @@ class test_merge_dicts(unittest.TestCase): ) def test_unsupported(self): with Capturing() as output: self._test_unsupported() def _test_unsupported(self): """ Test merging dict with unsupported types. should raise ValueError """ Loading @@ -670,6 +816,10 @@ class test_binaryc_json_serializer(unittest.TestCase): """ def test_not_function(self): with Capturing() as output: self._test_not_function() def _test_not_function(self): """ Test passing an object that doesnt get turned in to a string """ Loading @@ -679,6 +829,10 @@ class test_binaryc_json_serializer(unittest.TestCase): self.assertTrue(stringo == output) def test_function(self): with Capturing() as output: self._test_function() def _test_function(self): """ Test passing an object that gets turned in to a string: a function """ Loading @@ -694,6 +848,10 @@ class test_handle_ensemble_string_to_json(unittest.TestCase): """ def test_1(self): with Capturing() as output: self._test_1() def _test_1(self): """ Test passing string representation of a dictionary. """ Loading binarycpython/tests/test_grid.py +94 −1 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
binarycpython/tests/test_c_bindings.py +40 −7 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ from binarycpython.utils.functions import ( handle_ensemble_string_to_json, verbose_print, extract_ensemble_json_from_string, is_capsule, Capturing ) # https://docs.python.org/3/library/unittest.html Loading Loading @@ -63,12 +65,6 @@ ensemble_filters_off {8} ensemble_filter_{9} 1 probability 0.1" return argstring def is_capsule(o): t = type(o) return t.__module__ == 'builtins' and t.__name__ == 'PyCapsule' ####################################################################################################################################################### ### General run_system test ####################################################################################################################################################### Loading @@ -80,6 +76,10 @@ class test_run_system(unittest.TestCase): """ def test_output(self): with Capturing() as output: self._test_output() def _test_output(self): """ General test if run_system works """ Loading Loading @@ -123,10 +123,14 @@ class test_return_store_memaddr(unittest.TestCase): """ def test_return_store_memaddr(self): with Capturing() as output: self._test_return_store_memaddr() def _test_return_store_memaddr(self): """ Test to see if the memory adress is returned properly """ print(self.id()) output = _binary_c_bindings.return_store_memaddr() # print("function: test_return_store") Loading Loading @@ -159,6 +163,10 @@ class TestEnsemble(unittest.TestCase): super(TestEnsemble, self).__init__(*args, **kwargs) def test_return_persistent_data_memaddr(self): with Capturing() as output: self._test_return_persistent_data_memaddr() def _test_return_persistent_data_memaddr(self): """ Test case to check if the memory adress has been created succesfully """ Loading @@ -172,6 +180,10 @@ class TestEnsemble(unittest.TestCase): # ) def test_minimal_ensemble_output(self): with Capturing() as output: self._test_minimal_ensemble_output() def _test_minimal_ensemble_output(self): """ test_case to check if the ensemble output is correctly output """ Loading @@ -198,6 +210,10 @@ class TestEnsemble(unittest.TestCase): self.assertNotEqual(test_json["number_counts"], {}) def test_minimal_ensemble_output_defer(self): with Capturing() as output: self._test_minimal_ensemble_output_defer() def _test_minimal_ensemble_output_defer(self): """ test_case to check if the ensemble output is correctly output, by using defer command and freeing+outputting """ Loading Loading @@ -236,6 +252,10 @@ class TestEnsemble(unittest.TestCase): self.assertNotEqual(ensemble_json_output["number_counts"], {}) def test_add_ensembles_direct(self): with Capturing() as output: self._test_add_ensembles_direct() def _test_add_ensembles_direct(self): """ test_case to check if adding the ensemble outputs works. Many things should be caught by tests in the merge_dict test, but still good to test a bit here """ Loading Loading @@ -297,6 +317,10 @@ class TestEnsemble(unittest.TestCase): ) def test_compare_added_systems_with_double_deferred_systems(self): with Capturing() as output: self._test_compare_added_systems_with_double_deferred_systems() def _test_compare_added_systems_with_double_deferred_systems(self): """ test to run 2 systems without deferring, and merging them manually. Then run 2 systems with defer and then output them. """ Loading Loading @@ -384,6 +408,10 @@ class TestEnsemble(unittest.TestCase): ) def test_combine_with_empty_json(self): with Capturing() as output: self._test_combine_with_empty_json() def _test_combine_with_empty_json(self): """ Test for merging with an empty dict """ Loading @@ -408,6 +436,11 @@ class TestEnsemble(unittest.TestCase): self.assertEqual(merge_dicts(output_json_1, {}), output_json_1, assert_message) ############# # def test_full_ensemble_output(self): # with Capturing() as output: # self._test_full_ensemble_output() def _test_full_ensemble_output(self): """ Function to just output the whole ensemble Loading
binarycpython/tests/test_custom_logging.py +31 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ Unittests for the custom_logging module import unittest from binarycpython.utils.custom_logging_functions import * from binarycpython.utils.functions import Capturing binary_c_temp_dir = temp_dir() Loading @@ -15,6 +16,11 @@ class test_custom_logging(unittest.TestCase): """ def test_autogen_C_logging_code(self): with Capturing() as output: self._test_autogen_C_logging_code() print("\n".join(output)) def _test_autogen_C_logging_code(self): """ Tests for the autogeneration of a print statement from a dictionary. and then checking if the output is correct """ Loading Loading @@ -43,6 +49,11 @@ class test_custom_logging(unittest.TestCase): self.assertEqual(output_3, None, msg="Output should be None") def test_binary_c_log_code(self): with Capturing() as output: self._test_binary_c_log_code() print("\n".join(output)) def _test_binary_c_log_code(self): """ Test to see if passing a print statement to the function results in correct binary_c output """ Loading @@ -61,6 +72,11 @@ class test_custom_logging(unittest.TestCase): ) def test_binary_c_write_log_code(self): with Capturing() as output: self._test_binary_c_write_log_code() print("\n".join(output)) def _test_binary_c_write_log_code(self): """ Tests to see if writing the code to a file and reading that out again is the same """ Loading @@ -85,6 +101,11 @@ class test_custom_logging(unittest.TestCase): self.assertEqual(repr(input_1), content_file, msg="Contents are not similar") def test_from_binary_c_config(self): with Capturing() as output: self._test_from_binary_c_config() print("\n".join(output)) def _test_from_binary_c_config(self): """ Tests for interfacing with binary_c-config """ Loading @@ -109,6 +130,11 @@ class test_custom_logging(unittest.TestCase): self.assertEqual(output_2, "2.1.7", msg="binary_c version doesnt match") def test_return_compilation_dict(self): with Capturing() as output: self._test_return_compilation_dict() print("\n".join(output)) def _test_return_compilation_dict(self): """ Tests to see if the compilation dictionary contains the correct keys """ Loading @@ -125,6 +151,11 @@ class test_custom_logging(unittest.TestCase): self.assertTrue("inc" in output) def test_create_and_load_logging_function(self): with Capturing() as output: self._test_create_and_load_logging_function() print("\n".join(output)) def _test_create_and_load_logging_function(self): """ Tests checking the output of create_and_load_logging_function. Should return a valid memory int and a correct filename """ Loading
binarycpython/tests/test_distributions.py +77 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ import unittest from binarycpython.utils.distribution_functions import * from binarycpython.utils.useful_funcs import calc_sep_from_period from binarycpython.utils.functions import Capturing class TestDistributions(unittest.TestCase): """ Loading @@ -29,6 +29,10 @@ class TestDistributions(unittest.TestCase): self.tolerance = 1e-5 def test_setopts(self): with Capturing() as output: self._test_setopts() def _test_setopts(self): """ Unittest for function set_opts """ Loading @@ -45,6 +49,10 @@ class TestDistributions(unittest.TestCase): self.assertTrue(output_dict_2 == updated_dict) def test_flat(self): with Capturing() as output: self._test_flat() def _test_flat(self): """ Unittest for the function flat """ Loading @@ -55,6 +63,10 @@ class TestDistributions(unittest.TestCase): self.assertEqual(output_1, 1.0) def test_number(self): with Capturing() as output: self._test_number() def _test_number(self): """ Unittest for function number """ Loading @@ -65,6 +77,10 @@ class TestDistributions(unittest.TestCase): self.assertEqual(input_1, output_1) def test_const(self): with Capturing() as output: self._test_const() def _test_const(self): """ Unittest for function const """ Loading @@ -80,6 +96,10 @@ class TestDistributions(unittest.TestCase): ) def test_powerlaw(self): with Capturing() as output: self._test_powerlaw() def _test_powerlaw(self): """ unittest for the powerlaw test """ Loading Loading @@ -108,6 +128,10 @@ class TestDistributions(unittest.TestCase): self.assertRaises(ValueError, powerlaw, 1, 100, -1, 10) def test_three_part_power_law(self): with Capturing() as output: self._test_three_part_power_law() def _test_three_part_power_law(self): """ unittest for three_part_power_law """ Loading Loading @@ -142,6 +166,10 @@ class TestDistributions(unittest.TestCase): ) def test_Kroupa2001(self): with Capturing() as output: self._test_Kroupa2001() def _test_Kroupa2001(self): """ unittest for three_part_power_law """ Loading Loading @@ -173,6 +201,10 @@ class TestDistributions(unittest.TestCase): ) def test_ktg93(self): with Capturing() as output: self._test_ktg93() def _test_ktg93(self): """ unittest for three_part_power_law """ Loading Loading @@ -204,6 +236,10 @@ class TestDistributions(unittest.TestCase): ) def test_imf_tinsley1980(self): with Capturing() as output: self._test_imf_tinsley1980() def _test_imf_tinsley1980(self): """ Unittest for function imf_tinsley1980 """ Loading @@ -215,6 +251,10 @@ class TestDistributions(unittest.TestCase): ) def test_imf_scalo1986(self): with Capturing() as output: self._test_imf_scalo1986() def _test_imf_scalo1986(self): """ Unittest for function imf_scalo1986 """ Loading @@ -226,6 +266,10 @@ class TestDistributions(unittest.TestCase): ) def test_imf_scalo1998(self): with Capturing() as output: self._test_imf_scalo1998() def _test_imf_scalo1998(self): """ Unittest for function imf_scalo1986 """ Loading @@ -237,6 +281,10 @@ class TestDistributions(unittest.TestCase): ) def test_imf_chabrier2003(self): with Capturing() as output: self._test_imf_chabrier2003() def _test_imf_chabrier2003(self): """ Unittest for function imf_chabrier2003 """ Loading @@ -261,6 +309,10 @@ class TestDistributions(unittest.TestCase): ) def test_duquennoy1991(self): with Capturing() as output: self._test_duquennoy1991() def _test_duquennoy1991(self): """ Unittest for function duquennoy1991 """ Loading @@ -268,6 +320,10 @@ class TestDistributions(unittest.TestCase): self.assertEqual(duquennoy1991(4.2), gaussian(4.2, 4.8, 2.3, -2, 12)) def test_gaussian(self): with Capturing() as output: self._test_gaussian() def _test_gaussian(self): """ unittest for three_part_power_law """ Loading Loading @@ -299,6 +355,10 @@ class TestDistributions(unittest.TestCase): ) def test_Arenou2010_binary_fraction(self): with Capturing() as output: self._test_Arenou2010_binary_fraction() def _test_Arenou2010_binary_fraction(self): """ unittest for three_part_power_law """ Loading @@ -324,6 +384,10 @@ class TestDistributions(unittest.TestCase): self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) def test_raghavan2010_binary_fraction(self): with Capturing() as output: self._test_raghavan2010_binary_fraction() def _test_raghavan2010_binary_fraction(self): """ unittest for three_part_power_law """ Loading @@ -342,6 +406,10 @@ class TestDistributions(unittest.TestCase): self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) def test_Izzard2012_period_distribution(self): with Capturing() as output: self._test_Izzard2012_period_distribution() def _test_Izzard2012_period_distribution(self): """ unittest for three_part_power_law """ Loading Loading @@ -399,6 +467,10 @@ class TestDistributions(unittest.TestCase): self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) def test_flatsections(self): with Capturing() as output: self._test_flatsections() def _test_flatsections(self): """ unittest for three_part_power_law """ Loading Loading @@ -426,6 +498,10 @@ class TestDistributions(unittest.TestCase): self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg) def test_sana12(self): with Capturing() as output: self._test_sana12() def _test_sana12(self): """ unittest for three_part_power_law """ Loading
binarycpython/tests/test_functions.py +158 −0 Original line number Diff line number Diff line Loading @@ -45,13 +45,22 @@ class test_verbose_print(unittest.TestCase): Unittests for verbose_print """ def test_print(self): with Capturing() as output: self._test_print() def _test_print(self): """ Tests whether something gets printed """ verbose_print("test1", 1, 0) def test_not_print(self): with Capturing() as output: self._test_not_print() def _test_not_print(self): """ Tests whether nothing gets printed. """ Loading @@ -65,6 +74,10 @@ class test_remove_file(unittest.TestCase): """ def test_remove_file(self): with Capturing() as output: self._test_remove_file() def _test_remove_file(self): """ Test to remove a file """ Loading @@ -77,6 +90,10 @@ class test_remove_file(unittest.TestCase): remove_file(os.path.join(binary_c_temp_dir, "test_remove_file_file.txt")) def test_remove_nonexisting_file(self): with Capturing() as output: self._test_remove_nonexisting_file() def _test_remove_nonexisting_file(self): """ Test to try to remove a nonexistant file """ Loading @@ -92,6 +109,10 @@ class test_temp_dir(unittest.TestCase): """ def test_create_temp_dir(self): with Capturing() as output: self._test_create_temp_dir() def _test_create_temp_dir(self): """ Test making a temp directory and comparing that to what it should be """ Loading @@ -113,6 +134,10 @@ class test_create_hdf5(unittest.TestCase): """ def test_1(self): with Capturing() as output: self._test_1() def _test_1(self): """ Test that creates files, packs them in a hdf5 file and checks the contents """ Loading Loading @@ -146,6 +171,10 @@ class test_return_binary_c_version_info(unittest.TestCase): """ def test_not_parsed(self): with Capturing() as output: self._test_not_parsed() def _test_not_parsed(self): """ Test for the raw version_info output """ Loading @@ -158,6 +187,10 @@ class test_return_binary_c_version_info(unittest.TestCase): self.assertIn("SIGMA_THOMPSON", version_info) def test_parsed(self): with Capturing() as output: self._test_parsed() def _test_parsed(self): """ Test for the parssed version_info """ Loading @@ -182,6 +215,10 @@ class test_parse_binary_c_version_info(unittest.TestCase): """ def test_1(self): with Capturing() as output: self._test_1() def _test_1(self): """ Test for the parsed versio info, more detailed """ Loading Loading @@ -215,6 +252,10 @@ class test_output_lines(unittest.TestCase): """ def test_1(self): with Capturing() as output: self._test_1() def _test_1(self): """ Test to check if the shape and contents of output_lines is correct """ Loading @@ -234,6 +275,10 @@ class test_example_parse_output(unittest.TestCase): """ def test_normal_output(self): with Capturing() as output: self._test_normal_output() def _test_normal_output(self): """ Test checking if parsed output with a custom logging line works correctly """ Loading Loading @@ -263,6 +308,10 @@ class test_example_parse_output(unittest.TestCase): self.assertTrue(len(parsed_output["time"]) > 0) def test_mismatch_output(self): with Capturing() as output: self._test_mismatch_output() def _test_mismatch_output(self): """ Test checking if parsed output with a mismatching headerline doesnt have any contents """ Loading Loading @@ -294,6 +343,10 @@ class test_get_defaults(unittest.TestCase): """ def test_no_filter(self): with Capturing() as output: self._test_no_filter() def _test_no_filter(self): """ Test checking if the defaults without filtering contains non-filtered content """ Loading @@ -307,6 +360,10 @@ class test_get_defaults(unittest.TestCase): self.assertIn("use_fixed_timestep_%d", output_1.keys()) def test_filter(self): with Capturing() as output: self._test_filter() def _test_filter(self): """ Test checking filtering works correctly """ Loading @@ -326,7 +383,12 @@ class test_get_arg_keys(unittest.TestCase): Unittests for function get_arg_keys """ def test_1(self): with Capturing() as output: self._test_1() def _test_1(self): """ Test checking if some of the keys are indeed in the list """ Loading @@ -346,6 +408,10 @@ class test_create_arg_string(unittest.TestCase): """ def test_default(self): with Capturing() as output: self._test_default() def _test_default(self): """ Test checking if the argstring is correct """ Loading @@ -355,6 +421,10 @@ class test_create_arg_string(unittest.TestCase): self.assertEqual(argstring, "separation 40000 M_1 10") def test_sort(self): with Capturing() as output: self._test_sort() def _test_sort(self): """ Test checking if the argstring with a different ordered dict is also in a differnt order """ Loading @@ -364,6 +434,10 @@ class test_create_arg_string(unittest.TestCase): self.assertEqual(argstring, "M_1 10 separation 40000") def test_filtered(self): with Capturing() as output: self._test_filtered() def _test_filtered(self): """ Test if filtering works """ Loading @@ -379,6 +453,10 @@ class test_get_help(unittest.TestCase): """ def test_input_normal(self): with Capturing() as output: self._test_input_normal() def _test_input_normal(self): """ Function to test the get_help function """ Loading @@ -390,6 +468,10 @@ class test_get_help(unittest.TestCase): ) def test_no_input(self): with Capturing() as output: self._test_no_input() def _test_no_input(self): """ Test if the result is None if called without input """ Loading @@ -398,6 +480,10 @@ class test_get_help(unittest.TestCase): self.assertIsNone(output) def test_wrong_input(self): with Capturing() as output: self._test_wrong_input() def _test_wrong_input(self): """ Test if the result is None if called with an unknown input """ Loading @@ -415,6 +501,10 @@ class test_get_help_all(unittest.TestCase): """ def test_all_output(self): with Capturing() as output: self._test_all_output() def _test_all_output(self): """ Function to test the get_help_all function """ Loading @@ -441,6 +531,10 @@ class test_get_help_super(unittest.TestCase): """ def test_all_output(self): with Capturing() as output: self._test_all_output() def _test_all_output(self): """ Function to test the get_help_super function """ Loading @@ -467,6 +561,10 @@ class test_make_build_text(unittest.TestCase): """ def test_output(self): with Capturing() as output: self._test_output() def _test_output(self): """ Test checking the contents of the build_text """ Loading @@ -493,6 +591,10 @@ class test_write_binary_c_parameter_descriptions_to_rst_file(unittest.TestCase): """ def test_bad_outputname(self): with Capturing() as output: self._test_bad_outputname() def _test_bad_outputname(self): """ Test checking if None is returned when a bad input name is provided """ Loading @@ -505,6 +607,10 @@ class test_write_binary_c_parameter_descriptions_to_rst_file(unittest.TestCase): self.assertIsNone(output_1) def test_checkfile(self): with Capturing() as output: self._test_checkfile() def _test_checkfile(self): """ Test checking if the file is created correctly """ Loading @@ -523,6 +629,10 @@ class test_inspect_dict(unittest.TestCase): """ def test_compare_dict(self): with Capturing() as output: self._test_compare_dict() def _test_compare_dict(self): """ Test checking if inspect_dict returns the correct structure by comparing it to known value """ Loading @@ -545,6 +655,10 @@ class test_inspect_dict(unittest.TestCase): self.assertTrue(compare_dict == output_dict) def test_compare_dict_with_print(self): with Capturing() as output: self._test_compare_dict_with_print() def _test_compare_dict_with_print(self): """ Test checking output is printed """ Loading @@ -565,6 +679,10 @@ class test_merge_dicts(unittest.TestCase): """ def test_empty(self): with Capturing() as output: self._test_empty() def _test_empty(self): """ Test merging an empty dict """ Loading @@ -581,6 +699,10 @@ class test_merge_dicts(unittest.TestCase): self.assertTrue(output_dict == input_dict) def test_unequal_types(self): with Capturing() as output: self._test_unequal_types() def _test_unequal_types(self): """ Test merging unequal types: should raise valueError """ Loading @@ -591,6 +713,10 @@ class test_merge_dicts(unittest.TestCase): self.assertRaises(ValueError, merge_dicts, dict_1, dict_2) def test_bools(self): with Capturing() as output: self._test_bools() def _test_bools(self): """ Test merging dict with booleans """ Loading @@ -603,6 +729,10 @@ class test_merge_dicts(unittest.TestCase): self.assertTrue(output_dict["bool"]) def test_ints(self): with Capturing() as output: self._test_ints() def _test_ints(self): """ Test merging dict with ints """ Loading @@ -615,6 +745,10 @@ class test_merge_dicts(unittest.TestCase): self.assertEqual(output_dict["int"], 3) def test_floats(self): with Capturing() as output: self._test_floats() def _test_floats(self): """ Test merging dict with floats """ Loading @@ -626,6 +760,10 @@ class test_merge_dicts(unittest.TestCase): self.assertTrue(isinstance(output_dict["float"], float)) self.assertEqual(output_dict["float"], 9.1) def test_lists(self): with Capturing() as output: self._test_lists() def test_lists(self): """ Test merging dict with lists Loading @@ -639,6 +777,10 @@ class test_merge_dicts(unittest.TestCase): self.assertEqual(output_dict["list"], [1, 2, 3, 4]) def test_dicts(self): with Capturing() as output: self._test_dicts() def _test_dicts(self): """ Test merging dict with dicts """ Loading @@ -653,6 +795,10 @@ class test_merge_dicts(unittest.TestCase): ) def test_unsupported(self): with Capturing() as output: self._test_unsupported() def _test_unsupported(self): """ Test merging dict with unsupported types. should raise ValueError """ Loading @@ -670,6 +816,10 @@ class test_binaryc_json_serializer(unittest.TestCase): """ def test_not_function(self): with Capturing() as output: self._test_not_function() def _test_not_function(self): """ Test passing an object that doesnt get turned in to a string """ Loading @@ -679,6 +829,10 @@ class test_binaryc_json_serializer(unittest.TestCase): self.assertTrue(stringo == output) def test_function(self): with Capturing() as output: self._test_function() def _test_function(self): """ Test passing an object that gets turned in to a string: a function """ Loading @@ -694,6 +848,10 @@ class test_handle_ensemble_string_to_json(unittest.TestCase): """ def test_1(self): with Capturing() as output: self._test_1() def _test_1(self): """ Test passing string representation of a dictionary. """ Loading
binarycpython/tests/test_grid.py +94 −1 File changed.Preview size limit exceeded, changes collapsed. Show changes