Ejemplo n.º 1
0
    def test_generators(self):
        from mixer import generators as g

        test = next(g.gen_choice((1, 2, 3)))
        self.assertTrue(test in (1, 2, 3))

        self.assertTrue(g.get_date())

        test = next(g.gen_time())
        self.assertTrue(test)

        test = next(g.gen_datetime())
        self.assertTrue(test)

        test = next(g.gen_integer())
        self.assertTrue(-2147483647 <= test < 2147483647)

        test = next(g.gen_big_integer())
        self.assertTrue(-9223372036854775808 <= test < 9223372036854775808)

        test = next(g.gen_small_integer())
        self.assertTrue(-32768 <= test < 32768)

        test = next(g.gen_positive_integer())
        self.assertTrue(test >= 0)

        test = next(g.gen_small_positive_integer())
        self.assertTrue(test >= 0)

        test = next(g.gen_float())
        self.assertTrue(test)

        test = next(g.gen_boolean())
        self.assertTrue(test in (True, False))

        test = next(g.gen_string())
        self.assertTrue(test)

        test = next(g.gen_decimal())
        self.assertTrue(test)

        test = next(g.gen_positive_decimal())
        self.assertTrue(test)
Ejemplo n.º 2
0
def test_generators():
    """ Test random generators. """
    from mixer import generators as g

    test = next(g.gen_choice((1, 2, 3)))
    assert test in (1, 2, 3)

    test = next(g.gen_date())
    assert isinstance(test, datetime.date)

    min_date, max_date = (2010, 1, 1), (2011, 1, 1)
    test = next(g.gen_date(min_date, max_date))
    assert 2010 <= test.year <= 2011

    test = next(g.gen_date(
        datetime.date(*min_date), datetime.date(*max_date)))
    assert 2010 <= test.year <= 2011

    test = next(g.gen_time())
    assert isinstance(test, datetime.time)

    min_time, max_time = (14, 30), (15, 30)
    test = next(g.gen_time(min_time, max_time))
    assert 14 <= test.hour <= 15

    test = next(g.gen_time(
        datetime.time(*min_time), datetime.time(*max_time)))
    assert 14 <= test.hour <= 15

    test = next(g.gen_datetime())
    assert isinstance(test, datetime.datetime)

    test = next(g.gen_integer())
    assert -2147483647 <= test < 2147483647

    test = next(g.gen_big_integer())
    assert -9223372036854775808 <= test < 9223372036854775808

    test = next(g.gen_small_integer())
    assert -32768 <= test < 32768

    test = next(g.gen_positive_integer())
    assert test >= 0

    test = next(g.gen_small_positive_integer())
    assert test >= 0

    test = next(g.gen_float())
    assert test

    test = next(g.gen_boolean())
    assert test in (True, False)

    test = next(g.gen_string())
    assert test

    test = next(g.gen_decimal())
    assert test

    test = next(g.gen_positive_decimal())
    assert test

    test = next(g.gen_positive_decimal(i=2))
    assert test < 100

    test = next(g.gen_percent())
    assert 0 <= test <= 100

    test = next(g.gen_percent_decimal())
    assert Decimal('0.01') <= test <= Decimal('1.00')
Ejemplo n.º 3
0
    def test_generators(self):
        """ Test random generators. """
        from mixer import generators as g

        test = next(g.gen_choice((1, 2, 3)))
        self.assertTrue(test in (1, 2, 3))

        test = next(g.gen_date())
        self.assertTrue(isinstance(test, datetime.date))

        min_date, max_date = (2010, 1, 1), (2011, 1, 1)
        test = next(g.gen_date(min_date, max_date))
        self.assertTrue(2010 <= test.year <= 2011)

        test = next(
            g.gen_date(datetime.date(*min_date), datetime.date(*max_date)))
        self.assertTrue(2010 <= test.year <= 2011)

        test = next(g.gen_time())
        self.assertTrue(isinstance(test, datetime.time))

        min_time, max_time = (14, 30), (15, 30)
        test = next(g.gen_time(min_time, max_time))
        self.assertTrue(14 <= test.hour <= 15)

        test = next(
            g.gen_time(datetime.time(*min_time), datetime.time(*max_time)))
        self.assertTrue(14 <= test.hour <= 15)

        test = next(g.gen_datetime())
        self.assertTrue(isinstance(test, datetime.datetime))

        test = next(g.gen_integer())
        self.assertTrue(-2147483647 <= test < 2147483647)

        test = next(g.gen_big_integer())
        self.assertTrue(-9223372036854775808 <= test < 9223372036854775808)

        test = next(g.gen_small_integer())
        self.assertTrue(-32768 <= test < 32768)

        test = next(g.gen_positive_integer())
        self.assertTrue(test >= 0)

        test = next(g.gen_small_positive_integer())
        self.assertTrue(test >= 0)

        test = next(g.gen_float())
        self.assertTrue(test)

        test = next(g.gen_boolean())
        self.assertTrue(test in (True, False))

        test = next(g.gen_string())
        self.assertTrue(test)

        test = next(g.gen_decimal())
        self.assertTrue(test)

        test = next(g.gen_positive_decimal())
        self.assertTrue(test)
Ejemplo n.º 4
0
def test_generators():
    """ Test random generators. """
    from mixer import generators as g

    test = next(g.gen_choice((1, 2, 3)))
    assert test in (1, 2, 3)

    test = next(g.gen_date())
    assert isinstance(test, datetime.date)

    min_date, max_date = (2010, 1, 1), (2011, 1, 1)
    test = next(g.gen_date(min_date, max_date))
    assert 2010 <= test.year <= 2011

    test = next(g.gen_date(datetime.date(*min_date), datetime.date(*max_date)))
    assert 2010 <= test.year <= 2011

    test = next(g.gen_time())
    assert isinstance(test, datetime.time)

    min_time, max_time = (14, 30), (15, 30)
    test = next(g.gen_time(min_time, max_time))
    assert 14 <= test.hour <= 15

    test = next(g.gen_time(datetime.time(*min_time), datetime.time(*max_time)))
    assert 14 <= test.hour <= 15

    test = next(g.gen_datetime())
    assert isinstance(test, datetime.datetime)

    test = next(g.gen_integer())
    assert -2147483647 <= test < 2147483647

    test = next(g.gen_big_integer())
    assert -9223372036854775808 <= test < 9223372036854775808

    test = next(g.gen_small_integer())
    assert -32768 <= test < 32768

    test = next(g.gen_positive_integer())
    assert test >= 0

    test = next(g.gen_small_positive_integer())
    assert test >= 0

    test = next(g.gen_float())
    assert test

    test = next(g.gen_boolean())
    assert test in (True, False)

    test = next(g.gen_string())
    assert test

    test = next(g.gen_decimal())
    assert test

    test = next(g.gen_positive_decimal())
    assert test

    test = next(g.gen_positive_decimal(i=2))
    assert test < 100

    test = next(g.gen_percent())
    assert 0 <= test <= 100

    test = next(g.gen_percent_decimal())
    assert Decimal('0.01') <= test <= Decimal('1.00')

    test = next(g.gen_timedelta())
    assert test

    d1, d2 = next(g.gen_datetime_range())
    assert d1
    assert d2
    assert d2 > d1
Ejemplo n.º 5
0
    def test_generators(self):
        """ Test random generators. """
        from mixer import generators as g

        test = next(g.gen_choice((1, 2, 3)))
        self.assertTrue(test in (1, 2, 3))

        test = next(g.gen_date())
        self.assertTrue(isinstance(test, datetime.date))

        min_date, max_date = (2010, 1, 1), (2011, 1, 1)
        test = next(g.gen_date(min_date, max_date))
        self.assertTrue(2010 <= test.year <= 2011)

        test = next(g.gen_date(
            datetime.date(*min_date), datetime.date(*max_date)))
        self.assertTrue(2010 <= test.year <= 2011)

        test = next(g.gen_time())
        self.assertTrue(isinstance(test, datetime.time))

        min_time, max_time = (14, 30), (15, 30)
        test = next(g.gen_time(min_time, max_time))
        self.assertTrue(14 <= test.hour <= 15)

        test = next(g.gen_time(
            datetime.time(*min_time), datetime.time(*max_time)))
        self.assertTrue(14 <= test.hour <= 15)

        test = next(g.gen_datetime())
        self.assertTrue(isinstance(test, datetime.datetime))

        test = next(g.gen_integer())
        self.assertTrue(-2147483647 <= test < 2147483647)

        test = next(g.gen_big_integer())
        self.assertTrue(-9223372036854775808 <= test < 9223372036854775808)

        test = next(g.gen_small_integer())
        self.assertTrue(-32768 <= test < 32768)

        test = next(g.gen_positive_integer())
        self.assertTrue(test >= 0)

        test = next(g.gen_small_positive_integer())
        self.assertTrue(test >= 0)

        test = next(g.gen_float())
        self.assertTrue(test)

        test = next(g.gen_boolean())
        self.assertTrue(test in (True, False))

        test = next(g.gen_string())
        self.assertTrue(test)

        test = next(g.gen_decimal())
        self.assertTrue(test)

        test = next(g.gen_positive_decimal())
        self.assertTrue(test)