コード例 #1
0
    def test_min_max_values(self):
        v = IntegerField(min_value=-100, max_value=0)
        self.assertTrue(-100 <= v.generate() <= 0)

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

        v = IntegerField(min_value=100, max_value=0)
        with self.assertRaises(ValueError):
            v.generate()
コード例 #2
0
    def test_min_max_values(self):
        v = IntegerField(min_value=-100, max_value=0)
        self.assertTrue(-100 <= v.generate() <= 0)

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

        v = IntegerField(min_value=100, max_value=0)
        with self.assertRaises(ValueError):
            v.generate()
コード例 #3
0
    def test_blankable(self):
        v = IntegerField(blank=True, blank_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 1
            mocked_random.randint = random.randint
            self.assertTrue(0 <= v.generate() <= 100)

        v = IntegerField(blank=True, blank_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 0
            mocked_random.randint = random.randint
            self.assertEqual(v.generate(), 0)
コード例 #4
0
    def test_nullable(self):
        v = IntegerField(null=True, null_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 1
            mocked_random.randint = random.randint
            self.assertTrue(0 <= v.generate() <= 100)

        v = IntegerField(null=True, null_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 0
            mocked_random.randint = random.randint
            self.assertIsNone(v.generate())
コード例 #5
0
    def test_blankable(self):
        v = IntegerField(blank=True, blank_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 1
            mocked_random.randint = random.randint
            self.assertTrue(0 <= v.generate() <= 100)

        v = IntegerField(blank=True, blank_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 0
            mocked_random.randint = random.randint
            self.assertEqual(v.generate(), 0)
コード例 #6
0
    def test_nullable(self):
        v = IntegerField(null=True, null_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 1
            mocked_random.randint = random.randint
            self.assertTrue(0 <= v.generate() <= 100)

        v = IntegerField(null=True, null_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 0
            mocked_random.randint = random.randint
            self.assertIsNone(v.generate())
コード例 #7
0
    def test_nullable_blankable_choices(self):
        choices = [1, 5, 10]
        v = IntegerField(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)
コード例 #8
0
    def test_nullable_blankable_choices(self):
        choices = [1, 5, 10]
        v = IntegerField(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)
コード例 #9
0
    def test_not_required(self):
        v = IntegerField(required=False, not_present_prob=0)
        self.assertTrue(0 <= v.generate() <= 100)

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

        v = IntegerField(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 = IntegerField(required=False, not_present_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 1
            mocked_random.randint = random.randint
            self.assertTrue(0 <= v.generate() <= 100)
コード例 #10
0
    def test_not_required(self):
        v = IntegerField(required=False, not_present_prob=0)
        self.assertTrue(0 <= v.generate() <= 100)

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

        v = IntegerField(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 = IntegerField(required=False, not_present_prob=0.5)
        with mock.patch(FIELDS_RANDOM_MODULE) as mocked_random:
            mocked_random.random.return_value = 1
            mocked_random.randint = random.randint
            self.assertTrue(0 <= v.generate() <= 100)
コード例 #11
0
 def test_choices(self):
     choices = [1, 5, 10]
     v = IntegerField(choices=choices)
     self.assertIn(v.generate(), choices)
コード例 #12
0
 def test_default(self):
     v = IntegerField()
     self.assertTrue(0 <= v.generate() <= 100)
コード例 #13
0
 def test_choices(self):
     choices = [1, 5, 10]
     v = IntegerField(choices=choices)
     self.assertIn(v.generate(), choices)
コード例 #14
0
 def test_default(self):
     v = IntegerField()
     self.assertTrue(0 <= v.generate() <= 100)