示例#1
0
def pesel(input_file_path):
    root, ext = os.path.splitext(input_file_path)
    output_file_path = root + "-birthdays" + ext

    invalid_list = []

    with open(input_file_path, 'r') as input_file, open(output_file_path,
                                                        'w') as output_file:
        for line_number, pesel_line in enumerate(input_file, 1):
            pesel_line = pesel_line.rstrip()
            try:
                pesel = PESEL().from_string(pesel_line)
            except ValueError:
                invalid_list.append([line_number, pesel_line])
                continue

            processed_line = "{pesel} : {birthday}".format(
                **{
                    "pesel": pesel_line,
                    "birthday": pesel.to_date("%d-%m-%Y")
                })

            print(processed_line, file=output_file)

    retval = {
        "processed": line_number,
        "valid": line_number - len(invalid_list),
        "invalid": len(invalid_list),
        "invalid_list": invalid_list,
    }
    return retval
示例#2
0
 def test_20th_century_one_digit_month(self):
     p = PESEL().from_string("20022045678")
     self.assertEqual(p.to_date("%Y-%m-%d"), "1920-02-20" )
示例#3
0
 def test_lower_boundary_valid(self):
     self.assertTrue(PESEL().from_date(year=1800, month=1, day=1))
示例#4
0
 def test_leap_year_invalid(self):
     with self.assertRaises(ValueError):
         PESEL().from_date(year=2013, month=2, day=29)
示例#5
0
 def test_invalid_month_below(self):
     with self.assertRaises(ValueError):
         PESEL().from_date(year=2016, month=0, day=30)
示例#6
0
 def test_invalid_year_below(self):
     with self.assertRaises(ValueError):
         PESEL().from_date(year=1799, month=12, day=31)
示例#7
0
 def test_23rd_century(self):
     self.assertTrue(PESEL().from_string("16711012342"))
示例#8
0
 def test_21st_century(self):
     self.assertTrue(PESEL().from_string("16311012340"))
示例#9
0
 def test_23rd_century_one_digit_month(self):
     p = PESEL().from_string("00653011554")
     self.assertEqual(p.to_date("%Y-%m-%d"), "2200-05-30" )
示例#10
0
 def test_22nd_century_two_digit_month(self):
     p = PESEL().from_string("61513035794")
     self.assertEqual(p.to_date("%Y-%m-%d"), "2161-11-30" )
示例#11
0
 def test_space(self):
     with self.assertRaises(ValueError):
         PESEL().from_string("78a c859694")
示例#12
0
 def test_22nd_century_one_digit_month(self):
     p = PESEL().from_string("11443095179")
     self.assertEqual(p.to_date("%Y-%m-%d"), "2111-04-30" )
示例#13
0
 def test_21st_century_two_digit_month(self):
     p = PESEL().from_string("20323079310")
     self.assertEqual(p.to_date("%Y-%m-%d"), "2020-12-30" )
示例#14
0
 def test_21st_century_one_digit_month(self):
     p = PESEL().from_string("06233084266")
     self.assertEqual(p.to_date("%Y-%m-%d"), "2006-03-30" )
示例#15
0
 def test_20th_century_two_digit_month(self):
     p = PESEL().from_string("99123085265")
     self.assertEqual(p.to_date("%Y-%m-%d"), "1999-12-30" )
示例#16
0
 def test_19th_century(self):
     self.assertTrue(PESEL().from_string("16911012348"))
示例#17
0
 def test_20th_century(self):
     self.assertTrue(PESEL().from_string("16111012344"))
示例#18
0
 def test_23rd_century_two_digit_month(self):
     p = PESEL().from_string("99722984464")
     self.assertEqual(p.to_date("%Y-%m-%d"), "2299-12-29" )
示例#19
0
 def test_22nd_century(self):
     self.assertTrue(PESEL().from_string("16511012346"))
示例#20
0
 def test_special_char(self):
     with self.assertRaises(ValueError):
         PESEL().from_string("7-_=+*/<>82")
示例#21
0
 def test_short_string(self):
     with self.assertRaises(ValueError):
         PESEL().from_string("780524")
示例#22
0
 def test_zero_month(self):
     with self.assertRaises(ValueError):
         PESEL().from_string("49000501580")
示例#23
0
 def test_invalid_year_above(self):
     with self.assertRaises(ValueError):
         PESEL().from_date(year=2300, month=1, day=1)
示例#24
0
 def test_zero_day(self):
     with self.assertRaises(ValueError):
         PESEL().from_string("49040001580")
示例#25
0
 def test_invalid_day_above(self):
     with self.assertRaises(ValueError):
         PESEL().from_date(year=2016, month=11, day=32)
示例#26
0
 def test_invalid_month(self):
     with self.assertRaises(ValueError):
         PESEL().from_string("49140501580")
示例#27
0
 def test_leap_year_valid(self):
     self.assertTrue(PESEL().from_date(year=2012, month=2, day=29))
示例#28
0
 def test_invalid_day(self):
     with self.assertRaises(ValueError):
         PESEL().from_string("49043501580")
示例#29
0
 def test_upper_boundary_valid(self):
     self.assertTrue(PESEL().from_date(year=2299, month=12, day=31))
示例#30
0
 def test_invalid_control_number(self):
     with self.assertRaises(ValueError):
         PESEL().from_string("49040501587")