Lars Gustäbel | 96753b3 | 2000-09-24 12:24:24 +0000 | [diff] [blame] | 1 | |
| 2 | # regression test for SAX 2.0 |
| 3 | # $Id$ |
| 4 | |
Martin v. Löwis | 962c9e7 | 2000-10-06 17:41:52 +0000 | [diff] [blame] | 5 | from xml.sax import make_parser, ContentHandler |
| 6 | try: |
| 7 | make_parser() |
| 8 | except xml.sax.SAXReaderNotAvailable: |
| 9 | # don't try to test this module if we cannot create a parser |
| 10 | raise ImportError("no XML parsers available") |
Lars Gustäbel | 96753b3 | 2000-09-24 12:24:24 +0000 | [diff] [blame] | 11 | from xml.sax.saxutils import XMLGenerator, escape, XMLFilterBase |
| 12 | from xml.sax.expatreader import create_parser |
Lars Gustäbel | b7536d5 | 2000-09-24 18:53:56 +0000 | [diff] [blame] | 13 | from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl |
Lars Gustäbel | 96753b3 | 2000-09-24 12:24:24 +0000 | [diff] [blame] | 14 | from cStringIO import StringIO |
Martin v. Löwis | 33315b1 | 2000-09-24 20:30:24 +0000 | [diff] [blame] | 15 | from test_support import verbose, TestFailed, findfile |
Lars Gustäbel | 96753b3 | 2000-09-24 12:24:24 +0000 | [diff] [blame] | 16 | |
| 17 | # ===== Utilities |
| 18 | |
| 19 | tests = 0 |
| 20 | fails = 0 |
| 21 | |
| 22 | def confirm(outcome, name): |
| 23 | global tests, fails |
| 24 | |
| 25 | tests = tests + 1 |
| 26 | if outcome: |
| 27 | print "Passed", name |
| 28 | else: |
| 29 | print "Failed", name |
| 30 | fails = fails + 1 |
| 31 | |
| 32 | # =========================================================================== |
| 33 | # |
| 34 | # saxutils tests |
| 35 | # |
| 36 | # =========================================================================== |
| 37 | |
| 38 | # ===== escape |
| 39 | |
| 40 | def test_escape_basic(): |
| 41 | return escape("Donald Duck & Co") == "Donald Duck & Co" |
| 42 | |
| 43 | def test_escape_all(): |
| 44 | return escape("<Donald Duck & Co>") == "<Donald Duck & Co>" |
| 45 | |
| 46 | def test_escape_extra(): |
| 47 | return escape("Hei på deg", {"å" : "å"}) == "Hei på deg" |
| 48 | |
Martin v. Löwis | 962c9e7 | 2000-10-06 17:41:52 +0000 | [diff] [blame] | 49 | def test_make_parser(): |
| 50 | try: |
| 51 | # Creating a parser should succeed - it should fall back |
| 52 | # to the expatreader |
| 53 | p = make_parser(['xml.parsers.no_such_parser']) |
| 54 | except: |
| 55 | return 0 |
| 56 | else: |
| 57 | return p |
| 58 | |
| 59 | |
Lars Gustäbel | 96753b3 | 2000-09-24 12:24:24 +0000 | [diff] [blame] | 60 | # ===== XMLGenerator |
| 61 | |
| 62 | start = '<?xml version="1.0" encoding="iso-8859-1"?>\n' |
| 63 | |
| 64 | def test_xmlgen_basic(): |
| 65 | result = StringIO() |
| 66 | gen = XMLGenerator(result) |
| 67 | gen.startDocument() |
| 68 | gen.startElement("doc", {}) |
| 69 | gen.endElement("doc") |
| 70 | gen.endDocument() |
| 71 | |
| 72 | return result.getvalue() == start + "<doc></doc>" |
| 73 | |
| 74 | def test_xmlgen_content(): |
| 75 | result = StringIO() |
| 76 | gen = XMLGenerator(result) |
| 77 | |
| 78 | gen.startDocument() |
| 79 | gen.startElement("doc", {}) |
| 80 | gen.characters("huhei") |
| 81 | gen.endElement("doc") |
| 82 | gen.endDocument() |
| 83 | |
| 84 | return result.getvalue() == start + "<doc>huhei</doc>" |
| 85 | |
| 86 | def test_xmlgen_pi(): |
| 87 | result = StringIO() |
| 88 | gen = XMLGenerator(result) |
| 89 | |
| 90 | gen.startDocument() |
| 91 | gen.processingInstruction("test", "data") |
| 92 | gen.startElement("doc", {}) |
| 93 | gen.endElement("doc") |
| 94 | gen.endDocument() |
| 95 | |
| 96 | return result.getvalue() == start + "<?test data?><doc></doc>" |
| 97 | |
| 98 | def test_xmlgen_content_escape(): |
| 99 | result = StringIO() |
| 100 | gen = XMLGenerator(result) |
| 101 | |
| 102 | gen.startDocument() |
| 103 | gen.startElement("doc", {}) |
| 104 | gen.characters("<huhei&") |
| 105 | gen.endElement("doc") |
| 106 | gen.endDocument() |
| 107 | |
| 108 | return result.getvalue() == start + "<doc><huhei&</doc>" |
| 109 | |
| 110 | def test_xmlgen_ignorable(): |
| 111 | result = StringIO() |
| 112 | gen = XMLGenerator(result) |
| 113 | |
| 114 | gen.startDocument() |
| 115 | gen.startElement("doc", {}) |
| 116 | gen.ignorableWhitespace(" ") |
| 117 | gen.endElement("doc") |
| 118 | gen.endDocument() |
| 119 | |
| 120 | return result.getvalue() == start + "<doc> </doc>" |
| 121 | |
| 122 | ns_uri = "http://www.python.org/xml-ns/saxtest/" |
| 123 | |
| 124 | def test_xmlgen_ns(): |
| 125 | result = StringIO() |
| 126 | gen = XMLGenerator(result) |
| 127 | |
| 128 | gen.startDocument() |
| 129 | gen.startPrefixMapping("ns1", ns_uri) |
Lars Gustäbel | 6a7768a | 2000-09-27 08:12:17 +0000 | [diff] [blame] | 130 | gen.startElementNS((ns_uri, "doc"), "ns1:doc", {}) |
Martin v. Löwis | cf0a1cc | 2000-10-03 22:35:29 +0000 | [diff] [blame] | 131 | # add an unqualified name |
| 132 | gen.startElementNS((None, "udoc"), None, {}) |
| 133 | gen.endElementNS((None, "udoc"), None) |
Lars Gustäbel | 6a7768a | 2000-09-27 08:12:17 +0000 | [diff] [blame] | 134 | gen.endElementNS((ns_uri, "doc"), "ns1:doc") |
Lars Gustäbel | 96753b3 | 2000-09-24 12:24:24 +0000 | [diff] [blame] | 135 | gen.endPrefixMapping("ns1") |
| 136 | gen.endDocument() |
| 137 | |
Martin v. Löwis | cf0a1cc | 2000-10-03 22:35:29 +0000 | [diff] [blame] | 138 | return result.getvalue() == start + \ |
| 139 | ('<ns1:doc xmlns:ns1="%s"><udoc></udoc></ns1:doc>' % |
Lars Gustäbel | 96753b3 | 2000-09-24 12:24:24 +0000 | [diff] [blame] | 140 | ns_uri) |
| 141 | |
| 142 | # ===== XMLFilterBase |
| 143 | |
| 144 | def test_filter_basic(): |
| 145 | result = StringIO() |
| 146 | gen = XMLGenerator(result) |
| 147 | filter = XMLFilterBase() |
| 148 | filter.setContentHandler(gen) |
| 149 | |
| 150 | filter.startDocument() |
| 151 | filter.startElement("doc", {}) |
| 152 | filter.characters("content") |
| 153 | filter.ignorableWhitespace(" ") |
| 154 | filter.endElement("doc") |
| 155 | filter.endDocument() |
| 156 | |
| 157 | return result.getvalue() == start + "<doc>content </doc>" |
| 158 | |
| 159 | # =========================================================================== |
| 160 | # |
| 161 | # expatreader tests |
| 162 | # |
| 163 | # =========================================================================== |
| 164 | |
| 165 | # ===== DTDHandler support |
| 166 | |
| 167 | class TestDTDHandler: |
| 168 | |
| 169 | def __init__(self): |
| 170 | self._notations = [] |
| 171 | self._entities = [] |
| 172 | |
| 173 | def notationDecl(self, name, publicId, systemId): |
| 174 | self._notations.append((name, publicId, systemId)) |
| 175 | |
| 176 | def unparsedEntityDecl(self, name, publicId, systemId, ndata): |
| 177 | self._entities.append((name, publicId, systemId, ndata)) |
| 178 | |
Lars Gustäbel | e292a24 | 2000-09-24 20:19:45 +0000 | [diff] [blame] | 179 | def test_expat_dtdhandler(): |
| 180 | parser = create_parser() |
| 181 | handler = TestDTDHandler() |
| 182 | parser.setDTDHandler(handler) |
Lars Gustäbel | 96753b3 | 2000-09-24 12:24:24 +0000 | [diff] [blame] | 183 | |
Lars Gustäbel | e292a24 | 2000-09-24 20:19:45 +0000 | [diff] [blame] | 184 | parser.feed('<!DOCTYPE doc [\n') |
| 185 | parser.feed(' <!ENTITY img SYSTEM "expat.gif" NDATA GIF>\n') |
| 186 | parser.feed(' <!NOTATION GIF PUBLIC "-//CompuServe//NOTATION Graphics Interchange Format 89a//EN">\n') |
| 187 | parser.feed(']>\n') |
| 188 | parser.feed('<doc></doc>') |
| 189 | parser.close() |
Lars Gustäbel | 96753b3 | 2000-09-24 12:24:24 +0000 | [diff] [blame] | 190 | |
Lars Gustäbel | e292a24 | 2000-09-24 20:19:45 +0000 | [diff] [blame] | 191 | return handler._notations == [("GIF", "-//CompuServe//NOTATION Graphics Interchange Format 89a//EN", None)] and \ |
| 192 | handler._entities == [("img", None, "expat.gif", "GIF")] |
Lars Gustäbel | 96753b3 | 2000-09-24 12:24:24 +0000 | [diff] [blame] | 193 | |
| 194 | # ===== EntityResolver support |
| 195 | |
Lars Gustäbel | e292a24 | 2000-09-24 20:19:45 +0000 | [diff] [blame] | 196 | class TestEntityResolver: |
Lars Gustäbel | 96753b3 | 2000-09-24 12:24:24 +0000 | [diff] [blame] | 197 | |
Lars Gustäbel | e292a24 | 2000-09-24 20:19:45 +0000 | [diff] [blame] | 198 | def resolveEntity(self, publicId, systemId): |
| 199 | inpsrc = InputSource() |
| 200 | inpsrc.setByteStream(StringIO("<entity/>")) |
| 201 | return inpsrc |
| 202 | |
| 203 | def test_expat_entityresolver(): |
Lars Gustäbel | e292a24 | 2000-09-24 20:19:45 +0000 | [diff] [blame] | 204 | parser = create_parser() |
| 205 | parser.setEntityResolver(TestEntityResolver()) |
| 206 | result = StringIO() |
| 207 | parser.setContentHandler(XMLGenerator(result)) |
| 208 | |
| 209 | parser.feed('<!DOCTYPE doc [\n') |
| 210 | parser.feed(' <!ENTITY test SYSTEM "whatever">\n') |
| 211 | parser.feed(']>\n') |
| 212 | parser.feed('<doc>&test;</doc>') |
| 213 | parser.close() |
| 214 | |
| 215 | return result.getvalue() == start + "<doc><entity></entity></doc>" |
| 216 | |
Lars Gustäbel | ab64787 | 2000-09-24 18:40:52 +0000 | [diff] [blame] | 217 | # ===== Attributes support |
| 218 | |
| 219 | class AttrGatherer(ContentHandler): |
| 220 | |
| 221 | def startElement(self, name, attrs): |
| 222 | self._attrs = attrs |
| 223 | |
| 224 | def startElementNS(self, name, qname, attrs): |
| 225 | self._attrs = attrs |
| 226 | |
| 227 | def test_expat_attrs_empty(): |
| 228 | parser = create_parser() |
| 229 | gather = AttrGatherer() |
| 230 | parser.setContentHandler(gather) |
| 231 | |
| 232 | parser.feed("<doc/>") |
| 233 | parser.close() |
| 234 | |
| 235 | return verify_empty_attrs(gather._attrs) |
| 236 | |
| 237 | def test_expat_attrs_wattr(): |
| 238 | parser = create_parser() |
| 239 | gather = AttrGatherer() |
| 240 | parser.setContentHandler(gather) |
| 241 | |
| 242 | parser.feed("<doc attr='val'/>") |
| 243 | parser.close() |
| 244 | |
| 245 | return verify_attrs_wattr(gather._attrs) |
| 246 | |
| 247 | def test_expat_nsattrs_empty(): |
| 248 | parser = create_parser(1) |
| 249 | gather = AttrGatherer() |
| 250 | parser.setContentHandler(gather) |
| 251 | |
| 252 | parser.feed("<doc/>") |
| 253 | parser.close() |
| 254 | |
| 255 | return verify_empty_nsattrs(gather._attrs) |
| 256 | |
| 257 | def test_expat_nsattrs_wattr(): |
| 258 | parser = create_parser(1) |
| 259 | gather = AttrGatherer() |
| 260 | parser.setContentHandler(gather) |
| 261 | |
| 262 | parser.feed("<doc xmlns:ns='%s' ns:attr='val'/>" % ns_uri) |
| 263 | parser.close() |
| 264 | |
| 265 | attrs = gather._attrs |
| 266 | |
| 267 | return attrs.getLength() == 1 and \ |
| 268 | attrs.getNames() == [(ns_uri, "attr")] and \ |
| 269 | attrs.getQNames() == [] and \ |
| 270 | len(attrs) == 1 and \ |
| 271 | attrs.has_key((ns_uri, "attr")) and \ |
| 272 | attrs.keys() == [(ns_uri, "attr")] and \ |
| 273 | attrs.get((ns_uri, "attr")) == "val" and \ |
| 274 | attrs.get((ns_uri, "attr"), 25) == "val" and \ |
| 275 | attrs.items() == [((ns_uri, "attr"), "val")] and \ |
| 276 | attrs.values() == ["val"] and \ |
| 277 | attrs.getValue((ns_uri, "attr")) == "val" and \ |
| 278 | attrs[(ns_uri, "attr")] == "val" |
| 279 | |
Lars Gustäbel | b7536d5 | 2000-09-24 18:53:56 +0000 | [diff] [blame] | 280 | # ===== InputSource support |
| 281 | |
Martin v. Löwis | 33315b1 | 2000-09-24 20:30:24 +0000 | [diff] [blame] | 282 | xml_test_out = open(findfile("test.xml.out")).read() |
Lars Gustäbel | b7536d5 | 2000-09-24 18:53:56 +0000 | [diff] [blame] | 283 | |
| 284 | def test_expat_inpsource_filename(): |
| 285 | parser = create_parser() |
| 286 | result = StringIO() |
| 287 | xmlgen = XMLGenerator(result) |
| 288 | |
| 289 | parser.setContentHandler(xmlgen) |
Martin v. Löwis | 33315b1 | 2000-09-24 20:30:24 +0000 | [diff] [blame] | 290 | parser.parse(findfile("test.xml")) |
Lars Gustäbel | b7536d5 | 2000-09-24 18:53:56 +0000 | [diff] [blame] | 291 | |
| 292 | return result.getvalue() == xml_test_out |
| 293 | |
| 294 | def test_expat_inpsource_sysid(): |
| 295 | parser = create_parser() |
| 296 | result = StringIO() |
| 297 | xmlgen = XMLGenerator(result) |
| 298 | |
| 299 | parser.setContentHandler(xmlgen) |
Martin v. Löwis | 33315b1 | 2000-09-24 20:30:24 +0000 | [diff] [blame] | 300 | parser.parse(InputSource(findfile("test.xml"))) |
Lars Gustäbel | b7536d5 | 2000-09-24 18:53:56 +0000 | [diff] [blame] | 301 | |
| 302 | return result.getvalue() == xml_test_out |
| 303 | |
| 304 | def test_expat_inpsource_stream(): |
| 305 | parser = create_parser() |
| 306 | result = StringIO() |
| 307 | xmlgen = XMLGenerator(result) |
| 308 | |
| 309 | parser.setContentHandler(xmlgen) |
| 310 | inpsrc = InputSource() |
Martin v. Löwis | 33315b1 | 2000-09-24 20:30:24 +0000 | [diff] [blame] | 311 | inpsrc.setByteStream(open(findfile("test.xml"))) |
Lars Gustäbel | b7536d5 | 2000-09-24 18:53:56 +0000 | [diff] [blame] | 312 | parser.parse(inpsrc) |
| 313 | |
| 314 | return result.getvalue() == xml_test_out |
| 315 | |
Lars Gustäbel | ab64787 | 2000-09-24 18:40:52 +0000 | [diff] [blame] | 316 | # =========================================================================== |
| 317 | # |
| 318 | # xmlreader tests |
| 319 | # |
| 320 | # =========================================================================== |
| 321 | |
| 322 | # ===== AttributesImpl |
| 323 | |
| 324 | def verify_empty_attrs(attrs): |
| 325 | try: |
| 326 | attrs.getValue("attr") |
| 327 | gvk = 0 |
| 328 | except KeyError: |
| 329 | gvk = 1 |
| 330 | |
| 331 | try: |
| 332 | attrs.getValueByQName("attr") |
| 333 | gvqk = 0 |
| 334 | except KeyError: |
| 335 | gvqk = 1 |
| 336 | |
| 337 | try: |
| 338 | attrs.getNameByQName("attr") |
| 339 | gnqk = 0 |
| 340 | except KeyError: |
| 341 | gnqk = 1 |
| 342 | |
| 343 | try: |
| 344 | attrs.getQNameByName("attr") |
| 345 | gqnk = 0 |
| 346 | except KeyError: |
| 347 | gqnk = 1 |
| 348 | |
| 349 | try: |
| 350 | attrs["attr"] |
| 351 | gik = 0 |
| 352 | except KeyError: |
| 353 | gik = 1 |
| 354 | |
| 355 | return attrs.getLength() == 0 and \ |
| 356 | attrs.getNames() == [] and \ |
| 357 | attrs.getQNames() == [] and \ |
| 358 | len(attrs) == 0 and \ |
| 359 | not attrs.has_key("attr") and \ |
| 360 | attrs.keys() == [] and \ |
| 361 | attrs.get("attrs") == None and \ |
| 362 | attrs.get("attrs", 25) == 25 and \ |
| 363 | attrs.items() == [] and \ |
| 364 | attrs.values() == [] and \ |
| 365 | gvk and gvqk and gnqk and gik and gqnk |
| 366 | |
| 367 | def verify_attrs_wattr(attrs): |
| 368 | return attrs.getLength() == 1 and \ |
| 369 | attrs.getNames() == ["attr"] and \ |
| 370 | attrs.getQNames() == ["attr"] and \ |
| 371 | len(attrs) == 1 and \ |
| 372 | attrs.has_key("attr") and \ |
| 373 | attrs.keys() == ["attr"] and \ |
| 374 | attrs.get("attr") == "val" and \ |
| 375 | attrs.get("attr", 25) == "val" and \ |
| 376 | attrs.items() == [("attr", "val")] and \ |
| 377 | attrs.values() == ["val"] and \ |
| 378 | attrs.getValue("attr") == "val" and \ |
| 379 | attrs.getValueByQName("attr") == "val" and \ |
| 380 | attrs.getNameByQName("attr") == "attr" and \ |
| 381 | attrs["attr"] == "val" and \ |
| 382 | attrs.getQNameByName("attr") == "attr" |
| 383 | |
| 384 | def test_attrs_empty(): |
| 385 | return verify_empty_attrs(AttributesImpl({})) |
| 386 | |
| 387 | def test_attrs_wattr(): |
| 388 | return verify_attrs_wattr(AttributesImpl({"attr" : "val"})) |
| 389 | |
| 390 | # ===== AttributesImpl |
| 391 | |
| 392 | def verify_empty_nsattrs(attrs): |
| 393 | try: |
| 394 | attrs.getValue((ns_uri, "attr")) |
| 395 | gvk = 0 |
| 396 | except KeyError: |
| 397 | gvk = 1 |
| 398 | |
| 399 | try: |
| 400 | attrs.getValueByQName("ns:attr") |
| 401 | gvqk = 0 |
| 402 | except KeyError: |
| 403 | gvqk = 1 |
| 404 | |
| 405 | try: |
| 406 | attrs.getNameByQName("ns:attr") |
| 407 | gnqk = 0 |
| 408 | except KeyError: |
| 409 | gnqk = 1 |
| 410 | |
| 411 | try: |
| 412 | attrs.getQNameByName((ns_uri, "attr")) |
| 413 | gqnk = 0 |
| 414 | except KeyError: |
| 415 | gqnk = 1 |
| 416 | |
| 417 | try: |
| 418 | attrs[(ns_uri, "attr")] |
| 419 | gik = 0 |
| 420 | except KeyError: |
| 421 | gik = 1 |
| 422 | |
| 423 | return attrs.getLength() == 0 and \ |
| 424 | attrs.getNames() == [] and \ |
| 425 | attrs.getQNames() == [] and \ |
| 426 | len(attrs) == 0 and \ |
| 427 | not attrs.has_key((ns_uri, "attr")) and \ |
| 428 | attrs.keys() == [] and \ |
| 429 | attrs.get((ns_uri, "attr")) == None and \ |
| 430 | attrs.get((ns_uri, "attr"), 25) == 25 and \ |
| 431 | attrs.items() == [] and \ |
| 432 | attrs.values() == [] and \ |
| 433 | gvk and gvqk and gnqk and gik and gqnk |
| 434 | |
| 435 | def test_nsattrs_empty(): |
| 436 | return verify_empty_nsattrs(AttributesNSImpl({}, {})) |
| 437 | |
| 438 | def test_nsattrs_wattr(): |
| 439 | attrs = AttributesNSImpl({(ns_uri, "attr") : "val"}, |
| 440 | {(ns_uri, "attr") : "ns:attr"}) |
| 441 | |
| 442 | return attrs.getLength() == 1 and \ |
| 443 | attrs.getNames() == [(ns_uri, "attr")] and \ |
| 444 | attrs.getQNames() == ["ns:attr"] and \ |
| 445 | len(attrs) == 1 and \ |
| 446 | attrs.has_key((ns_uri, "attr")) and \ |
| 447 | attrs.keys() == [(ns_uri, "attr")] and \ |
| 448 | attrs.get((ns_uri, "attr")) == "val" and \ |
| 449 | attrs.get((ns_uri, "attr"), 25) == "val" and \ |
| 450 | attrs.items() == [((ns_uri, "attr"), "val")] and \ |
| 451 | attrs.values() == ["val"] and \ |
| 452 | attrs.getValue((ns_uri, "attr")) == "val" and \ |
| 453 | attrs.getValueByQName("ns:attr") == "val" and \ |
| 454 | attrs.getNameByQName("ns:attr") == (ns_uri, "attr") and \ |
| 455 | attrs[(ns_uri, "attr")] == "val" and \ |
| 456 | attrs.getQNameByName((ns_uri, "attr")) == "ns:attr" |
| 457 | |
| 458 | |
Lars Gustäbel | 96753b3 | 2000-09-24 12:24:24 +0000 | [diff] [blame] | 459 | # ===== Main program |
| 460 | |
Lars Gustäbel | b7536d5 | 2000-09-24 18:53:56 +0000 | [diff] [blame] | 461 | def make_test_output(): |
| 462 | parser = create_parser() |
| 463 | result = StringIO() |
| 464 | xmlgen = XMLGenerator(result) |
| 465 | |
| 466 | parser.setContentHandler(xmlgen) |
Martin v. Löwis | 33315b1 | 2000-09-24 20:30:24 +0000 | [diff] [blame] | 467 | parser.parse(findfile("test.xml")) |
Lars Gustäbel | b7536d5 | 2000-09-24 18:53:56 +0000 | [diff] [blame] | 468 | |
Martin v. Löwis | 33315b1 | 2000-09-24 20:30:24 +0000 | [diff] [blame] | 469 | outf = open(findfile("test.xml.out"), "w") |
Lars Gustäbel | b7536d5 | 2000-09-24 18:53:56 +0000 | [diff] [blame] | 470 | outf.write(result.getvalue()) |
| 471 | outf.close() |
| 472 | |
Lars Gustäbel | 96753b3 | 2000-09-24 12:24:24 +0000 | [diff] [blame] | 473 | items = locals().items() |
| 474 | items.sort() |
| 475 | for (name, value) in items: |
| 476 | if name[ : 5] == "test_": |
| 477 | confirm(value(), name) |
| 478 | |
| 479 | print "%d tests, %d failures" % (tests, fails) |
| 480 | if fails != 0: |
| 481 | raise TestFailed, "%d of %d tests failed" % (fails, tests) |