Ejemplo n.º 1
0
class TestFloatOptionWithDefault(TestFloatOptionNoDefault):
    """Tests FloatOption with a default value."""

    def setUp(self):
        self.option = FloatOption(1234.5)

    def test_default(self):
        """Tests that the default was set correctly."""
        self.assertEqual(self.option.default, 1234.5)

    def test_schema(self):
        """Tests FloatOption schema method."""
        self.assertRaises(ValidationError, validate, 'error', self.option.schema())
        self.assertIsNone(validate(5.0, self.option.schema()))
        self.assertDictEqual(self.option.schema(), {'default': 1234.5, 'type': 'number'})
Ejemplo n.º 2
0
class TestFloatOptionWithDefault(TestFloatOptionNoDefault):
    """Tests FloatOption with a default value."""
    def setUp(self):
        self.option = FloatOption(1234.5)

    def test_default(self):
        """Tests that the default was set correctly."""
        self.assertEqual(self.option.default, 1234.5)

    def test_schema(self):
        """Tests FloatOption schema method."""
        self.assertRaises(ValidationError, validate, 'error',
                          self.option.schema())
        self.assertIsNone(validate(5.0, self.option.schema()))
        self.assertDictEqual(self.option.schema(), {
            'default': 1234.5,
            'type': 'number'
        })
Ejemplo n.º 3
0
class TestFloatOptionNoDefault(unittest.TestCase, OptionTest):
    """Tests FloatOption without a default value."""

    valid_success = [x / 10.0 for x in xrange(-100, 100)]

    encode_success = zip(valid_success, map(str, valid_success))

    decode_success = zip(map(str, valid_success), valid_success)
    decode_failure = [
        'hello',
        '1world',
        'test2',
    ]

    def setUp(self):
        self.option = FloatOption()

    def test_schema(self):
        """Tests FloatOption schema method."""
        self.assertRaises(ValidationError, validate, 'error', self.option.schema())
        self.assertIsNone(validate(5.5, self.option.schema()))
        self.assertDictEqual(self.option.schema(), {'type': 'number'})
Ejemplo n.º 4
0
class TestFloatOptionNoDefault(unittest.TestCase, OptionTest):
    """Tests FloatOption without a default value."""

    valid_success = [x / 10.0 for x in xrange(-100, 100)]

    encode_success = zip(valid_success, map(str, valid_success))

    decode_success = zip(map(str, valid_success), valid_success)
    decode_failure = [
        'hello',
        '1world',
        'test2',
    ]

    def setUp(self):
        self.option = FloatOption()

    def test_schema(self):
        """Tests FloatOption schema method."""
        self.assertRaises(ValidationError, validate, 'error',
                          self.option.schema())
        self.assertIsNone(validate(5.5, self.option.schema()))
        self.assertDictEqual(self.option.schema(), {'type': 'number'})