def __init__(self, *args, **kwargs): """ Set the UnitTestInfo object for each form in the formset and set initial values for any CONSTANT Test type. """ unit_test_infos = kwargs.pop("unit_test_infos") initial = [] for uti in unit_test_infos: init = {"value": None} if uti.test.type == models.CONSTANT: init["value"] = utils.to_precision(uti.test.constant_value, settings.CONSTANT_PRECISION) initial.append(init) kwargs.update(initial=initial) super(CreateTestInstanceFormSet, self).__init__(*args, **kwargs) for form, uti in zip(self.forms, unit_test_infos): form.set_unit_test_info(uti)
def test_float_format(self): numbers = ( (0.999, 3, "0.999"), (-0.999, 3, "-0.999"), (0.999, 1, "1"), (0.999, 2, "1.0"), (0.0, 4, "0"), (-0.0, 4, "0"), (1234.567, 1, "1e+3"), (1234.567, 2, "1.2e+3"), (1234.567, 5, "1234.6"), ) for number, prec, expected in numbers: self.assertEqual(qautils.to_precision(number, prec), expected)
def __init__(self, *args, **kwargs): """ Set the UnitTestInfo object for each form in the formset and set initial values for any CONSTANT Test type. """ unit_test_infos = kwargs.pop("unit_test_infos") initial = [] for uti in unit_test_infos: init = {"value": None} if uti.test.type == models.CONSTANT: init["value"] = utils.to_precision(uti.test.constant_value, 4) initial.append(init) kwargs.update(initial=initial) super(CreateTestInstanceFormSet, self).__init__(*args, **kwargs) for form, uti in zip(self.forms, unit_test_infos): form.set_unit_test_info(uti)
def test_invalid_default_fallback(self): assert qautils.format_qc_value(1, None) == qautils.to_precision( 1, settings.CONSTANT_PRECISION)
def test_invalid_format(self): assert qautils.format_qc_value(1, "{:foo}") == qautils.to_precision( 1, settings.CONSTANT_PRECISION)