def test_stringification(self): self.assertEqual(str(ApproximateDate(future=True)), 'future') self.assertEqual(str(ApproximateDate(past=True)), 'past') self.assertEqual(repr(ApproximateDate(future=True)), 'future') self.assertEqual(repr(ApproximateDate(past=True)), 'past')
def test_compare(self): y_past = ApproximateDate(year=2000) y_future = ApproximateDate(year=2100) future = ApproximateDate(future=True) # check that we can be compared to None, '' and u'' for bad_val in ('', u'', None): self.assertFalse(y_past in (bad_val, )) self.assertFalse(y_past == bad_val) self.assertTrue(y_past != bad_val) # sanity check self.assertTrue(y_past == y_past) self.assertTrue(y_future == y_future) self.assertFalse(y_past != y_past) self.assertFalse(y_future != y_future) self.assertTrue(y_past != y_future) self.assertTrue(y_future != y_past) self.assertTrue(y_future > y_past) self.assertTrue(y_future >= y_past) self.assertFalse(y_past > y_future) self.assertFalse(y_past >= y_future) self.assertTrue(y_past < y_future) self.assertTrue(y_past <= y_future) self.assertFalse(y_future < y_past) self.assertFalse(y_future <= y_past) # Future dates are always greater self.assertTrue(y_past < future) self.assertTrue(y_past <= future) self.assertTrue(y_future < future) self.assertTrue(y_future <= future) self.assertTrue(future > y_past) self.assertTrue(future >= y_past) self.assertTrue(future > y_future) self.assertTrue(future >= y_future) # Future dates are equal to themselves (so that sorting is sane) self.assertFalse(future < future) self.assertTrue(future <= future) self.assertTrue(future == future) self.assertTrue(future >= future) self.assertFalse(future > future)
def add_parts(str, cast): people = re.findall('<tr>\s*<td class="UnderviewKey">\s* </td>\s*<td class="UnderviewEntry">\s*(.*?)\s*</td>\s*<td class="UnderviewEntry">\s*(.*?)\s*</td>\s*<td class="AuthorityLink">', str) for person in people: name, role = person if not name and not role: continue first_name, last_name, dob_year = get_name(name) person, created = Person.objects.get_or_create(first_name=first_name, last_name=last_name) if dob_year: person.dob = ApproximateDate(int(dob_year)) person.save() part = Part.objects.get_or_create(production=production, person=person, role=role.decode('iso-8859-1'), cast=cast)
for match in matches: data[match[0]] = match[1] if not data['Title']: raise Exception, 'Missing Title' if not data['PerfCode']: raise Exception, 'Missing production code' title = data['Title'].decode('iso-8859-1').replace('&', '&') title = re.sub('^(A|An|The) (.*)$', r'\2, \1', title) playwrights = re.findall('<td class="UnderviewEntry">\s*(.*?)\s*</td>\s*<td class="UnderviewEntry">Writer</td>', r) authors = [] for p in playwrights: first_name, last_name, dob_year = get_name(p) person, created = Person.objects.get_or_create(first_name=first_name, last_name=last_name) if dob_year: person.dob = ApproximateDate(int(dob_year)) person.save() authors.append(person) if len(authors)>1: play = Play(title=title) play.save() for author in authors: play.authors.add(author) elif len(authors)==1: person = authors[0] try: play = Play.objects.get(title=title, authors=person) except: try: play = Play.objects.get(title=title, authors=None)
def test_length(self): for kwargs, length in self.known_lengths: approx = ApproximateDate(**kwargs) self.assertEqual(len(approx), length)