def parse(cls, title, gfyear=None, **kwargs): root, period = tk.parse(title, _get_gfyear(gfyear)) letter = '(?:[A-Z]|Æ|Ø|Å|AE|OE|AA)' title_patterns = [ ('BEST', '^(?:CERM|FORM|INKA|KASS|NF|PR|SEKR|VC)$'), ('FU', '^FU%s%s$' % (letter, letter)), ('EFU', '^EFU%s%s$' % (letter, letter)), ] for kind, p in title_patterns: if re.match(p, root): return cls(period=period, root=root, kind=kind, **kwargs) raise ValueError(title)
def test_prefix_bestfuslash(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('BBEST/FU'), ('BESTFU', 2011))
def test_postfix_bestfu(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('BESTFU16'), ('BESTFU', 2016))
def test_postfix_leadingspace_space(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse(' FORM 1617'), ('FORM', 2016))
def test_context(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('FORM'), ('FORM', 2013))
def test_FUAEU_absolute_later(self): with tk.set_gfyear(2023): self.assertEqual(tk.parse('FUAEU21'), ('FUÄU', 2021))
def test_AAE(self): with tk.set_gfyear(2013): with self.assertRaisesRegex( ValueError, "FUAAE is an ambiguous alias. Cannot " "normalize."): tk.parse('FUAAE11')
def test_OE_3(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('FUOEH11'), ('FUØH', 2011))
def test_postfix_long(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('FORM2016'), ('FORM', 2016))
def test_postfix_double(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('FORM1617'), ('FORM', 2016))
def test_prefix_unicode_combined_2(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('T2OK³FORM'), ('FORM', 2011))
def test_prefix_unicode_plus_3(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('K³FORM'), ('FORM', 2016))
def test_prefix_plus_1(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('KFORM'), ('FORM', 2014))
def test_prefix_unicode_minus_35(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('T³²OFORM'), ('FORM', 1978))
def test_prefix_minus_5(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('T2OFORM'), ('FORM', 2008))
def test_AE_1(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('FUAE11'), ('FUAE', 2011))
def test_OE_2(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('FUHOE11'), ('FUHØ', 2011))
def test_postfix_reallylongslash(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('FORM2016/2017'), ('FORM', 2016))
def test_AAAA(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('FUAAAA11'), ('FUÅÅ', 2011))
def test_postfix_2021_slash(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('FORM20/21'), ('FORM', 2020))
def test_FUAEU_relative_next_year(self): with tk.set_gfyear(2022): self.assertEqual(tk.parse('GFUAEU'), ('FUÄU', 2021))
def test_postfix_longslash_space(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('FORM 2016/17'), ('FORM', 2016))
def test_prefix_leadingspace(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse(' T2OFORM'), ('FORM', 2008))
def test_arg(self): self.assertEqual(tk.parse('FORM', 2016), ('FORM', 2016))