Module flavio.test_parameters

Classes

class TestPDG (methodName='runTest')
Expand source code
class TestPDG(unittest.TestCase):
    year = 2022
    FlavioParticle.load_table(p_data.basepath / f"particle{year}.csv")
    def test_pdg(self):
        # check some tex names and masses
        to_check = {
            'Bs': ('B_{s}', 5.36692),
            'Bc': ('B_{c}', 6.27447),
            'Bs*': ('B_{s}^{*}', 5.4154),
            'B*+': ('B^{*+}', 5.3247100000000005),
            'B*0': ('B^{*0}', 5.3247100000000005),
            'B+': ('B^{+}', 5.27934),
            'B0': ('B^{0}', 5.27966),
            'Ds': ('D_{s}', 1.96835),
            'Ds*': ('D_{s}^{*}', 2.1122),
            'D+': ('D^{+}', 1.86966),
            'D0': ('D^{0}', 1.86484),
            'h': ('H', 125.25),
            'J/psi': ('J/\\psi', 3.0969),
            'KL': ('K_{L}', 0.497611),
            'KS': ('K_{S}', 0.497611),
            'K*+': ('K^{*+}', 0.8955000000000001),
            'K*0': ('K^{*0}', 0.89555),
            'K+': ('K^{+}', 0.49367700000000003),
            'K0': ('K^{0}', 0.497611),
            'Lambda': ('\\Lambda', 1.115683),
            'Lambdab': ('\\Lambda_{b}', 5.6196),
            'Lambdac': ('\\Lambda_{c}', 2.28646),
            'omega': ('\\omega', 0.78266),
            'D*0': ('D^{*0}', 2.00685),
            'D*+': ('D^{*+}', 2.01026),
            'W': ('W', 80.379),
            'Z': ('Z', 91.1876),
            'e': ('e', 0.0005109989499999999),
            'eta': ('\\eta', 0.547862),
            'f0': ('f_{0}', 0.99),
            'mu': ('\\mu', 0.10565837550000001),
            'phi': ('\\phi', 1.019461),
            'pi+': ('\\pi^{+}', 0.13957039000000002),
            'pi0': ('\\pi^{0}', 0.1349768),
            'psi(2S)': ('\\psi_{2S}', 3.6861),
            'rho+': ('\\rho^{+}', 0.7752600000000001),
            'rho0': ('\\rho^{0}', 0.7752600000000001),
            't': ('t', 172.5),
            'tau': ('\\tau', 1.7768599999999999),
            'u': ('u', 0.00216),
            'p': ('p', 0.93827208816),
            'n': ('n', 0.9395654205)
        }
        for flavio_name, (tex_test, mass_test) in to_check.items():
            particle = FlavioParticle.from_flavio_name(flavio_name)
            self.assertEqual(particle.latex_name_simplified, tex_test)
            self.assertEqual(particle.flavio_m[3], mass_test)
        # check B_s lifetime and errors in picoseconds
        particle = FlavioParticle.from_flavio_name('Bs')
        tauBs = particle.flavio_tau[3:]
        self.assertAlmostEqual(tauBs[0]/ps, 1.520, places=3)
        self.assertAlmostEqual(tauBs[1]/ps, 0.005, places=3)
        self.assertAlmostEqual(tauBs[2]/ps, 0.005, places=3)

A class whose instances are single test cases.

By default, the test code itself should be placed in a method named 'runTest'.

If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.

Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.

If it is necessary to override the init method, the base class init method must always be called. It is important that subclasses should not change the signature of their init method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.

When subclassing TestCase, you can set these attributes: * failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'. * longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed. * maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

Ancestors

  • unittest.case.TestCase

Class variables

var year

Methods

def test_pdg(self)
Expand source code
def test_pdg(self):
    # check some tex names and masses
    to_check = {
        'Bs': ('B_{s}', 5.36692),
        'Bc': ('B_{c}', 6.27447),
        'Bs*': ('B_{s}^{*}', 5.4154),
        'B*+': ('B^{*+}', 5.3247100000000005),
        'B*0': ('B^{*0}', 5.3247100000000005),
        'B+': ('B^{+}', 5.27934),
        'B0': ('B^{0}', 5.27966),
        'Ds': ('D_{s}', 1.96835),
        'Ds*': ('D_{s}^{*}', 2.1122),
        'D+': ('D^{+}', 1.86966),
        'D0': ('D^{0}', 1.86484),
        'h': ('H', 125.25),
        'J/psi': ('J/\\psi', 3.0969),
        'KL': ('K_{L}', 0.497611),
        'KS': ('K_{S}', 0.497611),
        'K*+': ('K^{*+}', 0.8955000000000001),
        'K*0': ('K^{*0}', 0.89555),
        'K+': ('K^{+}', 0.49367700000000003),
        'K0': ('K^{0}', 0.497611),
        'Lambda': ('\\Lambda', 1.115683),
        'Lambdab': ('\\Lambda_{b}', 5.6196),
        'Lambdac': ('\\Lambda_{c}', 2.28646),
        'omega': ('\\omega', 0.78266),
        'D*0': ('D^{*0}', 2.00685),
        'D*+': ('D^{*+}', 2.01026),
        'W': ('W', 80.379),
        'Z': ('Z', 91.1876),
        'e': ('e', 0.0005109989499999999),
        'eta': ('\\eta', 0.547862),
        'f0': ('f_{0}', 0.99),
        'mu': ('\\mu', 0.10565837550000001),
        'phi': ('\\phi', 1.019461),
        'pi+': ('\\pi^{+}', 0.13957039000000002),
        'pi0': ('\\pi^{0}', 0.1349768),
        'psi(2S)': ('\\psi_{2S}', 3.6861),
        'rho+': ('\\rho^{+}', 0.7752600000000001),
        'rho0': ('\\rho^{0}', 0.7752600000000001),
        't': ('t', 172.5),
        'tau': ('\\tau', 1.7768599999999999),
        'u': ('u', 0.00216),
        'p': ('p', 0.93827208816),
        'n': ('n', 0.9395654205)
    }
    for flavio_name, (tex_test, mass_test) in to_check.items():
        particle = FlavioParticle.from_flavio_name(flavio_name)
        self.assertEqual(particle.latex_name_simplified, tex_test)
        self.assertEqual(particle.flavio_m[3], mass_test)
    # check B_s lifetime and errors in picoseconds
    particle = FlavioParticle.from_flavio_name('Bs')
    tauBs = particle.flavio_tau[3:]
    self.assertAlmostEqual(tauBs[0]/ps, 1.520, places=3)
    self.assertAlmostEqual(tauBs[1]/ps, 0.005, places=3)
    self.assertAlmostEqual(tauBs[2]/ps, 0.005, places=3)
class TestParameters (methodName='runTest')
Expand source code
class TestParameters(unittest.TestCase):
    def test_parameters(self):
        par_dict = default_parameters.get_central_all()
        # parameters from the YAML file
        self.assertEqual(par_dict['alpha_s'],  0.1184)
        self.assertEqual(par_dict['Gamma12_Bs_c'],  -48.0)
        # parameters from the PDG file
        self.assertEqual(par_dict['m_W'], 80.379)
        self.assertEqual(par_dict['tau_phi'], 1/4.249e-3)
        # just check if the random values are numbers
        for par_random in default_parameters.get_random_all().values():
            self.assertIsInstance(par_random, (float, int))
        for par_random in default_parameters.get_random_all(size=2).values():
            self.assertEqual(par_random.shape, (2,))

    def test_constraints_from_string(self):
        pds = constraints_from_string('1.36(34)(3) 1e-3')
        for pd in pds:
            self.assertEqual(pd.get_central(), 1.36e-3)
        self.assertEqual(pds[0].standard_deviation, 0.34e-3)
        self.assertEqual(pds[1].standard_deviation, 0.03e-3)

        pds = constraints_from_string('1.36(1.4)(3)1E5')
        for pd in pds:
            self.assertEqual(pd.get_central(), 1.36e5)
        self.assertEqual(pds[0].standard_deviation, 1.4e5)
        self.assertEqual(pds[1].standard_deviation, 0.03e5)

        pds = constraints_from_string('5(3)(2)')
        for pd in pds:
            self.assertEqual(pd.get_central(), 5.)
        self.assertEqual(pds[0].standard_deviation, 3.)
        self.assertEqual(pds[1].standard_deviation, 2.)

        pds = constraints_from_string('1.36 +- 0.34 +- 0.3 * 10^-5')
        for pd in pds:
            self.assertAlmostEqual(pd.get_central(), 1.36e-5, places=12)
        self.assertAlmostEqual(pds[0].standard_deviation, 0.34e-5, places=12)
        self.assertAlmostEqual(pds[1].standard_deviation, 0.3e-5, places=12)

        pds = constraints_from_string('1.36±0.34±0.3')
        for pd in pds:
            self.assertEqual(pd.get_central(), 1.36)
        self.assertEqual(pds[0].standard_deviation, 0.34)
        self.assertEqual(pds[1].standard_deviation, 0.3)

        pds = constraints_from_string(r'1.36 \pm 0.34 \pm 0.3')
        for pd in pds:
            self.assertEqual(pd.get_central(), 1.36)
        self.assertEqual(pds[0].standard_deviation, 0.34)
        self.assertEqual(pds[1].standard_deviation, 0.3)

        pds = constraints_from_string('5 + 0.1 - 0.2 + 0.3 - 0.5')
        for pd in pds:
            self.assertEqual(pd.get_central(), 5.)
        self.assertEqual(pds[0].left_deviation, 0.2)
        self.assertEqual(pds[0].right_deviation, 0.1)
        self.assertEqual(pds[1].left_deviation, 0.5)
        self.assertEqual(pds[1].right_deviation, 0.3)

    def test_yaml_io_new(self):
        from flavio import default_parameters
        with tempfile.NamedTemporaryFile('r+') as tf:
            write_file(tf.name, default_parameters)
            tf.seek(0) # rewind
            c = read_file(tf.name)
        self.assertEqual(c.get_yaml_dict(), default_parameters.get_yaml_dict())

A class whose instances are single test cases.

By default, the test code itself should be placed in a method named 'runTest'.

If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.

Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.

If it is necessary to override the init method, the base class init method must always be called. It is important that subclasses should not change the signature of their init method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.

When subclassing TestCase, you can set these attributes: * failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'. * longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed. * maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

Ancestors

  • unittest.case.TestCase

Methods

def test_constraints_from_string(self)
Expand source code
def test_constraints_from_string(self):
    pds = constraints_from_string('1.36(34)(3) 1e-3')
    for pd in pds:
        self.assertEqual(pd.get_central(), 1.36e-3)
    self.assertEqual(pds[0].standard_deviation, 0.34e-3)
    self.assertEqual(pds[1].standard_deviation, 0.03e-3)

    pds = constraints_from_string('1.36(1.4)(3)1E5')
    for pd in pds:
        self.assertEqual(pd.get_central(), 1.36e5)
    self.assertEqual(pds[0].standard_deviation, 1.4e5)
    self.assertEqual(pds[1].standard_deviation, 0.03e5)

    pds = constraints_from_string('5(3)(2)')
    for pd in pds:
        self.assertEqual(pd.get_central(), 5.)
    self.assertEqual(pds[0].standard_deviation, 3.)
    self.assertEqual(pds[1].standard_deviation, 2.)

    pds = constraints_from_string('1.36 +- 0.34 +- 0.3 * 10^-5')
    for pd in pds:
        self.assertAlmostEqual(pd.get_central(), 1.36e-5, places=12)
    self.assertAlmostEqual(pds[0].standard_deviation, 0.34e-5, places=12)
    self.assertAlmostEqual(pds[1].standard_deviation, 0.3e-5, places=12)

    pds = constraints_from_string('1.36±0.34±0.3')
    for pd in pds:
        self.assertEqual(pd.get_central(), 1.36)
    self.assertEqual(pds[0].standard_deviation, 0.34)
    self.assertEqual(pds[1].standard_deviation, 0.3)

    pds = constraints_from_string(r'1.36 \pm 0.34 \pm 0.3')
    for pd in pds:
        self.assertEqual(pd.get_central(), 1.36)
    self.assertEqual(pds[0].standard_deviation, 0.34)
    self.assertEqual(pds[1].standard_deviation, 0.3)

    pds = constraints_from_string('5 + 0.1 - 0.2 + 0.3 - 0.5')
    for pd in pds:
        self.assertEqual(pd.get_central(), 5.)
    self.assertEqual(pds[0].left_deviation, 0.2)
    self.assertEqual(pds[0].right_deviation, 0.1)
    self.assertEqual(pds[1].left_deviation, 0.5)
    self.assertEqual(pds[1].right_deviation, 0.3)
def test_parameters(self)
Expand source code
def test_parameters(self):
    par_dict = default_parameters.get_central_all()
    # parameters from the YAML file
    self.assertEqual(par_dict['alpha_s'],  0.1184)
    self.assertEqual(par_dict['Gamma12_Bs_c'],  -48.0)
    # parameters from the PDG file
    self.assertEqual(par_dict['m_W'], 80.379)
    self.assertEqual(par_dict['tau_phi'], 1/4.249e-3)
    # just check if the random values are numbers
    for par_random in default_parameters.get_random_all().values():
        self.assertIsInstance(par_random, (float, int))
    for par_random in default_parameters.get_random_all(size=2).values():
        self.assertEqual(par_random.shape, (2,))
def test_yaml_io_new(self)
Expand source code
def test_yaml_io_new(self):
    from flavio import default_parameters
    with tempfile.NamedTemporaryFile('r+') as tf:
        write_file(tf.name, default_parameters)
        tf.seek(0) # rewind
        c = read_file(tf.name)
    self.assertEqual(c.get_yaml_dict(), default_parameters.get_yaml_dict())