Exemple #1
0
 def setUp(self):
     """
     An instance of
     :class:`~lofarpipe.support.lofaringredient.LOFARingredient` is defined
     which contains three instances of
     :class:`~lofarpipe.support.lofaringredient.StringField`.
     """
     from lofarpipe.support.lofaringredient import StringField
     from lofarpipe.support.lofaringredient import LOFARingredient
     f = StringField(default="foo")
     g = StringField()
     h = StringField(default=1)
     self.lofaringredient = LOFARingredient({"f": f, "g": g, "h": h})
Exemple #2
0
 def setUp(self):
     """
     An instance of
     :class:`~lofarpipe.support.lofaringredient.LOFARingredient` is defined
     which contains three instances of
     :class:`~lofarpipe.support.lofaringredient.StringField`.
     """
     from lofarpipe.support.lofaringredient import StringField
     from lofarpipe.support.lofaringredient import LOFARingredient
     f = StringField(default="foo")
     g = StringField()
     h = StringField(default=1)
     self.lofaringredient = LOFARingredient({"f": f, "g": g, "h": h})
Exemple #3
0
class LOFARIngredientTest(unittest.TestCase):
    """
    Tests for :class:`lofarpipe.support.lofaringredient.LOFARingredient`
    """
    def setUp(self):
        """
        An instance of
        :class:`~lofarpipe.support.lofaringredient.LOFARingredient` is defined
        which contains three instances of
        :class:`~lofarpipe.support.lofaringredient.StringField`.
        """
        from lofarpipe.support.lofaringredient import StringField
        from lofarpipe.support.lofaringredient import LOFARingredient
        f = StringField(default="foo")
        g = StringField()
        h = StringField(default=1)
        self.lofaringredient = LOFARingredient({"f": f, "g": g, "h": h})

    def test_keys(self):
        """
        ``self.lofaringredient`` should contain keys for the two fields
        which have default parameters, but not for the one which is unset.
        """
        self.assertEqual(len(list(self.lofaringredient.keys())), 2)
        self.assertRaises(KeyError, lambda: self.lofaringredient['g'])

    def test_values(self):
        """
        Prior to setting, the value of the fields should be equal to
        the default value.
        """
        self.assertEqual(self.lofaringredient['f'], "foo")

    def test_set(self):
        """
        When set, the value of the fields should be equal to the new value.
        """
        self.lofaringredient['g'] = "bar"
        self.assertEqual(self.lofaringredient['g'], "bar")

    def test_bad_values(self):
        """
        Unacceptable values should raise an exception.
        """
        self.assertRaises(TypeError, lambda: self.lofaringredient['h'])
        self.lofaringredient['h'] = "bar"
        self.assertEqual(self.lofaringredient['h'], "bar")
Exemple #4
0
class LOFARIngredientTest(unittest.TestCase):
    """
    Tests for :class:`lofarpipe.support.lofaringredient.LOFARingredient`
    """
    def setUp(self):
        """
        An instance of
        :class:`~lofarpipe.support.lofaringredient.LOFARingredient` is defined
        which contains three instances of
        :class:`~lofarpipe.support.lofaringredient.StringField`.
        """
        from lofarpipe.support.lofaringredient import StringField
        from lofarpipe.support.lofaringredient import LOFARingredient
        f = StringField(default="foo")
        g = StringField()
        h = StringField(default=1)
        self.lofaringredient = LOFARingredient({"f": f, "g": g, "h": h})

    def test_keys(self):
        """
        ``self.lofaringredient`` should contain keys for the two fields
        which have default parameters, but not for the one which is unset.
        """
        self.assertEqual(len(self.lofaringredient.keys()), 2)
        self.assertRaises(KeyError, lambda: self.lofaringredient['g'])

    def test_values(self):
        """
        Prior to setting, the value of the fields should be equal to
        the default value.
        """
        self.assertEqual(self.lofaringredient['f'], "foo")

    def test_set(self):
        """
        When set, the value of the fields should be equal to the new value.
        """
        self.lofaringredient['g'] = "bar"
        self.assertEqual(self.lofaringredient['g'], "bar")

    def test_bad_values(self):
        """
        Unacceptable values should raise an exception.
        """
        self.assertRaises(TypeError, lambda: self.lofaringredient['h'])
        self.lofaringredient['h'] = "bar"
        self.assertEqual(self.lofaringredient['h'], "bar")