Module flavio.test_measurements

Classes

class TestMeasurements (methodName='runTest')
Expand source code
class TestMeasurements(unittest.TestCase):
    def test_measurements(self):
        m = Measurement['Belle phigamma 2014']
        self.assertEqual(m.experiment, 'Belle')

    def test_yaml_io_new(self):
        # read_file for a single measurement
        m1 = Measurement['Belle phigamma 2014']
        with tempfile.NamedTemporaryFile('r+') as tf:
            tf.write(m1.get_yaml(pname='observables'))
            tf.seek(0) # rewind
            m2 = read_file(tf.name)
            m2 = [Measurement[m] for m in m2]
        self.assertEqual(m1.get_yaml_dict(), m2[0].get_yaml_dict())
        # and now for 2 measurements
        m1 = [Measurement['Belle phigamma 2014'], Measurement['HFAG rad 2014']]
        with tempfile.NamedTemporaryFile('r+') as tf:
            write_file(tf.name, m1)
            tf.seek(0) # rewind
            m2 = read_file(tf.name)
            m2 = [Measurement[m] for m in m2]
        for i in range(2):
            self.assertEqual(m1[i].get_yaml_dict(), m2[i].get_yaml_dict())
        # and again but using the string names in write_file
        with tempfile.NamedTemporaryFile('r+') as tf:
            write_file(tf.name, [m.name for m in m1])
            tf.seek(0) # rewind
            m2 = read_file(tf.name)
            m2 = [Measurement[m] for m in m2]
        for i in range(2):
            self.assertEqual(m1[i].get_yaml_dict(), m2[i].get_yaml_dict())

    def test_fix_correlation(self):
        npt.assert_array_equal(
            _fix_correlation_matrix(0.3, 2),
            np.array([[1, 0.3], [0.3, 1]]))
        npt.assert_array_equal(
            _fix_correlation_matrix(0.3, 3),
            np.array([[1, 0.3, 0.3], [0.3, 1, 0.3], [0.3, 0.3, 1]]))
        npt.assert_array_equal(
            _fix_correlation_matrix([[1, 0.4, 0.3], [1, 0.2], [1]], 3),
            np.array([[1, 0.4, 0.3], [0.4, 1, 0.2], [0.3, 0.2, 1]]))

    def test_measurements_yaml(self):
        # check if all observables in existing measurements exist
        for name, m in flavio.Measurement.instances.items():
            for obs in m.all_parameters:
                if 'test' in obs or 'test' in name:
                    continue  # ignore observables defined in unit tests
                # this will raise if the observable does not exist
                obsname = flavio.Observable.argument_format(obs, 'dict')['name']
                flavio.Observable[obsname]

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_fix_correlation(self)
Expand source code
def test_fix_correlation(self):
    npt.assert_array_equal(
        _fix_correlation_matrix(0.3, 2),
        np.array([[1, 0.3], [0.3, 1]]))
    npt.assert_array_equal(
        _fix_correlation_matrix(0.3, 3),
        np.array([[1, 0.3, 0.3], [0.3, 1, 0.3], [0.3, 0.3, 1]]))
    npt.assert_array_equal(
        _fix_correlation_matrix([[1, 0.4, 0.3], [1, 0.2], [1]], 3),
        np.array([[1, 0.4, 0.3], [0.4, 1, 0.2], [0.3, 0.2, 1]]))
def test_measurements(self)
Expand source code
def test_measurements(self):
    m = Measurement['Belle phigamma 2014']
    self.assertEqual(m.experiment, 'Belle')
def test_measurements_yaml(self)
Expand source code
def test_measurements_yaml(self):
    # check if all observables in existing measurements exist
    for name, m in flavio.Measurement.instances.items():
        for obs in m.all_parameters:
            if 'test' in obs or 'test' in name:
                continue  # ignore observables defined in unit tests
            # this will raise if the observable does not exist
            obsname = flavio.Observable.argument_format(obs, 'dict')['name']
            flavio.Observable[obsname]
def test_yaml_io_new(self)
Expand source code
def test_yaml_io_new(self):
    # read_file for a single measurement
    m1 = Measurement['Belle phigamma 2014']
    with tempfile.NamedTemporaryFile('r+') as tf:
        tf.write(m1.get_yaml(pname='observables'))
        tf.seek(0) # rewind
        m2 = read_file(tf.name)
        m2 = [Measurement[m] for m in m2]
    self.assertEqual(m1.get_yaml_dict(), m2[0].get_yaml_dict())
    # and now for 2 measurements
    m1 = [Measurement['Belle phigamma 2014'], Measurement['HFAG rad 2014']]
    with tempfile.NamedTemporaryFile('r+') as tf:
        write_file(tf.name, m1)
        tf.seek(0) # rewind
        m2 = read_file(tf.name)
        m2 = [Measurement[m] for m in m2]
    for i in range(2):
        self.assertEqual(m1[i].get_yaml_dict(), m2[i].get_yaml_dict())
    # and again but using the string names in write_file
    with tempfile.NamedTemporaryFile('r+') as tf:
        write_file(tf.name, [m.name for m in m1])
        tf.seek(0) # rewind
        m2 = read_file(tf.name)
        m2 = [Measurement[m] for m in m2]
    for i in range(2):
        self.assertEqual(m1[i].get_yaml_dict(), m2[i].get_yaml_dict())