def test_extra_year(self): with self.assertRaises(ValueError) as context: sort_copyrights([ "Copyright © 2015, 2016, 2018 John Doe <foo@bar>", "Copyright © 2016 John Doe <foo@bar>", "Copyright © 2016, 2017, 2019 John Doe <foo@bar>" ]) self.assertIn('First copyright found for <foo@bar> is missing years {2017, 2019}', context.exception.args[0])
def test_extra_year2(self): with self.assertRaises(ValueError) as context: sort_copyrights([ "Copyright © 2016 John Doe <foo@bar>", # After this entry the set needs to get updated, otherwise # 2018 will get lost "Copyright © 2016, 2018 John Doe <foo@bar>", "Copyright © 2016, 2020 John Doe <foo@bar>" ]) self.assertIn( 'First copyright found for <foo@bar> is missing years {2020}', context.exception.args[0])
def test_pick_longer(self): self.assertEqual(sort_copyrights([ "Copyright © 2015 John Doe <foo@bar>", "Copyright © 2015, 2016, 2018 John Doe <foo@bar>" ]), [ "Copyright © 2015, 2016, 2018 John Doe <foo@bar>" ])
def test_pick_earlier(self): self.assertEqual(sort_copyrights([ "Copyright © 2015, 2016, 2018 John Doe <foo@bar>", "Copyright © 2018 John Doe <foo@bar>", "Copyright © 1997, 2003 Boo Bee <bar@bar>", "Copyright © 2016 John Doe <foo@bar>" ]), [ "Copyright © 1997, 2003 Boo Bee <bar@bar>", "Copyright © 2015, 2016, 2018 John Doe <foo@bar>" ])
def test_sort(self): self.assertEqual(sort_copyrights([ "Copyright © 2015, 2016 John Doe <foo@bar>", "Copyright © 1997, 2003 Boo Bee <bar@bar>", "Copyright © 2018 Ho <hu@he>" ]), [ "Copyright © 1997, 2003 Boo Bee <bar@bar>", "Copyright © 2015, 2016 John Doe <foo@bar>", "Copyright © 2018 Ho <hu@he>" ])