X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=tests%2Ftest_parse_changes.py;h=65c0666a5a49cf92c12f8077d56ff47d8480fcb2;hb=7c5adcf962fe99d6a42307595f263f47d0112fbc;hp=85a76948d193c5f4a8f4615eb71aa1fdc011236f;hpb=1242127976118dbf4c73a9132db3481d72906c86;p=dak.git diff --git a/tests/test_parse_changes.py b/tests/test_parse_changes.py index 85a76948..65c0666a 100755 --- a/tests/test_parse_changes.py +++ b/tests/test_parse_changes.py @@ -5,28 +5,19 @@ from base_test import DakTestCase, fixture import unittest from daklib.gpg import GpgException -from daklib.utils import parse_changes +from daklib.utils import parse_changes, check_dsc_files, build_file_list from daklib.dak_exceptions import InvalidDscError, ParseChangesError class ParseChangesTestCase(DakTestCase): def assertParse(self, filename, *args): return parse_changes(fixture(filename), *args) - def assertFails(self, filename, line=None, *args): - try: - self.assertParse(filename, *args) - self.fail('%s was not recognised as invalid' % filename) - except ParseChangesError: - pass - except GpgException: - pass - except InvalidDscError, actual_line: - if line is not None: - assertEqual(actual_line, line) - class ParseDscTestCase(ParseChangesTestCase): def test_1(self): - self.assertParse('dsc/1.dsc', -1, 1) + changes = self.assertParse('dsc/1.dsc', -1, 1) + files = build_file_list(changes, 1) + rejmsg = check_dsc_files('1.dsc', changes, files.keys()) + self.assertEqual(rejmsg, []) def test_1_ignoreErrors(self): # Valid .dsc ; ignoring errors @@ -46,7 +37,8 @@ class ParseDscTestCase(ParseChangesTestCase): def test_4(self): # No blank lines at all - self.assertFails('dsc/4.dsc', -1, 1) + with self.assertRaises(GpgException): + self.assertParse('dsc/4.dsc', -1, 1) def test_5(self): # Extra blank line before signature body @@ -56,10 +48,33 @@ class ParseDscTestCase(ParseChangesTestCase): # Extra blank line after signature header self.assertParse('dsc/6.dsc', -1, 1) + def test_7(self): + # Blank file is an invalid armored GPG file + with self.assertRaises(GpgException): + self.assertParse('dsc/7.dsc', -1, 1) + + def test_8(self): + # No armored contents + with self.assertRaisesRegexp(ParseChangesError, "Empty changes"): + self.assertParse('dsc/8.dsc', -1, 1) + + def test_9(self): + changes = self.assertParse('dsc/9.dsc', -1, 1) + self.assert_(changes['question'] == 'Is this a bug?') + self.failIf(changes.get('this')) + + def test_10(self): + changes = self.assertParse('dsc/10.dsc', -1, 1) + files = build_file_list(changes, 1) + rejmsg = check_dsc_files('10.dsc', changes, files.keys()) + self.assertEqual(rejmsg, ['10.dsc: contains source files not allowed in format 1.0']) + + class ParseChangesTestCase(ParseChangesTestCase): def test_1(self): # Empty changes - self.assertFails('changes/1.changes', 5, -1) + with self.assertRaises(GpgException): + self.assertParse('changes/1.changes', 1) def test_2(self): changes = self.assertParse('changes/2.changes', -1) @@ -77,10 +92,5 @@ class ParseChangesTestCase(ParseChangesTestCase): ) self.failIf(changes.get('you')) - def test_4(self): - changes = self.assertParse('changes/two-beginnings.changes', -1, 1) - self.assert_(changes['question'] == 'Is this a bug?') - self.failIf(changes.get('this')) - if __name__ == '__main__': unittest.main()