Commit 4e78d65f authored by David Hendriks's avatar David Hendriks
Browse files

Black profile

parent 83ca68e4
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ from binarycpython.utils.functions import (
    verbose_print,
    extract_ensemble_json_from_string,
    is_capsule,
    Capturing
    Capturing,
)

# https://docs.python.org/3/library/unittest.html
@@ -65,6 +65,7 @@ ensemble_filters_off {8} ensemble_filter_{9} 1 probability 0.1"

    return argstring


#######################################################################################################################################################
### General run_system test
#######################################################################################################################################################
@@ -117,6 +118,7 @@ class test_run_system(unittest.TestCase):

# TODO: Make some assertion tests in c


class test_return_store_memaddr(unittest.TestCase):
    """
    Unit test for return_store_memaddr
+59 −19
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ 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):
    """
    Unittest class
@@ -121,7 +122,9 @@ class TestDistributions(unittest.TestCase):

        # GO over the results and check whether they are equal (within tolerance)
        for i in range(len(python_results)):
            msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format(python_results[i], perl_results[i], str(input_lists[i]))
            msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format(
                python_results[i], perl_results[i], str(input_lists[i])
            )
            self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance)

        # extra test for k = -1
@@ -155,8 +158,12 @@ class TestDistributions(unittest.TestCase):

        # GO over the results and check whether they are equal (within tolerance)
        for i in range(len(python_results)):
            msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format(python_results[i], perl_results[i], str(input_lists[i]))
            self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg)
            msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format(
                python_results[i], perl_results[i], str(input_lists[i])
            )
            self.assertLess(
                np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
            )

        # Extra test:
        # M < M0
@@ -191,8 +198,12 @@ class TestDistributions(unittest.TestCase):

        # GO over the results and check whether they are equal (within tolerance)
        for i in range(len(python_results)):
            msg = "Error: Value perl: {} Value python: {} for mass: {}".format(python_results[i], perl_results[i], str(input_lists[i]))
            self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg)
            msg = "Error: Value perl: {} Value python: {} for mass: {}".format(
                python_results[i], perl_results[i], str(input_lists[i])
            )
            self.assertLess(
                np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
            )

        # Extra tests:
        self.assertEqual(
@@ -226,8 +237,12 @@ class TestDistributions(unittest.TestCase):

        # GO over the results and check whether they are equal (within tolerance)
        for i in range(len(python_results)):
            msg = "Error: Value perl: {} Value python: {} for mass: {}".format(python_results[i], perl_results[i], str(input_lists[i]))
            self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg)
            msg = "Error: Value perl: {} Value python: {} for mass: {}".format(
                python_results[i], perl_results[i], str(input_lists[i])
            )
            self.assertLess(
                np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
            )

        # extra test:
        self.assertEqual(
@@ -345,8 +360,12 @@ class TestDistributions(unittest.TestCase):

        # GO over the results and check whether they are equal (within tolerance)
        for i in range(len(python_results)):
            msg = "Error: Value perl: {} Value python: {} for logper: {}".format(python_results[i], perl_results[i], str(input_lists[i]))
            self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg)
            msg = "Error: Value perl: {} Value python: {} for logper: {}".format(
                python_results[i], perl_results[i], str(input_lists[i])
            )
            self.assertLess(
                np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
            )

        # Extra test:
        self.assertTrue(
@@ -380,8 +399,12 @@ class TestDistributions(unittest.TestCase):

        # GO over the results and check whether they are equal (within tolerance)
        for i in range(len(python_results)):
            msg = "Error: Value perl: {} Value python: {} for mass: {}".format(python_results[i], perl_results[i], str(input_lists[i]))
            self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg)
            msg = "Error: Value perl: {} Value python: {} for mass: {}".format(
                python_results[i], perl_results[i], str(input_lists[i])
            )
            self.assertLess(
                np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
            )

    def test_raghavan2010_binary_fraction(self):
        with Capturing() as output:
@@ -402,8 +425,12 @@ class TestDistributions(unittest.TestCase):

        # GO over the results and check whether they are equal (within tolerance)
        for i in range(len(python_results)):
            msg = "Error: Value perl: {} Value python: {} for mass: {}".format(python_results[i], perl_results[i], str(input_lists[i]))
            self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg)
            msg = "Error: Value perl: {} Value python: {} for mass: {}".format(
                python_results[i], perl_results[i], str(input_lists[i])
            )
            self.assertLess(
                np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
            )

    def test_Izzard2012_period_distribution(self):
        with Capturing() as output:
@@ -463,8 +490,12 @@ class TestDistributions(unittest.TestCase):

        # GO over the results and check whether they are equal (within tolerance)
        for i in range(len(python_results)):
            msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format(python_results[i], perl_results[i], str(input_lists[i]))
            self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg)
            msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format(
                python_results[i], perl_results[i], str(input_lists[i])
            )
            self.assertLess(
                np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
            )

    def test_flatsections(self):
        with Capturing() as output:
@@ -494,8 +525,12 @@ class TestDistributions(unittest.TestCase):

        # GO over the results and check whether they are equal (within tolerance)
        for i in range(len(python_results)):
            msg = "Error: Value perl: {} Value python: {} for q: {}".format(python_results[i], perl_results[i], str(input_lists[i]))
            self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg)
            msg = "Error: Value perl: {} Value python: {} for q: {}".format(
                python_results[i], perl_results[i], str(input_lists[i])
            )
            self.assertLess(
                np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
            )

    def test_sana12(self):
        with Capturing() as output:
@@ -746,8 +781,13 @@ class TestDistributions(unittest.TestCase):

        # GO over the results and check whether they are equal (within tolerance)
        for i in range(len(python_results)):
            msg = "Error: Value perl: {} Value python: {} for mass, mass2, per: {}".format(python_results[i], perl_results[i], str(input_lists[i]))
            self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg)
            msg = "Error: Value perl: {} Value python: {} for mass, mass2, per: {}".format(
                python_results[i], perl_results[i], str(input_lists[i])
            )
            self.assertLess(
                np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
            )


if __name__ == "__main__":
    unittest.main()
+0 −2
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ class test_verbose_print(unittest.TestCase):
    Unittests for verbose_print
    """


    def test_print(self):
        with Capturing() as output:
            self._test_print()
@@ -383,7 +382,6 @@ class test_get_arg_keys(unittest.TestCase):
    Unittests for function get_arg_keys
    """


    def test_1(self):
        with Capturing() as output:
            self._test_1()
+9 −6
Original line number Diff line number Diff line
@@ -887,12 +887,12 @@ class test_grid_evolve(unittest.TestCase):

        analytics = test_pop.evolve()

        self.assertTrue(isinstance(test_pop.grid_ensemble_results['ensemble'], dict))
        self.assertNotEqual(test_pop.grid_ensemble_results['ensemble'], {})
        self.assertTrue(isinstance(test_pop.grid_ensemble_results["ensemble"], dict))
        self.assertNotEqual(test_pop.grid_ensemble_results["ensemble"], {})

        self.assertIn("number_counts", test_pop.grid_ensemble_results['ensemble'])
        self.assertIn("number_counts", test_pop.grid_ensemble_results["ensemble"])
        self.assertNotEqual(
            test_pop.grid_ensemble_results['ensemble']["number_counts"], {}
            test_pop.grid_ensemble_results["ensemble"]["number_counts"], {}
        )

    def test_grid_evolve_2_threads_with_ensemble_comparing_two_methods(self):
@@ -1004,17 +1004,20 @@ class test_grid_evolve(unittest.TestCase):

                ensemble_output_2 = merge_dicts(ensemble_output_2, ensemble_json)

        for key in ensemble_output_1['ensemble']["number_counts"]["stellar_type"]["0"]:
        for key in ensemble_output_1["ensemble"]["number_counts"]["stellar_type"]["0"]:
            self.assertIn(key, ensemble_output_2["number_counts"]["stellar_type"]["0"])

            # compare values
            self.assertLess(
                np.abs(
                    ensemble_output_1['ensemble']["number_counts"]["stellar_type"]["0"][key]
                    ensemble_output_1["ensemble"]["number_counts"]["stellar_type"]["0"][
                        key
                    ]
                    - ensemble_output_2["number_counts"]["stellar_type"]["0"][key]
                ),
                1e-8,
            )


if __name__ == "__main__":
    unittest.main()
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ from binarycpython.utils.functions import Capturing
#     def test_1(self):
#         pass


class test_color_by_index(unittest.TestCase):
    """
    Unittests for function color_by_index
Loading