Ejemplo n.º 1
0
    def test_reference_string(self):
        """Verify reference property for different reference datasets."""
        m1 = Metric('test',
                    'test',
                    '<=',
                    reference_url='example.com',
                    reference_doc='Doc',
                    reference_page=1)
        self.assertEqual(m1.reference, 'Doc, p. 1, example.com')

        m2 = Metric('test', 'test', '<=', reference_url='example.com')
        self.assertEqual(m2.reference, 'example.com')

        m3 = Metric('test',
                    'test',
                    '<=',
                    reference_url='example.com',
                    reference_doc='Doc')
        self.assertEqual(m3.reference, 'Doc, example.com')

        m4 = Metric('test',
                    'test',
                    '<=',
                    reference_doc='Doc',
                    reference_page=1)
        self.assertEqual(m4.reference, 'Doc, p. 1')

        m4 = Metric('test', 'test', '<=', reference_doc='Doc')
        self.assertEqual(m4.reference, 'Doc')
Ejemplo n.º 2
0
    def test_get_spec_dependency(self):
        af1 = Metric.from_yaml('AF1', yaml_doc=self.metric_doc)
        dep = af1.get_spec_dependency('design', 'AD1', filter_name='r')

        ad1 = Metric.from_yaml('AD1', yaml_doc=self.metric_doc)

        self.assertEqual(dep.quantity,
                         ad1.get_spec('design', filter_name='r').quantity)
Ejemplo n.º 3
0
    def test_check_spec(self):
        """Test Metric.check_spec()."""
        a = Specification('a', 0., 'mag')
        b_r = Specification('b', 2., 'mag', filter_names=['r'])
        b_ug = Specification('b', 4., 'mag', filter_names=['u', 'g'])
        m = Metric('test', 'test', '<', specs=[a, b_r, b_ug])

        self.assertFalse(m.check_spec(3. * u.mag, 'b', filter_name='r'))
        self.assertTrue(m.check_spec(3. * u.mag, 'b', filter_name='g'))
        self.assertTrue(m.check_spec(10. * u.mmag, 'b', filter_name='g'))
Ejemplo n.º 4
0
    def test_am1_get_spec_names(self):
        """Test get_spec_names against AM1."""
        am1 = Metric.from_yaml('AM1', yaml_doc=self.metric_doc)
        spec_names_all = am1.get_spec_names()
        self.assertTrue(len(spec_names_all) == 3)
        self.assertIn('design', spec_names_all)
        self.assertIn('minimum', spec_names_all)
        self.assertIn('stretch', spec_names_all)

        # No specs for bands other than r and i!
        spec_names_g = am1.get_spec_names(filter_name='g')
        self.assertTrue(len(spec_names_g) == 0)
Ejemplo n.º 5
0
    def test_json(self):
        """Simple test of the serialized JSON content of a metric."""
        name = 'T1'
        description = 'Test'
        operator_str = '=='
        reference_doc = 'TEST-1'
        reference_page = 1
        reference_url = 'example.com'
        params = {'p': Datum(5., 'mag')}
        m = Metric(name,
                   description,
                   operator_str,
                   reference_doc=reference_doc,
                   reference_url=reference_url,
                   reference_page=reference_page,
                   parameters=params)

        j = m.json
        self.assertEqual(j['name'], name)
        self.assertEqual(j['description'], description)
        self.assertEqual(j['operator_str'], operator_str)
        self.assertEqual(j['reference']['doc'], reference_doc)
        self.assertEqual(j['reference']['page'], reference_page)
        self.assertEqual(j['reference']['url'], reference_url)
        self.assertEqual(j['parameters']['p']['value'], 5.)
        self.assertEqual(j['parameters']['p']['unit'], 'mag')
        self.assertIsInstance(j['specifications'], list)

        # rebuild from json
        m2 = Metric.from_json(j)
        self.assertEqual(m.name, m2.name)
        self.assertEqual(m.description, m2.description)
        self.assertEqual(m.description, m2.description)
        self.assertEqual(m.reference_doc, m2.reference_doc)
        self.assertEqual(m.reference_page, m2.reference_page)
        self.assertEqual(m.reference_url, m2.reference_url)
        for name, param in m.parameters.items():
            self.assertEqual(param.quantity, m2.parameters[name].quantity)
        for spec1, spec2 in zip(m.specs, m2.specs):
            self.assertEqual(spec1.quantity, spec2.quantity)
    def __init__(self):
        MeasurementBase.__init__(self)
        self.metric = Metric('Test', 'Test metric', '<')
        self.quantity = 5. * u.mag

        # link a blob
        self.ablob = DemoBlob()

        # datum-based parameters
        self.register_parameter('datum_param',
                                datum=Datum(10. * u.arcsec),
                                description='A datum')
        # set this parameter later
        self.register_parameter('deferred_datum_param', description='A datum')

        # quantity-based parameter
        self.register_parameter('q_param',
                                quantity=10. * u.arcsec,
                                description='A quantity')
        # set this parameter later
        self.register_parameter('deferred_q_param', description='A quantity')

        # string-based parameters
        self.register_parameter('str_param',
                                'test_string',
                                description='A string')
        # set this parameter later
        self.register_parameter('deferred_str_param', description='A string')

        # boolean parameters
        self.register_parameter('bool_param', False, description='A boolean')
        # set this parameter later
        self.register_parameter('deferred_bool_param', description='A boolean')

        # int-type parameter
        self.register_parameter('int_param',
                                42,
                                description='An integer parameter')
        # set this parameter later
        self.register_parameter('deferred_int_param', description='An integer')

        # quantity-based extras
        self.register_extra('q_extra',
                            quantity=1000. * u.microJansky,
                            description='Quantity extra')

        # none-type extra
        self.register_extra('none_extra',
                            label='none type',
                            description='None type Extra')
        self.none_extra = None
Ejemplo n.º 7
0
 def test_operator_conversion(self):
     """Tests for Metric.convert_operator_str."""
     self.assertTrue(Metric.convert_operator_str('>=')(7, 7))
     self.assertTrue(Metric.convert_operator_str('>')(7, 5))
     self.assertTrue(Metric.convert_operator_str('<')(5, 7))
     self.assertTrue(Metric.convert_operator_str('<=')(7, 7))
     self.assertTrue(Metric.convert_operator_str('==')(7, 7))
     self.assertTrue(Metric.convert_operator_str('!=')(7, 5))
Ejemplo n.º 8
0
    def testGetSpec(self):
        """Test Metric.getSpec() search strategy."""
        a = Specification('a', 0., 'mag')
        b_r = Specification('b', 0., 'mag', filter_names=['r'])
        b_ug = Specification('b', 0., 'mag', filter_names=['u', 'g'])

        m = Metric('test', 'test', '==', specs=[a, b_r, b_ug])

        self.assertEqual(m.get_spec('a'), a)
        self.assertEqual(m.get_spec('a', filter_name='r'), a)
        self.assertEqual(m.get_spec('b', filter_name='r'), b_r)
        self.assertEqual(m.get_spec('b', filter_name='u'), b_ug)

        with self.assertRaises(RuntimeError):
            self.assertEqual(m.get_spec('c'))

        with self.assertRaises(RuntimeError):
            self.assertEqual(m.get_spec('b', filter_name='z'))
 def __init__(self):
     MeasurementBase.__init__(self)
     self.metric = Metric('Test', 'Test metric', '<')
     self.quantity = None
Ejemplo n.º 10
0
 def test_load_all_yaml_metrics(self):
     """Verify that all metrics from metrics.yaml can be loaded."""
     for metric_name in self.metric_doc:
         m = Metric.from_yaml(metric_name, yaml_doc=self.metric_doc)
         self.assertIsInstance(m, Metric)