Example #1
0
    def test_intervals_do_not_overlap(self):
        da_start = faker.date()
        a_start = PartialDate(da_start)

        da_end = datetime.strftime(
            faker.date_time_between(
                a_start.date_as_dt
            ), '%Y-%m-%d'
        )
        a_end = PartialDate(da_end)

        db_start = datetime.strftime(
            faker.date_time_between(
                a_end.date_as_dt
            ), '%Y-%m-%d'
        )
        b_start = PartialDate(db_start)

        db_end = datetime.strftime(
            faker.date_time_between(
                b_start.date_as_dt
            ), '%Y-%m-%d'
        )
        b_end = PartialDate(db_end)

        a = PartialDatesInterval(start=a_start, end=a_end)
        b = PartialDatesInterval(start=b_start, end=b_end)

        overlap = PartialDate.intervals_overlap(a, b)
        self.assertLessEqual(overlap, 0)
Example #2
0
    def test_lt_comparison_null(self):
        da = faker.date()

        a = PartialDate(da)
        b = PartialDate(None)
        with self.assertRaises(PartialDateException):
            self.assertLess(a, b)
Example #3
0
    def test_gt_comparison_null(self):
        da = faker.date()

        a = PartialDate(da)
        b = PartialDate(None)
        with self.assertRaises(PartialDateException):
            self.assertGreater(b, a)
Example #4
0
    def test_gt_comparison(self):
        dt = timedelta(100)

        da = faker.date()
        a = PartialDate(da)
        b = PartialDate(da) + dt

        self.assertGreater(b, a)
Example #5
0
    def test_sub_timedelta(self):
        dt = timedelta(100)

        da = faker.date()
        a = PartialDate(da)
        b = PartialDate(da) + dt

        self.assertTrue(b - dt, a)
Example #6
0
    def test_lt_comparison(self):
        dt = timedelta(100)

        da = faker.date()
        a = PartialDate(da)
        b = PartialDate(da) + dt

        self.assertLess(a, b)
Example #7
0
    def test_ge_comparison(self):
        dt = timedelta(100)

        da = faker.date()
        a = PartialDate(da)
        b = PartialDate(da) + dt
        c = PartialDate(da)

        self.assertGreaterEqual(b, a)
        self.assertGreaterEqual(c, a)
Example #8
0
    def test_sum_timedelta(self):
        da = faker.date()
        a = PartialDate(da)

        dt = timedelta(100)

        db = datetime.strftime(
            faker.date_time_between(
                a.date_as_dt + timedelta(days=100)
            ), '%Y-%m-%d'
        )
        b = PartialDate(db)
        self.assertTrue(b + dt, a)
Example #9
0
    def test_sub_partialdate(self):
        dt = timedelta(100)

        da = faker.date()
        a = PartialDate(da)
        b = a + dt

        self.assertTrue(b - a, dt)
Example #10
0
    def test_intervals_do_not_overlap_null_start_end(self):
        a_start = PartialDate(None)

        da_end = faker.date()
        a_end = PartialDate(da_end)

        db_start = datetime.strftime(
            faker.date_time_between(
                a_end.date_as_dt + timedelta(days=10)
            ), '%Y-%m-%d'
        )
        b_start = PartialDate(db_start)

        b_end = PartialDate(None)

        a = PartialDatesInterval(start=a_start, end=a_end)
        b = PartialDatesInterval(start=b_start, end=b_end)

        overlap = PartialDate.intervals_overlap(a, b)
        self.assertLessEqual(overlap, 0)
Example #11
0
    def test_eq_comparison_null(self):
        a = PartialDate(None)
        b = PartialDate(None)

        self.assertEqual(a, b)
Example #12
0
 def test_new_instance_null(self):
     d = PartialDate(None)
     self.assertEqual(d.date, None)
     self.assertEqual(d.date_as_dt, None)
Example #13
0
 def create_instance(self, ds=None, pattern=PartialDate.d_fmt):
     if not ds:
         ds = faker.date(pattern=pattern)
     return PartialDate(ds)