예제 #1
0
 def test_iso_conversions(self):
     a = ApproxDate.from_iso8601("2015")
     assert a.to_iso8601() == "2015"
     a = ApproxDate.from_iso8601("2015-06")
     assert a.to_iso8601() == "2015-06"
     a = ApproxDate.from_iso8601("2015-06-23")
     assert a.to_iso8601() == "2015-06-23"
     a = ApproxDate.from_iso8601("2015-06-23/2015-07-12")
     assert a.to_iso8601() == "2015-06-23/2015-07-12"
    def test_date_save_load(self):

        p = Person()
        p.birth_date = ApproxDate.from_iso8601("2015")
        assert approx_date_to_iso(p.birth_date) == "2015"
        p.birth_date = ApproxDate.from_iso8601("2015-06")
        assert approx_date_to_iso(p.birth_date) == "2015-06"
        p.birth_date = "2015-06-23 to 2015-07-12"
        assert approx_date_to_iso(p.birth_date) == "2015-06-23 to 2015-07-12"
        p.birth_date = datetime(2015, 6, 23)
        assert approx_date_to_iso(p.birth_date) == "2015-06-23"
예제 #3
0
def approx_date_getter(iso8601_date_string):
    #duplicated here until approx_date package updated
    if " to " in iso8601_date_string:  #extract double date
        start, end = iso8601_date_string.split(" to ")
        start_date = ApproxDate.from_iso8601(start)
        end_date = ApproxDate.from_iso8601(end)
        combined = ApproxDate(start_date.earliest_date, end_date.latest_date,
                              iso8601_date_string)
        return combined
    else:
        return ApproxDate.from_iso8601(iso8601_date_string)
예제 #4
0
 def test_start_end_no_source(self):
     d = ApproxDate(date(
         1900,
         1,
         1,
     ), date(1999, 12, 31))
     assert repr(
         d
     ) == 'ApproxDate(datetime.date(1900, 1, 1), datetime.date(1999, 12, 31))'
    def test_membership_returns_legislative_period_start_and_end(self):
        #return sepcific start date and generic end date
        with example_file(EXAMPLE_MEMBERSHIP_ALL_FIELDS) as fname:
            popolo = Popolo.from_filename(fname)
            m = popolo.memberships[0]
            print(m.effective_start_date)
            assert m.effective_start_date == ApproxDate.from_iso8601(
                '1784-03-01')
            assert m.effective_end_date == ApproxDate.from_iso8601(
                '1784-05-23')

        #check it returns the start date when we are missing a more specific entry
        with example_file(EXAMPLE_MEMBERSHIP_ALL_FIELDS_NO_DATES) as fname:
            popolo = Popolo.from_filename(fname)
            m = popolo.memberships[0]
            assert m.effective_start_date == ApproxDate.from_iso8601(
                '1783-12-19')
            assert m.effective_end_date == ApproxDate.from_iso8601(
                '1801-01-01')
예제 #6
0
 def test_abritrary_date_range(self):
     d = ApproxDate(date(1926, 1, 3), date(2016, 3, 8))
     assert text_type(d) == '1926-01-03 to 2016-03-08'
예제 #7
0
 def test_midpoint_for_missing_day(self):
     d = ApproxDate.from_iso8601('1999-12')
     assert d.midpoint_date == date(1999, 12, 16)
예제 #8
0
 def test_malformed_iso_8601_date(self):
     with pytest.raises(ValueError):
         ApproxDate.from_iso8601('next Tuesday-ish')
예제 #9
0
 def test_create_from_parial_iso_8601_only_year(self):
     d = ApproxDate.from_iso8601('1964')
     assert isinstance(d, ApproxDate)
     assert d.earliest_date == date(1964, 1, 1)
     assert d.latest_date == date(1964, 12, 31)
     assert text_type(d) == '1964'
예제 #10
0
 def test_datetime_date_between(self):
     d1 = date(2000, 1, 1)
     d2 = date(2005, 12, 31)
     assert ApproxDate.possibly_between(d1, date(2002, 7, 1), d2)
예제 #11
0
 def test_equality_false_to_different_precision(self):
     d1 = ApproxDate.from_iso8601('1964-06-26')
     d2 = ApproxDate.from_iso8601('1964-06')
     assert not (d1 == d2)
예제 #12
0
 def test_inequality_false_to_other_approxdate(self):
     d1 = ApproxDate.from_iso8601('1964-06-26')
     d2 = ApproxDate.from_iso8601('1964-06-26')
     assert not (d1 != d2)
예제 #13
0
 def month(self, month):
     approx_date = ApproxDate.from_iso8601(month)
     return self.filter(transaction__date__range=(
         approx_date.earliest_date,
         approx_date.latest_date))
예제 #14
0
 def test_start_end_source(self):
     d = ApproxDate.from_iso8601('2010-07')
     if six.PY2:
         assert repr(d) == "ApproxDate.from_iso8601(u'2010-07')"
     else:
         assert repr(d) == "ApproxDate.from_iso8601('2010-07')"
예제 #15
0
 def test_possibly_in_clearly_after(self):
     d1 = ApproxDate.from_iso8601('2000')
     d2 = ApproxDate.from_iso8601('2005')
     assert not ApproxDate.possibly_between(d1, date(2010, 12, 31), d2)
예제 #16
0
 def test_possibly_in_borderline_after(self):
     d1 = ApproxDate.from_iso8601('2000')
     d2 = ApproxDate.from_iso8601('2005')
     assert ApproxDate.possibly_between(d1, date(2005, 7, 1), d2)
예제 #17
0
 def test_inequality_true_to_different_precision(self):
     d1 = ApproxDate.from_iso8601('1964-06-26')
     d2 = ApproxDate.from_iso8601('1964-06')
     assert (d1 != d2)
예제 #18
0
 def test_datetime_date_after(self):
     d1 = date(2000, 1, 1)
     d2 = date(2005, 12, 31)
     assert not ApproxDate.possibly_between(d1, date(1980, 1, 1), d2)
예제 #19
0
 def test_equality_false_between_precise_and_different_date(self):
     approx_date = ApproxDate.from_iso8601('1964-06-26')
     datetime_date = date(1964, 6, 10)
     assert not (approx_date == datetime_date)
예제 #20
0
 def test_possibly_in_clearly_between(self):
     d1 = ApproxDate.from_iso8601('2000')
     d2 = ApproxDate.from_iso8601('2005')
     assert ApproxDate.possibly_between(d1, date(2002, 7, 1), d2)
예제 #21
0
 def test_equality_false_between_imprecise_and_date_out_of_range(self):
     approx_date = ApproxDate.from_iso8601('1999')
     datetime_date = date(1964, 6, 26)
     assert not (approx_date == datetime_date)
예제 #22
0
 def test_create_from_parial_iso_8601_only_year_and_month(self):
     d = ApproxDate.from_iso8601('1964-06')
     assert isinstance(d, ApproxDate)
     assert d.earliest_date == date(1964, 6, 1)
     assert d.latest_date == date(1964, 6, 30)
     assert text_type(d) == '1964-06'
예제 #23
0
 def test_equality_true_to_other_approxdate(self):
     d1 = ApproxDate.from_iso8601('1964-06-26')
     d2 = ApproxDate.from_iso8601('1964-06-26')
     assert d1 == d2
예제 #24
0
 def test_midpoint_for_precise_date(self):
     d = ApproxDate.from_iso8601('1977-12-27')
     assert d.midpoint_date == date(1977, 12, 27)
 def current_at(self, when):
     return ApproxDate.possibly_between(self.start_date, when,
                                        self.end_date)
예제 #26
0
 def test_midpoint_for_year(self):
     d = ApproxDate.from_iso8601('2016')
     assert d.midpoint_date == date(2016, 7, 1)
 def get_date(self, attr, default):
     d = self.data.get(attr)
     if d:
         return ApproxDate.from_iso8601(d)
     return default
예제 #28
0
 def test_create_from_full_iso_8601(self):
     d = ApproxDate.from_iso8601('1964-06-26')
     assert isinstance(d, ApproxDate)
     assert d.earliest_date == date(1964, 6, 26)
     assert d.latest_date == date(1964, 6, 26)
     assert text_type(d) == '1964-06-26'
예제 #29
0
 def test_possibly_in_clearly_before(self):
     d1 = ApproxDate.from_iso8601('2000')
     d2 = ApproxDate.from_iso8601('2005')
     assert not ApproxDate.possibly_between(d1, date(1980, 1, 1), d2)