def get_titles(self, profile): titles = list(profile.title_set.all()) if titles: with tk.set_gfyear(config.GFYEAR): return ', '.join( sorted( tk.prepostfix(t, prefixtype="unicode") for t in titles))
def __init__(self, **kwargs): profiles = kwargs.pop('profiles') try: period = kwargs.pop('period') except KeyError: period = config.GFYEAR super().__init__(**kwargs) with tk.set_gfyear(period): self._init(profiles)
def test_called_once(self): calls = 0 def get_value(): nonlocal calls calls += 1 return 2013 o = tk.set_gfyear(get_value) self.assertEqual(calls, 0) with o: self.assertEqual(calls, 1) self.assertEqual(tk.get_gfyear(), 2013) self.assertEqual(calls, 1) self.assertEqual(tk.get_gfyear(), 2013) self.assertEqual(calls, 1)
def test_postfix_leadingspace_space(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse(' FORM 1617'), ('FORM', 2016))
def test_kprefix(self): with tk.set_gfyear(2015): self.assertEqual(tk.kprefix(('CERM', 2014)), 'KBCERM')
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_FUAEU_absolute_later(self): with tk.set_gfyear(2023): self.assertEqual(tk.parse('FUAEU21'), ('FUÄU', 2021))
def test_AE_1(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('FUAE11'), ('FUAE', 2011))
def test_OE_3(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('FUOEH11'), ('FUØH', 2011))
def test_prefix_unicode_plus_3(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('K³FORM'), ('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_minus_35(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('T³²OFORM'), ('FORM', 1978))
def test_prefix_plus_1(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('KFORM'), ('FORM', 2014))
def test_prefix_minus_5(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('T2OFORM'), ('FORM', 2008))
def test_context(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('FORM'), ('FORM', 2013))
def test_postfix(self): with tk.set_gfyear(2015): self.assertEqual(tk.postfix(('CERM', 2014)), 'CERM14')
def test_postfix_bestfu(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('BESTFU16'), ('BESTFU', 2016))
def test_postfix_double(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('FORM1617'), ('FORM', 2016))
def test_prefix_bestfuslash(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('BBEST/FU'), ('BESTFU', 2011))
def test_postfix_long(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('FORM2016'), ('FORM', 2016))
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_context_manager(self): with tk.set_gfyear(2012): self.assertEqual(tk.get_gfyear(), 2012)
def test_lambda(self): with tk.set_gfyear(lambda: 2013): self.assertEqual(tk.get_gfyear(), 2013)
def test_prefix_leadingspace(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse(' T2OFORM'), ('FORM', 2008))
def test_postfix_longslash_space(self): with tk.set_gfyear(2013): self.assertEqual(tk.parse('FORM 2016/17'), ('FORM', 2016))
def test_reentrant(self): with tk.set_gfyear(2011): self.assertEqual(tk.get_gfyear(), 2011) with tk.set_gfyear(2012): self.assertEqual(tk.get_gfyear(), 2012) self.assertEqual(tk.get_gfyear(), 2011)