Beispiel #1
0
def _expand(generation: int):
    multiplier = abs(generation) + 1 if generation < 0 else 1
    threshold_year = datetime.now().year - 100 * multiplier
    date_under_threshold = Date(threshold_year + 1, 1, 1)
    date_over_threshold = Date(threshold_year - 1, 1, 1)
    return parameterized.expand([
        # If there are no events for a person, their privacy does not change.
        (True, None, None),
        (True, True, None),
        (False, False, None),
        # Deaths are special, and their existence prevents generation 0 from being private even without a date.
        (generation != 0, None, Event('E0', Event.Type.DEATH)),
        (True, True, Event('E0', Event.Type.DEATH)),
        (False, False, Event('E0', Event.Type.DEATH)),
        # Regular events without dates do not affect privacy.
        (True, None, Event('E0', Event.Type.BIRTH)),
        (True, True, Event('E0', Event.Type.BIRTH)),
        (False, False, Event('E0', Event.Type.BIRTH)),
        # Regular events with incomplete dates do not affect privacy.
        (True, None, Event('E0', Event.Type.BIRTH, date=Date())),
        (True, True, Event('E0', Event.Type.BIRTH, date=Date())),
        (False, False, Event('E0', Event.Type.BIRTH, date=Date())),
        # Regular events under the lifetime threshold do not affect privacy.
        (True, None, Event('E0', Event.Type.BIRTH, date=date_under_threshold)),
        (True, True, Event('E0', Event.Type.BIRTH, date=date_under_threshold)),
        (False, False, Event('E0', Event.Type.BIRTH,
                             date=date_under_threshold)),
        # Regular events over the lifetime threshold affect privacy.
        (False, None, Event('E0', Event.Type.BIRTH, date=date_over_threshold)),
        (True, True, Event('E0', Event.Type.BIRTH, date=date_over_threshold)),
        (False, False, Event('E0', Event.Type.BIRTH,
                             date=date_over_threshold)),
    ])
Beispiel #2
0
def _parse_date(element: Element) -> Optional[Date]:
    dateval = str(_xpath1(element, './ns:dateval/@val'))
    if _DATE_PATTERN.fullmatch(dateval):
        date_parts = [
            int(part) if _DATE_PART_PATTERN.fullmatch(part) else None
            for part in dateval.split('-')
        ]
        return Date(*date_parts)
    return None
Beispiel #3
0
 def test_gt_should_raise_typeerror_for_missing_parts(self, date):
     # This tests __lt__ and @total_ordering, by invoking the generated __gt__ implementation.
     with self.assertRaises(TypeError):
         date > Date(1970, 1, 1)
Beispiel #4
0
 def test_gt(self, expected, year, month, day):
     # This tests __lt__ and @total_ordering, by invoking the generated __gt__ implementation.
     sut = Date(year, month, day)
     self.assertEquals(expected, sut > Date(1970, 1, 1))
Beispiel #5
0
 def test_eq(self, expected, date):
     self.assertEquals(expected, date == Date(1970, 1, 1))
Beispiel #6
0
 def test_parts(self, year, month, day):
     self.assertEquals((year, month, day), Date(year, month, day).parts)
Beispiel #7
0
 def test_complete(self, expected, year, month, day):
     sut = Date(year, month, day)
     self.assertEquals(expected, sut.complete)
Beispiel #8
0
 def test_day(self):
     day = 1
     sut = Date(day=day)
     self.assertEquals(day, sut.day)
Beispiel #9
0
 def test_month(self):
     month = 1
     sut = Date(month=month)
     self.assertEquals(month, sut.month)
Beispiel #10
0
 def test_year(self):
     year = 1970
     sut = Date(year=year)
     self.assertEquals(year, sut.year)
Beispiel #11
0
class DateTest(TestCase):
    def test_year(self):
        year = 1970
        sut = Date(year=year)
        self.assertEquals(year, sut.year)

    def test_month(self):
        month = 1
        sut = Date(month=month)
        self.assertEquals(month, sut.month)

    def test_day(self):
        day = 1
        sut = Date(day=day)
        self.assertEquals(day, sut.day)

    @parameterized.expand([
        (True, 1970, 1, 1),
        (False, None, 1, 1),
        (False, 1970, None, 1),
        (False, 1970, 1, None),
        (False, None, None, 1),
        (False, 1970, None, None),
        (False, None, None, None),
    ])
    def test_complete(self, expected, year, month, day):
        sut = Date(year, month, day)
        self.assertEquals(expected, sut.complete)

    @parameterized.expand([
        (1970, 1, 1),
        (None, None, None),
    ])
    def test_parts(self, year, month, day):
        self.assertEquals((year, month, day), Date(year, month, day).parts)

    @parameterized.expand([
        (True, Date(1970, 1, 1)),
        (False, Date(1970, 1, None)),
        (False, Date(1970, None, 1)),
        (False, Date(None, 1, 1)),
        (False, Date(1970, None, None)),
        (False, Date(None, 1, None)),
        (False, Date(None, None, 1)),
        (False, None),
    ])
    def test_eq(self, expected, date):
        self.assertEquals(expected, date == Date(1970, 1, 1))

    @parameterized.expand([
        (True, 1970, 1, 2),
        (True, 1970, 2, 1),
        (True, 1971, 1, 1),
        (False, 1970, 1, 1),
        (False, 1970, 1, 1),
        (False, 1969, 1, 1),
        (False, 1969, 12, 12),
    ])
    def test_gt(self, expected, year, month, day):
        # This tests __lt__ and @total_ordering, by invoking the generated __gt__ implementation.
        sut = Date(year, month, day)
        self.assertEquals(expected, sut > Date(1970, 1, 1))

    @parameterized.expand([
        (Date(1970, 1, None), ),
        (Date(1970, None, 1), ),
        (Date(None, 1, 1), ),
        (Date(1970, None, None), ),
        (Date(None, 1, None), ),
        (Date(None, None, 1), ),
        (Date(None, None, None), ),
        (None, ),
    ])
    def test_gt_should_raise_typeerror_for_missing_parts(self, date):
        # This tests __lt__ and @total_ordering, by invoking the generated __gt__ implementation.
        with self.assertRaises(TypeError):
            date > Date(1970, 1, 1)