def test_encode_birthdate_invalid_arguments(self): with self.assertRaises(ValueError): codicefiscale.encode_birthdate(None, 'M') with self.assertRaises(ValueError): codicefiscale.encode_birthdate('03/04/1985', None) with self.assertRaises(ValueError): codicefiscale.encode_birthdate('03/04/1985', 'X') with self.assertRaises(ValueError): codicefiscale.encode_birthdate('1985/1985/1985', 'M')
def test_encode_birthdate_sex(self): data = [ { 'input': ['03/04/1985', 'M'], 'result': '85D03', }, { 'input': ['03/04/1985', 'F'], 'result': '85D43', }, ] for obj in data: # with self.subTest(obj=obj): self.assertEqual(codicefiscale.encode_birthdate(*obj['input']), obj['result'])
def test_encode_birthdate_formats(self): data = [ { 'input': datetime(1985, 4, 3), 'result': '85D03', }, { 'input': '03 04 1985', 'result': '85D03', }, { 'input': '03/04/1985', 'result': '85D03', }, { 'input': '03-04-1985', 'result': '85D03', }, { 'input': '03.04.1985', 'result': '85D03', }, { 'input': '3/4/1985', 'result': '85D03', }, { 'input': '3-4-1985', 'result': '85D03', }, { 'input': '3.4.1985', 'result': '85D03', }, { 'input': '1985 04 03', 'result': '85D03', }, { 'input': '1985/04/03', 'result': '85D03', }, { 'input': '1985-04-03', 'result': '85D03', }, { 'input': '1985.04.03', 'result': '85D03', }, { 'input': '1985/4/3', 'result': '85D03', }, { 'input': '1985-4-3', 'result': '85D03', }, { 'input': '1985.4.3', 'result': '85D03', }, ] for obj in data: # with self.subTest(obj=obj): self.assertEqual(codicefiscale.encode_birthdate(obj['input'], 'M'), obj['result'])