def test_parameters_with_quantity_powers(self):
        """Test if we can construct and use a Parameter instance passing  pint.Quantity and pint.Unit objects to the constructor and interval setter. Use different powers of 10 in parameter initialization and value assignment."""

        # Define the base unit of my parameter object.
        meter = Unit("meter")
        centimeter = Unit("centimeter")
        self.assertIsInstance(meter, Unit)

        minimum_undulator_length = 10.0 * meter
        undulator_length = Parameter("undulator_length", centimeter)

        self.assertIsInstance(undulator_length, Parameter)
        self.assertEqual(undulator_length.unit, Unit("centimeter"))

        undulator_length.add_interval(
            min_value=minimum_undulator_length,
            max_value=numpy.inf * meter,
            intervals_are_legal=True,
        )

        print(undulator_length)

        self.assertTrue(undulator_length.is_legal(10.1 * meter))
        self.assertFalse(undulator_length.is_legal(9.0 * centimeter))
        self.assertTrue(undulator_length.is_legal(5.5e4 * Unit("centimeter")))
 def test_parameter_iterable(self):
     par = Parameter("test")
     par.add_interval(3, 4.5, True)
     par.add_option(7, True)
     self.assertFalse(par.is_legal([0.5, 3.2, 5.0]))
     self.assertTrue(par.is_legal([3.1, 4.2, 4.4]))
     self.assertTrue(par.is_legal([3.1, 4.2, 4.4, 7]))
    def test_parameter_multiple_options(self):
        par = Parameter("test")
        par.add_option(9.8, True)

        self.assertRaises(ValueError, par.add_option, 3, False)
        self.assertFalse(par.is_legal(-831.0))
        self.assertTrue(par.is_legal(9.8))
        self.assertFalse(par.is_legal(3))
    def test_parameter_legal_option_bool(self):
        par = Parameter("test")
        par.add_option(True, True)

        self.assertFalse(par.is_legal(10))
        self.assertFalse(par.is_legal(9.8))
        self.assertTrue(par.is_legal(True))
        self.assertFalse(par.is_legal("A"))
        self.assertFalse(par.is_legal(38))
    def test_parameter_multiple_intervals(self):
        par = Parameter("test")
        par.add_interval(None, 8.5, True)  # minus infinite to 8.5

        self.assertRaises(ValueError, par.add_interval, 3, 4.5, False)
        self.assertTrue(par.is_legal(-831.0))
        self.assertTrue(par.is_legal(3.5))
        self.assertTrue(par.is_legal(5.0))
        self.assertFalse(par.is_legal(10.0))
    def test_parameter_illegal_interval_plus_legal_option(self):
        par = Parameter("test")
        par.add_interval(None, 8.5, False)  # minus infinite to 8.5
        par.add_option(5, True)

        self.assertFalse(par.is_legal(-831.0))
        self.assertFalse(par.is_legal(8.5))
        self.assertTrue(par.is_legal(5.0))
        self.assertTrue(par.is_legal(10.0))
        self.assertTrue(par.is_legal(11.0))
    def test_parameter_legal_option_int_and_float(self):
        par = Parameter("test")
        par.add_option(38, True)
        par.add_option(9.8, True)

        self.assertFalse(par.is_legal(10))
        self.assertTrue(par.is_legal(9.8))
        self.assertFalse(par.is_legal(True))
        self.assertFalse(par.is_legal("A"))
        self.assertTrue(par.is_legal(38))
    def test_parameter_illegal_interval_plus_illegal_option(self):
        par = Parameter("test")
        par.add_interval(None, 8.5, False)  # minus infinite to 8.5
        par.add_option(
            5, False)  # this is stupid, already accounted in the interval
        par.add_option(11, False)

        self.assertFalse(par.is_legal(-831.0))
        self.assertFalse(par.is_legal(8.5))  # illegal because closed interval
        self.assertFalse(par.is_legal(5.0))
        self.assertTrue(par.is_legal(10.0))
        self.assertFalse(par.is_legal(11.0))
 def test_parameter_no_legal_conditions(self):
     par = Parameter("test")
     self.assertTrue(
         par.is_legal(None))  # FIXME how is this supposed to work?
     self.assertTrue(par.is_legal(-999))
     self.assertTrue(par.is_legal(-1))
     self.assertTrue(par.is_legal(0))
     self.assertTrue(par.is_legal(1))
     self.assertTrue(par.is_legal("This is a string"))
     self.assertTrue(par.is_legal(True))
     self.assertTrue(par.is_legal(False))
     self.assertTrue(par.is_legal([0, "A", True]))
    def test_parameter_legal_option_fromlist(self):
        par = Parameter("test")
        par.add_option([9, 8, 38], True)

        self.assertFalse(par.is_legal(10))
        self.assertFalse(par.is_legal(9.8))
        self.assertFalse(par.is_legal(True))
        self.assertFalse(par.is_legal("A"))
        self.assertTrue(par.is_legal(38))
        self.assertTrue(par.is_legal(38.0))
        self.assertTrue(par.is_legal(8))
    def test_parameter_legal_option_string(self):
        par = Parameter("test")
        par.add_option(["B", "A"], True)

        self.assertFalse(par.is_legal(10))
        self.assertFalse(par.is_legal(9.8))
        self.assertFalse(par.is_legal(True))
        self.assertTrue(par.is_legal("A"))
        self.assertTrue(par.is_legal("B"))
        self.assertFalse(par.is_legal("C"))
        self.assertFalse(par.is_legal(38))
    def test_parameter_legal_interval(self):
        par = Parameter("test")
        par.add_interval(3, 4.5, True)

        self.assertTrue(par.is_legal(3.5))
        self.assertFalse(par.is_legal(1.0))