From 47955ee9a5730c81b21ca9f31da4c176a82bcdc4 Mon Sep 17 00:00:00 2001 From: Chris Lamb Date: Sat, 31 Oct 2009 21:35:19 +0000 Subject: [PATCH] Port old tests to unittest; currently 18 failures. Signed-off-by: Chris Lamb --- dak/test/001/test.py | 94 ------------- dak/test/002/test.py | 49 ------- dak/test/003/test.py | 68 --------- dak/test/004/test.py | 122 ---------------- dak/test/005/test.py | 50 ------- dak/test/006/test.py | 130 ------------------ .../fixtures/changes/1.changes | 0 .../fixtures/changes/2.changes | 0 .../fixtures/changes}/bogus-post.changes | 0 .../fixtures/changes}/bogus-pre.changes | 0 .../fixtures/changes}/valid.changes | 0 {dak/test/001 => tests/fixtures/dsc}/1.dsc | 0 {dak/test/001 => tests/fixtures/dsc}/2.dsc | 0 {dak/test/001 => tests/fixtures/dsc}/3.dsc | 0 {dak/test/001 => tests/fixtures/dsc}/4.dsc | 0 {dak/test/001 => tests/fixtures/dsc}/5.dsc | 0 {dak/test/001 => tests/fixtures/dsc}/6.dsc | 0 tests/fixtures/dsc/7.dsc | 0 tests/test_extract_component_from_section.py | 59 ++++++++ tests/test_fix_maintainer.py | 105 ++++++++++++++ tests/test_parse_changes.py | 78 +++++++++++ 21 files changed, 242 insertions(+), 513 deletions(-) delete mode 100644 dak/test/001/test.py delete mode 100644 dak/test/002/test.py delete mode 100755 dak/test/003/test.py delete mode 100755 dak/test/004/test.py delete mode 100755 dak/test/005/test.py delete mode 100755 dak/test/006/test.py rename dak/test/002/empty.changes => tests/fixtures/changes/1.changes (100%) rename dak/test/003/krb5_1.2.2-4_m68k.changes => tests/fixtures/changes/2.changes (100%) rename {dak/test/005 => tests/fixtures/changes}/bogus-post.changes (100%) rename {dak/test/005 => tests/fixtures/changes}/bogus-pre.changes (100%) rename {dak/test/005 => tests/fixtures/changes}/valid.changes (100%) rename {dak/test/001 => tests/fixtures/dsc}/1.dsc (100%) rename {dak/test/001 => tests/fixtures/dsc}/2.dsc (100%) rename {dak/test/001 => tests/fixtures/dsc}/3.dsc (100%) rename {dak/test/001 => tests/fixtures/dsc}/4.dsc (100%) rename {dak/test/001 => tests/fixtures/dsc}/5.dsc (100%) rename {dak/test/001 => tests/fixtures/dsc}/6.dsc (100%) create mode 100644 tests/fixtures/dsc/7.dsc create mode 100755 tests/test_extract_component_from_section.py create mode 100755 tests/test_fix_maintainer.py create mode 100755 tests/test_parse_changes.py diff --git a/dak/test/001/test.py b/dak/test/001/test.py deleted file mode 100644 index 8238c20f..00000000 --- a/dak/test/001/test.py +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env python - -# Check utils.parse_changes()'s .dsc file validation -# Copyright (C) 2000, 2006 James Troup - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -################################################################################ - -import os, sys - -sys.path.append(os.path.abspath('../../')) - -import utils - -################################################################################ - -def fail(message): - sys.stderr.write("%s\n" % (message)) - sys.exit(1) - -################################################################################ - -def main (): - # Valid .dsc - utils.parse_changes('1.dsc',1) - - # Missing blank line before signature body - try: - utils.parse_changes('2.dsc',1) - except utils.invalid_dsc_format_exc, line: - if line != 14: - fail("Incorrect line number ('%s') for test #2." % (line)) - else: - fail("Test #2 wasn't recognised as invalid.") - - # Missing blank line after signature header - try: - utils.parse_changes('3.dsc',1) - except utils.invalid_dsc_format_exc, line: - if line != 14: - fail("Incorrect line number ('%s') for test #3." % (line)) - else: - fail("Test #3 wasn't recognised as invalid.") - - # No blank lines at all - try: - utils.parse_changes('4.dsc',1) - except utils.invalid_dsc_format_exc, line: - if line != 19: - fail("Incorrect line number ('%s') for test #4." % (line)) - else: - fail("Test #4 wasn't recognised as invalid.") - - # Extra blank line before signature body - try: - utils.parse_changes('5.dsc',1) - except utils.invalid_dsc_format_exc, line: - if line != 15: - fail("Incorrect line number ('%s') for test #5." % (line)) - else: - fail("Test #5 wasn't recognised as invalid.") - - # Extra blank line after signature header - try: - utils.parse_changes('6.dsc',1) - except utils.invalid_dsc_format_exc, line: - if line != 5: - fail("Incorrect line number ('%s') for test #6." % (line)) - else: - fail("Test #6 wasn't recognised as invalid.") - - # Valid .dsc ; ignoring errors - utils.parse_changes('1.dsc', 0) - - # Invalid .dsc ; ignoring errors - utils.parse_changes('2.dsc', 0) - -################################################################################ - -if __name__ == '__main__': - main() diff --git a/dak/test/002/test.py b/dak/test/002/test.py deleted file mode 100644 index 919a70ab..00000000 --- a/dak/test/002/test.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env python - -# Check utils.parse_changes()'s for handling empty files -# Copyright (C) 2000, 2006 James Troup - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -################################################################################ - -import os, sys - -sys.path.append(os.path.abspath('../../')) - -import utils - -################################################################################ - -def fail(message): - sys.stderr.write("%s\n" % (message)) - sys.exit(1) - -################################################################################ - -def main (): - # Empty .changes file; should raise a 'parse error' exception. - try: - utils.parse_changes('empty.changes', 0) - except utils.changes_parse_error_exc, line: - if line != "[Empty changes file]": - fail("Returned exception with unexcpected error message `%s'." % (line)) - else: - fail("Didn't raise a 'parse error' exception for a zero-length .changes file.") - -################################################################################ - -if __name__ == '__main__': - main() diff --git a/dak/test/003/test.py b/dak/test/003/test.py deleted file mode 100755 index ce07c118..00000000 --- a/dak/test/003/test.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env python - -# Check utils.parse_changes()'s for handling of multi-line fields -# Copyright (C) 2000, 2006 James Troup - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -################################################################################ - -# The deal here is that for the first 6 months of dak's -# implementation it has been misparsing multi-line fields in .changes -# files; specifically multi-line fields where there _is_ data on the -# first line. So, for example: - -# Foo: bar baz -# bat bant - -# Became "foo: bar bazbat bant" rather than "foo: bar baz\nbat bant" - -################################################################################ - -import os, sys - -sys.path.append(os.path.abspath('../../')) - -import utils - -################################################################################ - -def fail(message): - sys.stderr.write("%s\n" % (message)) - sys.exit(1) - -################################################################################ - -def main (): - # Valid .changes file with a multi-line Binary: field - try: - changes = utils.parse_changes('krb5_1.2.2-4_m68k.changes', 0) - except utils.changes_parse_error_exc, line: - fail("parse_changes() returned an exception with error message `%s'." % (line)) - - o = changes.get("binary", "") - if o != "": - del changes["binary"] - changes["binary"] = {} - for j in o.split(): - changes["binary"][j] = 1 - - if not changes["binary"].has_key("krb5-ftpd"): - fail("parse_changes() is broken; 'krb5-ftpd' is not in the Binary: dictionary.") - -################################################################################ - -if __name__ == '__main__': - main() diff --git a/dak/test/004/test.py b/dak/test/004/test.py deleted file mode 100755 index 4aa6b480..00000000 --- a/dak/test/004/test.py +++ /dev/null @@ -1,122 +0,0 @@ -#!/usr/bin/env python - -# Check utils.extract_component_from_section() -# Copyright (C) 2000, 2006 James Troup - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -################################################################################ - -import os, sys - -sys.path.append(os.path.abspath('../../')) - -import utils - -################################################################################ - -def fail(message): - sys.stderr.write("%s\n" % (message)) - sys.exit(1) - -################################################################################ - -# prefix: non-US -# component: main, contrib, non-free -# section: games, admin, libs, [...] - -# [1] Order is as above. -# [2] Prefix is optional for the default archive, but mandatory when -# uploads are going anywhere else. -# [3] Default component is main and may be omitted. -# [4] Section is optional. -# [5] Prefix is case insensitive -# [6] Everything else is case sensitive. - -def test(input, output): - result = utils.extract_component_from_section(input) - if result != output: - fail ("%s -> %r [should have been %r]" % (input, result, output)) - -def main (): - # Err, whoops? should probably be "utils", "main"... - input = "main/utils"; output = ("main/utils", "main") - test (input, output) - - - # Validate #3 - input = "utils"; output = ("utils", "main") - test (input, output) - - input = "non-free/libs"; output = ("non-free/libs", "non-free") - test (input, output) - - input = "contrib/net"; output = ("contrib/net", "contrib") - test (input, output) - - - # Validate #3 with a prefix - input = "non-US"; output = ("non-US", "non-US/main") - test (input, output) - - - # Validate #4 - input = "main"; output = ("main", "main") - test (input, output) - - input = "contrib"; output = ("contrib", "contrib") - test (input, output) - - input = "non-free"; output = ("non-free", "non-free") - test (input, output) - - - # Validate #4 with a prefix - input = "non-US/main"; output = ("non-US/main", "non-US/main") - test (input, output) - - input = "non-US/contrib"; output = ("non-US/contrib", "non-US/contrib") - test (input, output) - - input = "non-US/non-free"; output = ("non-US/non-free", "non-US/non-free") - test (input, output) - - - # Validate #5 - input = "non-us"; output = ("non-us", "non-US/main") - test (input, output) - - input = "non-us/contrib"; output = ("non-us/contrib", "non-US/contrib") - test (input, output) - - - # Validate #6 (section) - input = "utIls"; output = ("utIls", "main") - test (input, output) - - # Others.. - input = "non-US/libs"; output = ("non-US/libs", "non-US/main") - test (input, output) - input = "non-US/main/libs"; output = ("non-US/main/libs", "non-US/main") - test (input, output) - input = "non-US/contrib/libs"; output = ("non-US/contrib/libs", "non-US/contrib") - test (input, output) - input = "non-US/non-free/libs"; output = ("non-US/non-free/libs", "non-US/non-free") - test (input, output) - -################################################################################ - -if __name__ == '__main__': - main() diff --git a/dak/test/005/test.py b/dak/test/005/test.py deleted file mode 100755 index b5d3bbc7..00000000 --- a/dak/test/005/test.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env python - -# Check utils.parse_changes() correctly ignores data outside the signed area -# Copyright (C) 2004, 2006 James Troup - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -################################################################################ - -import os, sys - -sys.path.append(os.path.abspath('../../')) - -import utils - -################################################################################ - -def fail(message): - sys.stderr.write("%s\n" % (message)) - sys.exit(1) - -################################################################################ - -def main (): - for file in [ "valid", "bogus-pre", "bogus-post" ]: - for strict_whitespace in [ 0, 1 ]: - try: - changes = utils.parse_changes("%s.changes" % (file), strict_whitespace) - except utils.changes_parse_error_exc, line: - fail("%s[%s]: parse_changes() returned an exception with error message `%s'." % (file, strict_whitespace, line)) - oh_dear = changes.get("you") - if oh_dear: - fail("%s[%s]: parsed and accepted unsigned data!" % (file, strict_whitespace)) - -################################################################################ - -if __name__ == '__main__': - main() diff --git a/dak/test/006/test.py b/dak/test/006/test.py deleted file mode 100755 index 51a33170..00000000 --- a/dak/test/006/test.py +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# Test textutils.fix_maintainer() -# Copyright (C) 2004, 2006 James Troup - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -################################################################################ - -import os, sys - -sys.path.append(os.path.abspath('../../')) - -import textutils - -################################################################################ - -def fail(message): - sys.stderr.write("%s\n" % (message)) - sys.exit(1) - -################################################################################ - -def check_valid(s, xa, xb, xc, xd): - (a, b, c, d) = textutils.fix_maintainer(s) - if a != xa: - fail("rfc822_maint: %s (returned) != %s (expected [From: '%s']" % (a, xa, s)) - if b != xb: - fail("rfc2047_maint: %s (returned) != %s (expected [From: '%s']" % (b, xb, s)) - if c != xc: - fail("name: %s (returned) != %s (expected [From: '%s']" % (c, xc, s)) - if d != xd: - fail("email: %s (returned) != %s (expected [From: '%s']" % (d, xd, s)) - -def check_invalid(s): - try: - textutils.fix_maintainer(s) - fail("%s was parsed successfully but is expected to be invalid." % (s)) - except utils.ParseMaintError, unused: - pass - -def main (): - # Check Valid UTF-8 maintainer field - s = "Noèl Köthe " - xa = "Noèl Köthe " - xb = "=?utf-8?b?Tm/DqGwgS8O2dGhl?= " - xc = "Noèl Köthe" - xd = "noel@debian.org" - check_valid(s, xa, xb, xc, xd) - - # Check valid ISO-8859-1 maintainer field - s = "Noèl Köthe " - xa = "Noèl Köthe " - xb = "=?iso-8859-1?q?No=E8l_K=F6the?= " - xc = "Noèl Köthe" - xd = "noel@debian.org" - check_valid(s, xa, xb, xc, xd) - - # Check valid ASCII maintainer field - s = "James Troup " - xa = "James Troup " - xb = "James Troup " - xc = "James Troup" - xd = "james@nocrew.org" - check_valid(s, xa, xb, xc, xd) - - # Check "Debian vs RFC822" fixup of names with '.' or ',' in them - s = "James J. Troup " - xa = "james@nocrew.org (James J. Troup)" - xb = "james@nocrew.org (James J. Troup)" - xc = "James J. Troup" - xd = "james@nocrew.org" - check_valid(s, xa, xb, xc, xd) - s = "James J, Troup " - xa = "james@nocrew.org (James J, Troup)" - xb = "james@nocrew.org (James J, Troup)" - xc = "James J, Troup" - xd = "james@nocrew.org" - check_valid(s, xa, xb, xc, xd) - - # Check just-email form - s = "james@nocrew.org" - xa = " " - xb = " " - xc = "" - xd = "james@nocrew.org" - check_valid(s, xa, xb, xc, xd) - - # Check bracketed just-email form - s = "" - xa = " " - xb = " " - xc = "" - xd = "james@nocrew.org" - check_valid(s, xa, xb, xc, xd) - - # Check Krazy quoted-string local part email address - s = "Cris van Pelt <\"Cris van Pelt\"@tribe.eu.org>" - xa = "Cris van Pelt <\"Cris van Pelt\"@tribe.eu.org>" - xb = "Cris van Pelt <\"Cris van Pelt\"@tribe.eu.org>" - xc = "Cris van Pelt" - xd = "\"Cris van Pelt\"@tribe.eu.org" - check_valid(s, xa, xb, xc, xd) - - # Check empty string - s = xa = xb = xc = xd = "" - check_valid(s, xa, xb, xc, xd) - - # Check for missing email address - check_invalid("James Troup") - # Check for invalid email address - check_invalid("James Troup ", + "Noèl Köthe ", + "=?utf-8?b?Tm/DqGwgS8O2dGhl?= ", + "Noèl Köthe", + "noel@debian.org", + ) + + def testASCII(self): + # Check valid ASCII maintainer field + self.assertValid( + "James Troup ", + "James Troup ", + "James Troup ", + "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 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 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", + ) + + def testBracketedEmail(self): + # Check bracketed just-email form + self.assertValid( + "", + " ", + " ", + "", + "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