Exemple #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"
Exemple #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)
    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')
Exemple #5
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)
Exemple #6
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)
Exemple #7
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')"
Exemple #8
0
 def test_midpoint_for_year(self):
     d = ApproxDate.from_iso8601('2016')
     assert d.midpoint_date == date(2016, 7, 1)
Exemple #9
0
 def test_midpoint_for_precise_date(self):
     d = ApproxDate.from_iso8601('1977-12-27')
     assert d.midpoint_date == date(1977, 12, 27)
Exemple #10
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'
Exemple #11
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)
Exemple #12
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)
Exemple #13
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)
Exemple #14
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)
Exemple #15
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))
Exemple #16
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)
Exemple #17
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'
Exemple #18
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)
Exemple #19
0
 def test_malformed_iso_8601_date(self):
     with pytest.raises(ValueError):
         ApproxDate.from_iso8601('next Tuesday-ish')
Exemple #20
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
Exemple #21
0
 def test_midpoint_for_missing_day(self):
     d = ApproxDate.from_iso8601('1999-12')
     assert d.midpoint_date == date(1999, 12, 16)
 def get_date(self, attr, default):
     d = self.data.get(attr)
     if d:
         return ApproxDate.from_iso8601(d)
     return default
Exemple #23
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'
Exemple #24
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)