1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
|
#!/usr/bin/env python
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
import unittest
from qpid.codec import Codec
from qpid.spec08 import load
from cStringIO import StringIO
from qpid.reference import ReferenceId
__doc__ = """
This is a unit test script for qpid/codec.py
It can be run standalone or as part of the existing test framework.
To run standalone:
-------------------
Place in the qpid/python/tests/ directory and type...
python codec.py
A brief output will be printed on screen. The verbose output will be placed inn a file called
codec_unit_test_output.txt. [TODO: make this filename configurable]
To run as part of the existing test framework:
-----------------------------------------------
python run-tests tests.codec
Change History:
-----------------
Jimmy John 05/19/2007 Initial draft
Jimmy John 05/22/2007 Implemented comments by Rafael Schloming
"""
from qpid.specs_config import amqp_spec_0_8
SPEC = load(amqp_spec_0_8)
# --------------------------------------
# --------------------------------------
class BaseDataTypes(unittest.TestCase):
"""
Base class containing common functions
"""
# ---------------
def setUp(self):
"""
standard setUp for unitetest (refer unittest documentation for details)
"""
self.codec = Codec(StringIO(), SPEC)
# ------------------
def tearDown(self):
"""
standard tearDown for unitetest (refer unittest documentation for details)
"""
self.codec.stream.flush()
self.codec.stream.close()
# ----------------------------------------
def callFunc(self, functionName, *args):
"""
helper function - given a function name and arguments, calls the function with the args and
returns the contents of the stream
"""
getattr(self.codec, functionName)(args[0])
return self.codec.stream.getvalue()
# ----------------------------------------
def readFunc(self, functionName, *args):
"""
helper function - creates a input stream and then calls the function with arguments as have been
supplied
"""
self.codec.stream = StringIO(args[0])
return getattr(self.codec, functionName)()
# ----------------------------------------
# ----------------------------------------
class IntegerTestCase(BaseDataTypes):
"""
Handles octet, short, long, long long
"""
# -------------------------
def __init__(self, *args):
"""
sets constants for use in tests
"""
BaseDataTypes.__init__(self, *args)
self.const_integer = 2
self.const_integer_octet_encoded = '\x02'
self.const_integer_short_encoded = '\x00\x02'
self.const_integer_long_encoded = '\x00\x00\x00\x02'
self.const_integer_long_long_encoded = '\x00\x00\x00\x00\x00\x00\x00\x02'
# -------------------------- #
# Unsigned Octect - 8 bits #
# -------------------------- #
# --------------------------
def test_unsigned_octet(self):
"""
ubyte format requires 0<=number<=255
"""
self.failUnlessEqual(self.callFunc('encode_octet', self.const_integer), self.const_integer_octet_encoded, 'octect encoding FAILED...')
# -------------------------------------------
def test_octet_out_of_upper_range(self):
"""
testing for input above acceptable range
"""
self.failUnlessRaises(Exception, self.codec.encode_octet, 256)
# -------------------------------------------
def test_uoctet_out_of_lower_range(self):
"""
testing for input below acceptable range
"""
self.failUnlessRaises(Exception, self.codec.encode_octet, -1)
# ---------------------------------
def test_uoctet_with_fraction(self):
"""
the fractional part should be ignored...
"""
self.failUnlessEqual(self.callFunc('encode_octet', 2.5), self.const_integer_octet_encoded, 'octect encoding FAILED with fractions...')
# ------------------------------------
def test_unsigned_octet_decode(self):
"""
octet decoding
"""
self.failUnlessEqual(self.readFunc('decode_octet', self.const_integer_octet_encoded), self.const_integer, 'octect decoding FAILED...')
# ----------------------------------- #
# Unsigned Short Integers - 16 bits #
# ----------------------------------- #
# -----------------------
def test_ushort_int(self):
"""
testing unsigned short integer
"""
self.failUnlessEqual(self.callFunc('encode_short', self.const_integer), self.const_integer_short_encoded, 'short encoding FAILED...')
# -------------------------------------------
def test_ushort_int_out_of_upper_range(self):
"""
testing for input above acceptable range
"""
self.failUnlessRaises(Exception, self.codec.encode_short, 65536)
# -------------------------------------------
def test_ushort_int_out_of_lower_range(self):
"""
testing for input below acceptable range
"""
self.failUnlessRaises(Exception, self.codec.encode_short, -1)
# ---------------------------------
def test_ushort_int_with_fraction(self):
"""
the fractional part should be ignored...
"""
self.failUnlessEqual(self.callFunc('encode_short', 2.5), self.const_integer_short_encoded, 'short encoding FAILED with fractions...')
# ------------------------------------
def test_ushort_int_decode(self):
"""
unsigned short decoding
"""
self.failUnlessEqual(self.readFunc('decode_short', self.const_integer_short_encoded), self.const_integer, 'unsigned short decoding FAILED...')
# ---------------------------------- #
# Unsigned Long Integers - 32 bits #
# ---------------------------------- #
# -----------------------
def test_ulong_int(self):
"""
testing unsigned long iteger
"""
self.failUnlessEqual(self.callFunc('encode_long', self.const_integer), self.const_integer_long_encoded, 'long encoding FAILED...')
# -------------------------------------------
def test_ulong_int_out_of_upper_range(self):
"""
testing for input above acceptable range
"""
self.failUnlessRaises(Exception, self.codec.encode_long, 4294967296)
# -------------------------------------------
def test_ulong_int_out_of_lower_range(self):
"""
testing for input below acceptable range
"""
self.failUnlessRaises(Exception, self.codec.encode_long, -1)
# ---------------------------------
def test_ulong_int_with_fraction(self):
"""
the fractional part should be ignored...
"""
self.failUnlessEqual(self.callFunc('encode_long', 2.5), self.const_integer_long_encoded, 'long encoding FAILED with fractions...')
# -------------------------------
def test_ulong_int_decode(self):
"""
unsigned long decoding
"""
self.failUnlessEqual(self.readFunc('decode_long', self.const_integer_long_encoded), self.const_integer, 'unsigned long decoding FAILED...')
# --------------------------------------- #
# Unsigned Long Long Integers - 64 bits #
# --------------------------------------- #
# -----------------------
def test_ulong_long_int(self):
"""
testing unsinged long long integer
"""
self.failUnlessEqual(self.callFunc('encode_longlong', self.const_integer), self.const_integer_long_long_encoded, 'long long encoding FAILED...')
# -------------------------------------------
def test_ulong_long_int_out_of_upper_range(self):
"""
testing for input above acceptable range
"""
self.failUnlessRaises(Exception, self.codec.encode_longlong, 18446744073709551616)
# -------------------------------------------
def test_ulong_long_int_out_of_lower_range(self):
"""
testing for input below acceptable range
"""
self.failUnlessRaises(Exception, self.codec.encode_longlong, -1)
# ---------------------------------
def test_ulong_long_int_with_fraction(self):
"""
the fractional part should be ignored...
"""
self.failUnlessEqual(self.callFunc('encode_longlong', 2.5), self.const_integer_long_long_encoded, 'long long encoding FAILED with fractions...')
# ------------------------------------
def test_ulong_long_int_decode(self):
"""
unsigned long long decoding
"""
self.failUnlessEqual(self.readFunc('decode_longlong', self.const_integer_long_long_encoded), self.const_integer, 'unsigned long long decoding FAILED...')
# -----------------------------------
# -----------------------------------
class BitTestCase(BaseDataTypes):
"""
Handles bits
"""
# ----------------------------------------------
def callFunc(self, functionName, *args):
"""
helper function
"""
for ele in args:
getattr(self.codec, functionName)(ele)
self.codec.flush()
return self.codec.stream.getvalue()
# -------------------
def test_bit1(self):
"""
sends in 11
"""
self.failUnlessEqual(self.callFunc('encode_bit', 1, 1), '\x03', '11 bit encoding FAILED...')
# -------------------
def test_bit2(self):
"""
sends in 10011
"""
self.failUnlessEqual(self.callFunc('encode_bit', 1, 1, 0, 0, 1), '\x13', '10011 bit encoding FAILED...')
# -------------------
def test_bit3(self):
"""
sends in 1110100111 [10 bits(right to left), should be compressed into two octets]
"""
self.failUnlessEqual(self.callFunc('encode_bit', 1,1,1,0,0,1,0,1,1,1), '\xa7\x03', '1110100111(right to left) bit encoding FAILED...')
# ------------------------------------
def test_bit_decode_1(self):
"""
decode bit 1
"""
self.failUnlessEqual(self.readFunc('decode_bit', '\x01'), 1, 'decode bit 1 FAILED...')
# ------------------------------------
def test_bit_decode_0(self):
"""
decode bit 0
"""
self.failUnlessEqual(self.readFunc('decode_bit', '\x00'), 0, 'decode bit 0 FAILED...')
# -----------------------------------
# -----------------------------------
class StringTestCase(BaseDataTypes):
"""
Handles short strings, long strings
"""
# ------------------------------------------------------------- #
# Short Strings - 8 bit length followed by zero or more octets #
# ------------------------------------------------------------- #
# ---------------------------------------
def test_short_string_zero_length(self):
"""
0 length short string
"""
self.failUnlessEqual(self.callFunc('encode_shortstr', ''), '\x00', '0 length short string encoding FAILED...')
# -------------------------------------------
def test_short_string_positive_length(self):
"""
positive length short string
"""
self.failUnlessEqual(self.callFunc('encode_shortstr', 'hello world'), '\x0bhello world', 'positive length short string encoding FAILED...')
# -------------------------------------------
def test_short_string_out_of_upper_range(self):
"""
string length > 255
"""
self.failUnlessRaises(Exception, self.codec.encode_shortstr, 'x'*256)
# ------------------------------------
def test_short_string_decode(self):
"""
short string decode
"""
self.failUnlessEqual(self.readFunc('decode_shortstr', '\x0bhello world'), 'hello world', 'short string decode FAILED...')
# ------------------------------------------------------------- #
# Long Strings - 32 bit length followed by zero or more octets #
# ------------------------------------------------------------- #
# ---------------------------------------
def test_long_string_zero_length(self):
"""
0 length long string
"""
self.failUnlessEqual(self.callFunc('encode_longstr', ''), '\x00\x00\x00\x00', '0 length long string encoding FAILED...')
# -------------------------------------------
def test_long_string_positive_length(self):
"""
positive length long string
"""
self.failUnlessEqual(self.callFunc('encode_longstr', 'hello world'), '\x00\x00\x00\x0bhello world', 'positive length long string encoding FAILED...')
# ------------------------------------
def test_long_string_decode(self):
"""
long string decode
"""
self.failUnlessEqual(self.readFunc('decode_longstr', '\x00\x00\x00\x0bhello world'), 'hello world', 'long string decode FAILED...')
# --------------------------------------
# --------------------------------------
class TimestampTestCase(BaseDataTypes):
"""
No need of any test cases here as timestamps are implemented as long long which is tested above
"""
pass
# ---------------------------------------
# ---------------------------------------
class FieldTableTestCase(BaseDataTypes):
"""
Handles Field Tables
Only S/I type messages seem to be implemented currently
"""
# -------------------------
def __init__(self, *args):
"""
sets constants for use in tests
"""
BaseDataTypes.__init__(self, *args)
self.const_field_table_dummy_dict = {'$key1':'value1','$key2':'value2'}
self.const_field_table_dummy_dict_encoded = '\x00\x00\x00\x22\x05$key2S\x00\x00\x00\x06value2\x05$key1S\x00\x00\x00\x06value1'
# -------------------------------------------
def test_field_table_name_value_pair(self):
"""
valid name value pair
"""
self.failUnlessEqual(self.callFunc('encode_table', {'$key1':'value1'}), '\x00\x00\x00\x11\x05$key1S\x00\x00\x00\x06value1', 'valid name value pair encoding FAILED...')
# ---------------------------------------------------
def test_field_table_multiple_name_value_pair(self):
"""
multiple name value pair
"""
self.failUnlessEqual(self.callFunc('encode_table', self.const_field_table_dummy_dict), self.const_field_table_dummy_dict_encoded, 'multiple name value pair encoding FAILED...')
# ------------------------------------
def test_field_table_decode(self):
"""
field table decode
"""
self.failUnlessEqual(self.readFunc('decode_table', self.const_field_table_dummy_dict_encoded), self.const_field_table_dummy_dict, 'field table decode FAILED...')
# ------------------------------------
# ------------------------------------
class ContentTestCase(BaseDataTypes):
"""
Handles Content data types
"""
# -----------------------------
def test_content_inline(self):
"""
inline content
"""
self.failUnlessEqual(self.callFunc('encode_content', 'hello inline message'), '\x00\x00\x00\x00\x14hello inline message', 'inline content encoding FAILED...')
# --------------------------------
def test_content_reference(self):
"""
reference content
"""
self.failUnlessEqual(self.callFunc('encode_content', ReferenceId('dummyId')), '\x01\x00\x00\x00\x07dummyId', 'reference content encoding FAILED...')
# ------------------------------------
def test_content_inline_decode(self):
"""
inline content decode
"""
self.failUnlessEqual(self.readFunc('decode_content', '\x00\x00\x00\x00\x14hello inline message'), 'hello inline message', 'inline content decode FAILED...')
# ------------------------------------
def test_content_reference_decode(self):
"""
reference content decode
"""
self.failUnlessEqual(self.readFunc('decode_content', '\x01\x00\x00\x00\x07dummyId').id, 'dummyId', 'reference content decode FAILED...')
# -----------------------------------
# -----------------------------------
class BooleanTestCase(BaseDataTypes):
# -------------------
def test_true_encode(self):
self.failUnlessEqual(self.callFunc('encode_boolean', True), '\x01', 'True encoding FAILED...')
# -------------------
def test_true_decode(self):
self.failUnlessEqual(self.readFunc('decode_boolean', '\x01'), True, 'True decoding FAILED...')
self.failUnlessEqual(self.readFunc('decode_boolean', '\x02'), True, 'True decoding FAILED...')
self.failUnlessEqual(self.readFunc('decode_boolean', '\xFF'), True, 'True decoding FAILED...')
# -------------------
def test_false_encode(self):
self.failUnlessEqual(self.callFunc('encode_boolean', False), '\x00', 'False encoding FAILED...')
# -------------------
def test_false_decode(self):
self.failUnlessEqual(self.readFunc('decode_boolean', '\x00'), False, 'False decoding FAILED...')
# -----------------------------------
# -----------------------------------
class ResolveTestCase(BaseDataTypes):
# -------------------
# Test resolving the value 1, which should implicitly be a python int
def test_resolve_int_1(self):
value = 1
expected = "signed_int"
resolved = self.codec.resolve(value.__class__, value)
self.failUnlessEqual(resolved, expected, "resolve FAILED...expected %s got %s" % (expected, resolved))
# -------------------
# Test resolving the value -1, which should implicitly be a python int
def test_resolve_int_negative_1(self):
value = -1
expected = "signed_int"
resolved = self.codec.resolve(value.__class__, value)
self.failUnlessEqual(resolved, expected, "resolve FAILED...expected %s got %s" % (expected, resolved))
# -------------------
# Test resolving the min signed 32bit integer value, -2^31
def test_resolve_int_min(self):
value = -2147483648 #-2^31
expected = "signed_int"
resolved = self.codec.resolve(value.__class__, value)
self.failUnlessEqual(resolved, expected, "resolve FAILED...expected %s got %s" % (expected, resolved))
# -------------------
# Test resolving the max signed 32bit integer value, 2^31 -1
def test_resolve_int_max(self):
value = 2147483647 #2^31 -1
expected = "signed_int"
resolved = self.codec.resolve(value.__class__, value)
self.failUnlessEqual(resolved, expected, "resolve FAILED...expected %s got %s" % (expected, resolved))
# -------------------
# Test resolving above the max signed 32bit integer value of 2^31 -1
# Should be a python long, but should be classed as a signed 64bit long on the wire either way
def test_resolve_int_above_signed_32bit_max(self):
value = 2147483648 #2^31, i.e 1 above the 32bit signed max
expected = "signed_long"
resolved = self.codec.resolve(value.__class__, value)
self.failUnlessEqual(resolved, expected, "resolve FAILED...expected %s got %s" % (expected, resolved))
# -------------------
# Test resolving above the max signed 32bit integer value of 2^31 -1
# As above except use an explicitly cast python long
def test_resolve_long_above_signed_32bit_max(self):
value = 2147483648L #2^31, i.e 1 above the 32bit signed max
expected = "signed_long"
resolved = self.codec.resolve(value.__class__, value)
self.failUnlessEqual(resolved, expected, "resolve FAILED...expected %s got %s" % (expected, resolved))
# -------------------
# Test resolving an explicitly cast python long of value 1, i.e less than the max signed 32bit integer value
# Should be encoded as a 32bit signed int on the wire
def test_resolve_long_1(self):
value = 1L
expected = "signed_int"
resolved = self.codec.resolve(value.__class__, value)
self.failUnlessEqual(resolved, expected, "resolve FAILED...expected %s got %s" % (expected, resolved))
# -------------------
# Test resolving the max signed 64bit integer value of 2^63 -1
# Should be a python long, but should be classed as a signed 64bit long on the wire either way
def test_resolve_64bit_signed_max(self):
value = 9223372036854775807 #2^63 -1
expected = "signed_long"
resolved = self.codec.resolve(value.__class__, value)
self.failUnlessEqual(resolved, expected, "resolve FAILED...expected %s got %s" % (expected, resolved))
# -------------------
# Test resolving the min signed 64bit integer value of -2^63
# Should be a python long, but should be classed as a signed 64bit long on the wire either way
def test_resolve_64bit_signed_min(self):
value = -9223372036854775808 # -2^63
expected = "signed_long"
resolved = self.codec.resolve(value.__class__, value)
self.failUnlessEqual(resolved, expected, "resolve FAILED...expected %s got %s" % (expected, resolved))
# -------------------
# Test resolving a value of 2^63, i.e more than the max a signed 64bit integer value can hold.
# Should throw an exception indicating the value can't be encoded.
def test_resolve_above_64bit_signed_max(self):
value = 9223372036854775808L #2^63
self.failUnlessRaises(Exception, self.codec.resolve, value.__class__, value)
# -------------------
# Test resolving a value of -2^63 -1, i.e less than the min a signed 64bit integer value can hold.
# Should throw an exception indicating the value can't be encoded.
def test_resolve_below_64bit_signed_min(self):
value = 9223372036854775808L # -2^63 -1
self.failUnlessRaises(Exception, self.codec.resolve, value.__class__, value)
# -------------------
# Test resolving a float. Should indicate use of double as python uses 64bit floats
def test_resolve_float(self):
value = 1.1
expected = "double"
resolved = self.codec.resolve(value.__class__, value)
self.failUnlessEqual(resolved, expected, "resolve FAILED...expected %s got %s" % (expected, resolved))
# -------------------
# Test resolving a string. Should indicate use of long string encoding
def test_resolve_string(self):
value = "myString"
expected = "longstr"
resolved = self.codec.resolve(value.__class__, value)
self.failUnlessEqual(resolved, expected, "resolve FAILED...expected %s got %s" % (expected, resolved))
# -------------------
# Test resolving None. Should indicate use of a void encoding.
def test_resolve_None(self):
value = None
expected = "void"
resolved = self.codec.resolve(value.__class__, value)
self.failUnlessEqual(resolved, expected, "resolve FAILED...expected %s got %s" % (expected, resolved))
# ------------------------ #
# Pre - existing test code #
# ------------------------ #
# ---------------------
def test(type, value):
"""
old test function cut/copy/paste from qpid/codec.py
"""
if isinstance(value, (list, tuple)):
values = value
else:
values = [value]
stream = StringIO()
codec = Codec(stream, SPEC)
for v in values:
codec.encode(type, v)
codec.flush()
enc = stream.getvalue()
stream.reset()
dup = []
for i in xrange(len(values)):
dup.append(codec.decode(type))
if values != dup:
raise AssertionError("%r --> %r --> %r" % (values, enc, dup))
# -----------------------
def dotest(type, value):
"""
old test function cut/copy/paste from qpid/codec.py
"""
args = (type, value)
test(*args)
# -------------
def oldtests():
"""
old test function cut/copy/paste from qpid/codec.py
"""
for value in ("1", "0", "110", "011", "11001", "10101", "10011"):
for i in range(10):
dotest("bit", map(lambda x: x == "1", value*i))
for value in ({}, {"asdf": "fdsa", "fdsa": 1, "three": 3}, {"one": 1}):
dotest("table", value)
for type in ("octet", "short", "long", "longlong"):
for value in range(0, 256):
dotest(type, value)
for type in ("shortstr", "longstr"):
for value in ("", "a", "asdf"):
dotest(type, value)
# -----------------------------------------
class oldTests(unittest.TestCase):
"""
class to handle pre-existing test cases
"""
# ---------------------------
def test_oldtestcases(self):
"""
call the old tests
"""
return oldtests()
# ---------------------------
# ---------------------------
if __name__ == '__main__':
codec_test_suite = unittest.TestSuite()
#adding all the test suites...
codec_test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(IntegerTestCase))
codec_test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(BitTestCase))
codec_test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(StringTestCase))
codec_test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TimestampTestCase))
codec_test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(FieldTableTestCase))
codec_test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(ContentTestCase))
#loading pre-existing test case from qpid/codec.py
codec_test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(oldTests))
run_output_stream = StringIO()
test_runner = unittest.TextTestRunner(run_output_stream, '', '')
test_result = test_runner.run(codec_test_suite)
print '\n%d test run...' % (test_result.testsRun)
if test_result.wasSuccessful():
print '\nAll tests successful\n'
if test_result.failures:
print '\n----------'
print '%d FAILURES:' % (len(test_result.failures))
print '----------\n'
for failure in test_result.failures:
print str(failure[0]) + ' ... FAIL'
if test_result.errors:
print '\n---------'
print '%d ERRORS:' % (len(test_result.errors))
print '---------\n'
for error in test_result.errors:
print str(error[0]) + ' ... ERROR'
f = open('codec_unit_test_output.txt', 'w')
f.write(str(run_output_stream.getvalue()))
f.close()
|