]> git.decadent.org.uk Git - dak.git/blob - dak/test/001/test.py
Add a 'fixture' utility to generate a path to a fixture.
[dak.git] / dak / test / 001 / test.py
1 #!/usr/bin/env python
2
3 # Check utils.parse_changes()'s .dsc file validation
4 # Copyright (C) 2000, 2006  James Troup <james@nocrew.org>
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20 ################################################################################
21
22 import os, sys
23
24 sys.path.append(os.path.abspath('../../'))
25
26 import utils
27
28 ################################################################################
29
30 def fail(message):
31     sys.stderr.write("%s\n" % (message))
32     sys.exit(1)
33
34 ################################################################################
35
36 def main ():
37     # Valid .dsc
38     utils.parse_changes('1.dsc',1)
39
40     # Missing blank line before signature body
41     try:
42         utils.parse_changes('2.dsc',1)
43     except utils.invalid_dsc_format_exc, line:
44         if line != 14:
45             fail("Incorrect line number ('%s') for test #2." % (line))
46     else:
47         fail("Test #2 wasn't recognised as invalid.")
48
49     # Missing blank line after signature header
50     try:
51         utils.parse_changes('3.dsc',1)
52     except utils.invalid_dsc_format_exc, line:
53         if line != 14:
54             fail("Incorrect line number ('%s') for test #3." % (line))
55     else:
56         fail("Test #3 wasn't recognised as invalid.")
57
58     # No blank lines at all
59     try:
60         utils.parse_changes('4.dsc',1)
61     except utils.invalid_dsc_format_exc, line:
62         if line != 19:
63             fail("Incorrect line number ('%s') for test #4." % (line))
64     else:
65         fail("Test #4 wasn't recognised as invalid.")
66
67     # Extra blank line before signature body
68     try:
69         utils.parse_changes('5.dsc',1)
70     except utils.invalid_dsc_format_exc, line:
71         if line != 15:
72             fail("Incorrect line number ('%s') for test #5." % (line))
73     else:
74         fail("Test #5 wasn't recognised as invalid.")
75
76     # Extra blank line after signature header
77     try:
78         utils.parse_changes('6.dsc',1)
79     except utils.invalid_dsc_format_exc, line:
80         if line != 5:
81             fail("Incorrect line number ('%s') for test #6." % (line))
82     else:
83         fail("Test #6 wasn't recognised as invalid.")
84
85     # Valid .dsc ; ignoring errors
86     utils.parse_changes('1.dsc', 0)
87
88     # Invalid .dsc ; ignoring errors
89     utils.parse_changes('2.dsc', 0)
90
91 ################################################################################
92
93 if __name__ == '__main__':
94     main()