Exemplo n.º 1
0
    def test_blankable(self):
        v = DoubleField(blank=True, blank_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 1
            mocked_random.uniform = random.uniform
            self.assertTrue(0 <= v.generate() <= 1)

        v = DoubleField(blank=True, blank_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 0
            mocked_random.uniform = random.uniform
            self.assertEqual(v.generate(), 0)
Exemplo n.º 2
0
    def test_nullable(self):
        v = DoubleField(null=True, null_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 1
            mocked_random.uniform = random.uniform
            self.assertTrue(0 <= v.generate() <= 1)

        v = DoubleField(null=True, null_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 0
            mocked_random.uniform = random.uniform
            self.assertIsNone(v.generate())
    def test_min_max_values(self):
        v = DoubleField(min_value=-2.5, max_value=0)
        self.assertTrue(-2.5 <= v.generate() <= 0)

        v = DoubleField(min_value=0, max_value=0)
        self.assertEqual(v.generate(), 0)

        v = DoubleField(min_value=2.5, max_value=0)
        self.assertTrue(0 <= v.generate() <= 2.5)
    def test_nullable_blankable(self):
        v = DoubleField(null=True, null_prob=0.3, blank=True, blank_prob=0.3)

        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 0
            mocked_random.uniform = random.uniform
            self.assertIsNone(v.generate())

        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 0.5
            mocked_random.uniform = random.uniform
            self.assertEqual(v.generate(), 0)

        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 1
            mocked_random.uniform = random.uniform
            self.assertTrue(0 <= v.generate() <= 1)
Exemplo n.º 5
0
    def test_nullable_blankable_choices(self):
        choices = [1, 5, 10]
        v = DoubleField(null=True, null_prob=0.3, blank=True, blank_prob=0.3, choices=choices)

        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 0
            mocked_random.choice = random.choice
            self.assertIsNone(v.generate())

        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 0.5
            mocked_random.choice = random.choice
            self.assertEqual(v.generate(), 0)

        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 1
            mocked_random.choice = random.choice
            self.assertIn(v.generate(), choices)
    def test_nullable_blankable_choices(self):
        choices = [1, 5, 10]
        v = DoubleField(null=True, null_prob=0.3, blank=True, blank_prob=0.3,
                        choices=choices)

        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 0
            mocked_random.choice = random.choice
            self.assertIsNone(v.generate())

        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 0.5
            mocked_random.choice = random.choice
            self.assertEqual(v.generate(), 0)

        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 1
            mocked_random.choice = random.choice
            self.assertIn(v.generate(), choices)
Exemplo n.º 7
0
    def test_not_required(self):
        v = DoubleField(required=False, not_present_prob=0)
        self.assertTrue(0 <= v.generate() <= 1)

        v = DoubleField(required=False, not_present_prob=1)
        with self.assertRaises(NotGeneratedException):
            v.generate()

        v = DoubleField(required=False, not_present_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 0
            with self.assertRaises(NotGeneratedException):
                v.generate()

        v = DoubleField(required=False, not_present_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 1
            mocked_random.uniform = random.uniform
            self.assertTrue(0 <= v.generate() <= 1)
Exemplo n.º 8
0
class SimpleTestSchema(BaseSchema):

    schema = {
        'array': ArrayField(IntegerField()),
        'nest-1': {
            'nest-2': {
                'string': StringField()
            },
            'integer': IntegerField()
        },
        'nest_3': {
            'double': DoubleField()
        }
    }
Exemplo n.º 9
0
    def test_min_max_values(self):
        v = DoubleField(min_value=-2.5, max_value=0)
        self.assertTrue(-2.5 <= v.generate() <= 0)

        v = DoubleField(min_value=0, max_value=0)
        self.assertEqual(v.generate(), 0)

        v = DoubleField(min_value=2.5, max_value=0)
        self.assertTrue(0 <= v.generate() <= 2.5)
 def test_choices(self):
     choices = [1, 5, 10]
     v = DoubleField(choices=choices)
     self.assertIn(v.generate(), choices)
    def test_not_required(self):
        v = DoubleField(required=False, not_present_prob=0)
        self.assertTrue(0 <= v.generate() <= 1)

        v = DoubleField(required=False, not_present_prob=1)
        with self.assertRaises(NotGeneratedException):
            v.generate()

        v = DoubleField(required=False, not_present_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 0
            with self.assertRaises(NotGeneratedException):
                v.generate()

        v = DoubleField(required=False, not_present_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 1
            mocked_random.uniform = random.uniform
            self.assertTrue(0 <= v.generate() <= 1)
 def test_default(self):
     v = DoubleField()
     self.assertTrue(0 <= v.generate() <= 1)
Exemplo n.º 13
0
 def test_choices(self):
     choices = [1, 5, 10]
     v = DoubleField(choices=choices)
     self.assertIn(v.generate(), choices)
Exemplo n.º 14
0
 def test_default(self):
     v = DoubleField()
     self.assertTrue(0 <= v.generate() <= 1)