Exemplo n.º 1
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'))
Exemplo n.º 2
0
    def test_unitless_int(self):
        """Test that a specification can be a unitless integer (count)."""
        s = Specification('design', 10)
        self.assertEqual(s.quantity, 10)

        # test JSON output
        json_data = s.json
        self.assertEqual(json_data['value'], 10)

        # rebuild from JSON
        s2 = Specification.from_json(json_data)
        self.assertEqual(s.quantity, s2.quantity)
Exemplo n.º 3
0
 def test_dependency_access(self):
     deps = {'a': Datum(5., 'mag')}
     s = Specification('design', 0., '', dependencies=deps)
     self.assertEqual(s.a.quantity, 5. * u.mag)
     json_data = s.json
     self.assertEqual(json_data['dependencies']['a']['value'], 5.)
     self.assertEqual(json_data['dependencies']['a']['unit'], 'mag')
Exemplo n.º 4
0
 def test_filters(self):
     """Test setting filter dependencies."""
     filter_names = ['u', 'g']
     s = Specification('design', 5 * u.mag, filter_names=filter_names)
     for filter_name in s.filter_names:
         self.assertIn(filter_name, filter_names)
     self.assertEqual(len(filter_names), len(s.filter_names))
Exemplo n.º 5
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'))
Exemplo n.º 6
0
    def test_unitless(self):
        """Test unitless specifications."""
        s = Specification('design', 100., unit='')
        self.assertEqual(s.quantity.value, 100.)
        self.assertEqual(s.unit, u.Unit(''))
        self.assertEqual(s.unit_str, '')

        # test json output
        json_data = s.json
        self.assertEqual(json_data['name'], 'design')
        self.assertEqual(json_data['value'], 100.)
        self.assertEqual(json_data['unit'], '')

        # rebuild from json
        s2 = Specification.from_json(json_data)
        self.assertEqual(s.name, s2.name)
        self.assertEqual(s.quantity, s2.quantity)
        self.assertEqual(s.filter_names, s2.filter_names)

        # test datum output
        d = s.datum
        self.assertEqual(d.quantity, 100. * u.Unit(''))
        self.assertEqual(d.label, 'design')
Exemplo n.º 7
0
    def test_quantity(self):
        """Test creating and accessing a specification from a quantity."""
        s = Specification('design', 5 * u.mag)
        self.assertEqual(s.quantity.value, 5.)
        self.assertEqual(s.unit, u.mag)
        self.assertEqual(s.unit_str, 'mag')

        # test json output
        json_data = s.json
        self.assertEqual(json_data['name'], 'design')
        self.assertEqual(json_data['value'], 5.)
        self.assertEqual(json_data['unit'], 'mag')

        # rebuild from json
        s2 = Specification.from_json(json_data)
        self.assertEqual(s.name, s2.name)
        self.assertEqual(s.quantity, s2.quantity)
        self.assertEqual(s.filter_names, s2.filter_names)

        # test datum output
        d = s.datum
        self.assertEqual(d.quantity, 5. * u.mag)
        self.assertEqual(d.label, 'design')