123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- from base_test import DakTestCase
- import unittest
- from daklib.textutils import fix_maintainer
- from daklib.dak_exceptions import ParseMaintError
- class FixMaintainerTestCase(DakTestCase):
- def assertValid(self, input, a, b, c, d):
- a_, b_, c_, d_ = fix_maintainer(input)
- self.assertEqual(a, a_)
- self.assertEqual(b, b_)
- self.assertEqual(c, c_)
- self.assertEqual(d, d_)
- def assertNotValid(self, input):
- self.assertRaises(ParseMaintError, lambda: fix_maintainer(input))
- def testUTF8Maintainer(self):
- # Check Valid UTF-8 maintainer field
- self.assertValid(
- "Noèl Köthe <noel@debian.org>",
- "Noèl Köthe <noel@debian.org>",
- "=?utf-8?b?Tm/DqGwgS8O2dGhl?= <noel@debian.org>",
- "Noèl Köthe",
- "noel@debian.org",
- )
- def testASCII(self):
- # Check valid ASCII maintainer field
- self.assertValid(
- "James Troup <james@nocrew.org>",
- "James Troup <james@nocrew.org>",
- "James Troup <james@nocrew.org>",
- "James Troup",
- "james@nocrew.org",
- )
- def testRFC822(self):
- # Check "Debian vs RFC822" fixup of names with '.' or ',' in them
- self.assertValid(
- "James J. Troup <james@nocrew.org>",
- "james@nocrew.org (James J. Troup)",
- "james@nocrew.org (James J. Troup)",
- "James J. Troup",
- "james@nocrew.org",
- )
- def testSimple(self):
- self.assertValid(
- "James J, Troup <james@nocrew.org>",
- "james@nocrew.org (James J, Troup)",
- "james@nocrew.org (James J, Troup)",
- "James J, Troup",
- "james@nocrew.org",
- )
- def testJustEmail(self):
- # Check just-email form
- self.assertValid(
- "james@nocrew.org",
- " <james@nocrew.org>",
- " <james@nocrew.org>",
- "",
- "james@nocrew.org",
- )
- def testBracketedEmail(self):
- # Check bracketed just-email form
- self.assertValid(
- "<james@nocrew.org>",
- " <james@nocrew.org>",
- " <james@nocrew.org>",
- "",
- "james@nocrew.org",
- )
- def testKrazy(self):
- # Check Krazy quoted-string local part email address
- self.assertValid(
- "Cris van Pelt <\"Cris van Pelt\"@tribe.eu.org>",
- "Cris van Pelt <\"Cris van Pelt\"@tribe.eu.org>",
- "Cris van Pelt <\"Cris van Pelt\"@tribe.eu.org>",
- "Cris van Pelt",
- "\"Cris van Pelt\"@tribe.eu.org",
- )
- def testEmptyString(self):
- # Check empty string
- self.assertValid("", "", "", "", "")
- def testMissingEmailAddress(self):
- # Check for missing email address
- self.assertNotValid("James Troup")
- def testInvalidEmail(self):
- # Check for invalid email address
- self.assertNotValid("James Troup <james@nocrew.org")
- if __name__ == '__main__':
- unittest.main()
|