Changeset 1199
- Timestamp:
- 04/14/08 19:51:41 (2 years ago)
- Location:
- pyamf/trunk/pyamf
- Files:
-
- 7 modified
-
amf0.py (modified) (1 diff)
-
amf3.py (modified) (1 diff)
-
tests/test_amf0.py (modified) (15 diffs)
-
tests/test_amf3.py (modified) (24 diffs)
-
tests/test_basic.py (modified) (15 diffs)
-
tests/test_gateway.py (modified) (1 diff)
-
tests/util.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
pyamf/trunk/pyamf/amf0.py
r1151 r1199 370 370 371 371 for key in filter(lambda x: x in attrs, obj_attrs.keys()): 372 obj.__setattr__(key, obj_attrs[key])372 setattr(obj, key, obj_attrs[key]) 373 373 else: 374 374 f = obj.__setattr__ -
pyamf/trunk/pyamf/amf3.py
r1157 r1199 1134 1134 else: 1135 1135 for k, v in obj_attrs.iteritems(): 1136 obj.__setattr__(k, v)1136 setattr(obj, k, v) 1137 1137 1138 1138 return obj -
pyamf/trunk/pyamf/tests/test_amf0.py
r1146 r1199 18 18 import pyamf 19 19 from pyamf import amf0, util 20 from pyamf.tests.util import EncoderTester, DecoderTester 20 from pyamf.tests.util import EncoderTester, DecoderTester, ClassCacheClearingTestCase, Spam, ClassicSpam 21 21 22 22 class TypesTestCase(unittest.TestCase): … … 118 118 self.assertRaises(pyamf.ReferenceError, x.getObjectReference, {}) 119 119 120 class EncoderTestCase( unittest.TestCase):120 class EncoderTestCase(ClassCacheClearingTestCase): 121 121 """ 122 122 Tests the output from the AMF0 L{Encoder<pyamf.amf0.Encoder>} class. … … 124 124 125 125 def setUp(self): 126 ClassCacheClearingTestCase.setUp(self) 127 126 128 self.buf = util.BufferedByteStream() 127 129 self.encoder = amf0.Encoder(self.buf) … … 254 256 255 257 def test_force_amf3(self): 256 class Spam(object):257 pass258 259 258 pyamf.register_class(Spam, 'spam.eggs', metadata=['amf3']) 260 259 … … 268 267 269 268 def test_typed_object(self): 270 class Spam(object):271 pass272 273 269 pyamf.register_class(Spam, alias='org.pyamf.spam') 274 270 … … 307 303 308 304 def test_anonymous(self): 309 class Spam(object):310 pass311 312 305 pyamf.register_class(Spam) 313 306 … … 319 312 (x, '\x03\x00\x05hello\x02\x00\x05world\x00\x04spam\x02\x00\x04eggs\x00\x00\t')]) 320 313 321 pyamf.unregister_class(Spam)322 323 314 def test_dynamic(self): 324 class Spam(pyamf.ASObject):325 pass326 327 315 def attr_func(obj): 328 316 self.assertTrue(isinstance(obj, Spam)) … … 368 356 self._run([(x, '\x10\x00\x01x\x00\x03foo\x02\x00\x03bar\x00\x05hello' 369 357 '\x02\x00\x05world\x00\x00\t')]) 370 pyamf.unregister_class(Spam)371 358 372 359 def test_custom_type(self): … … 407 394 '\x00\x0bfamily_name\x02\x00\x03Doe\x00\ngiven_name\x02\x00\x04' 408 395 'Jane\x00\x00\t') 409 410 pyamf.unregister_class(Person)411 396 412 397 def test_getstate(self): … … 429 414 self.assertTrue(self.executed) 430 415 431 pyamf.unregister_class(Foo) 432 433 class DecoderTestCase(unittest.TestCase): 416 class DecoderTestCase(ClassCacheClearingTestCase): 434 417 """ 435 418 Tests the output from the AMF0 L{Decoder<pyamf.amf0.Decoder>} class. 436 419 """ 437 420 def setUp(self): 421 ClassCacheClearingTestCase.setUp(self) 422 438 423 self.buf = util.BufferedByteStream() 439 424 self.decoder = amf0.Decoder(self.buf) … … 572 557 573 558 def test_registered_class(self): 574 class Spam(object):575 pass576 577 try:578 del pyamf.CLASS_CACHE['org.pyamf.spam']579 except KeyError:580 pass581 582 559 pyamf.register_class(Spam, alias='org.pyamf.spam') 583 560 … … 592 569 self.assertTrue(hasattr(obj, 'baz')) 593 570 self.assertEquals(obj.baz, 'hello') 594 595 del pyamf.CLASS_CACHE['org.pyamf.spam']596 571 597 572 def test_complex_list(self): … … 659 634 self._run([(x, '\x10\x00\x01x\x00\x03foo\x02\x00\x03bar\x00\x05hello' 660 635 '\x02\x00\x05world\x00\x00\t')]) 661 pyamf.unregister_class(Foo)662 636 663 637 def test_setstate_newstyle(self): … … 685 659 self.assertEquals(foo.eggs, True) 686 660 self.assertTrue(self.executed) 687 688 pyamf.unregister_class(Foo)689 661 690 662 def test_setstate_classic(self): … … 715 687 716 688 pyamf.unregister_class(Foo) 689 690 def test_classic_class(self): 691 pyamf.register_class(ClassicSpam, 'spam.eggs') 692 693 self.buf.write('\x10\x00\tspam.eggs\x00\x03foo\x02\x00\x03bar\x00\x00\t') 694 self.buf.seek(0) 695 696 foo = self.decoder.readElement() 697 698 self.assertEquals(foo.foo, 'bar') 717 699 718 700 class HelperTestCase(unittest.TestCase): -
pyamf/trunk/pyamf/tests/test_amf3.py
r1157 r1199 18 18 import pyamf 19 19 from pyamf import amf3, util 20 from pyamf.tests.util import EncoderTester, DecoderTester 21 22 class Spam(object): 23 """ 24 A generic object to use for object encoding 25 """ 26 def __init__(self, d={}): 27 self.__dict__.update(d) 28 29 def __readamf__(self, input): 30 pass 31 32 def __writeamf__(self, output): 33 pass 20 from pyamf.tests import util as _util 21 from pyamf.tests.util import Spam, ClassicSpam 34 22 35 23 class TypesTestCase(unittest.TestCase): … … 195 183 self.assertEquals(len(new.legacy_xml), 0) 196 184 197 class ClassDefinitionTestCase( unittest.TestCase):185 class ClassDefinitionTestCase(_util.ClassCacheClearingTestCase): 198 186 def test_create(self): 199 187 x = amf3.ClassDefinition('') … … 220 208 self.assertEquals(len(x.static_attrs), 0) 221 209 222 pyamf.unregister_class(Spam)223 224 210 def test_name(self): 225 211 x = amf3.ClassDefinition('') … … 233 219 x = amf3.ClassDefinition('spam.eggs') 234 220 self.assertEquals(x.name, 'spam.eggs') 235 236 pyamf.unregister_class(Spam)237 221 238 222 def test_get_class(self): … … 249 233 self.assertEquals(x.getClass(), Spam) 250 234 251 pyamf.unregister_class(Spam)252 253 235 def test_get_alias(self): 254 236 pyamf.register_class(Spam, 'spam.eggs') … … 268 250 self.assertRaises(pyamf.UnknownClassAlias, x.getClassAlias) 269 251 270 class EncoderTestCase( unittest.TestCase):252 class EncoderTestCase(_util.ClassCacheClearingTestCase): 271 253 """ 272 254 Tests the output from the AMF3 L{Encoder<pyamf.amf3.Encoder>} class. 273 255 """ 274 256 def setUp(self): 257 _util.ClassCacheClearingTestCase.setUp(self) 258 275 259 self.buf = util.BufferedByteStream() 276 260 self.context = amf3.Context() … … 280 264 self.context.clear() 281 265 282 e = EncoderTester(self.encoder, data)266 e = _util.EncoderTester(self.encoder, data) 283 267 e.run(self) 284 268 … … 361 345 '\xb6tley Cr\xc3\x83\xc3\x82\xc2\xbce') 362 346 363 364 347 def test_string_references(self): 365 348 self._run([ … … 523 506 self.assertEquals(class_def.static_attrs, attrs) 524 507 525 pyamf.unregister_class(Spam)526 527 508 def test_anonymous(self): 528 509 pyamf.register_class(Spam) … … 531 512 532 513 self._run([(x, '\n\x0b\x01\x09spam\x06\x09eggs\x01')]) 533 pyamf.unregister_class(Spam)534 514 535 515 def test_custom_type(self): … … 590 570 self.assertTrue(self.executed) 591 571 592 pyamf.unregister_class(Foo) 593 594 class DecoderTestCase(unittest.TestCase): 572 class DecoderTestCase(_util.ClassCacheClearingTestCase): 595 573 """ 596 574 Tests the output from the AMF3 L{Decoder<pyamf.amf3.Decoder>} class. 597 575 """ 598 576 def setUp(self): 577 _util.ClassCacheClearingTestCase.setUp(self) 578 599 579 self.buf = util.BufferedByteStream() 600 580 self.context = amf3.Context() … … 604 584 def _run(self, data): 605 585 self.context.clear() 606 e = DecoderTester(self.decoder, data)586 e = _util.DecoderTester(self.decoder, data) 607 587 e.run(self) 608 588 … … 798 778 self.assertEquals(obj.baz, 'hello') 799 779 800 pyamf.unregister_class(Spam)801 802 780 def test_byte_array(self): 803 781 self._run([(amf3.ByteArray('hello'), '\x0c\x0bhello')]) … … 857 835 self.context.classes.remove(class_def) 858 836 859 pyamf.unregister_class(Spam)860 861 837 def test_setstate_newstyle(self): 862 838 self.executed = False … … 884 860 self.assertTrue(self.executed) 885 861 886 pyamf.unregister_class(Foo)887 888 862 def test_setstate_classic(self): 889 863 self.executed = False … … 911 885 self.assertTrue(self.executed) 912 886 913 pyamf.unregister_class(Foo) 887 def test_classic_class(self): 888 pyamf.register_class(ClassicSpam, 'spam.eggs') 889 890 self.buf.write('\n\x0b\x13spam.eggs\x07foo\x06\x07bar\x01') 891 self.buf.seek(0) 892 893 foo = self.decoder.readElement() 894 895 self.assertEquals(foo.foo, 'bar') 914 896 915 897 class ObjectEncodingTestCase(unittest.TestCase): … … 1013 995 pyamf.unregister_class(Spam) 1014 996 1015 class ObjectDecodingTestCase( unittest.TestCase):997 class ObjectDecodingTestCase(_util.ClassCacheClearingTestCase): 1016 998 def setUp(self): 999 _util.ClassCacheClearingTestCase.setUp(self) 1000 1017 1001 self.stream = util.BufferedByteStream() 1018 1002 self.context = amf3.Context() … … 1052 1036 self.assertEquals(obj.__dict__, {'spam': 'eggs'}) 1053 1037 1054 pyamf.unregister_class(Spam)1055 1056 1038 def test_dynamic(self): 1057 1039 pyamf.register_class(Spam, 'abc.xyz', metadata='dynamic') … … 1072 1054 self.assertTrue(isinstance(obj, Spam)) 1073 1055 self.assertEquals(obj.__dict__, {'spam': 'eggs'}) 1074 1075 pyamf.unregister_class(Spam)1076 1056 1077 1057 def test_combined(self): … … 1099 1079 self.assertEquals(obj.__dict__, {'spam': 'eggs', 'baz': 'nat'}) 1100 1080 1101 pyamf.unregister_class(Spam)1102 1103 1081 def test_external(self): 1104 1082 pyamf.register_class(Spam, 'abc.xyz', metadata=['external']) … … 1110 1088 self.assertTrue(isinstance(x, Spam)) 1111 1089 self.assertEquals(x.__dict__, {}) 1112 1113 pyamf.unregister_class(Spam)1114 1090 1115 1091 class DataOutputTestCase(unittest.TestCase): … … 1342 1318 u'ἔδωσαν', x.readUTFBytes, 13) 1343 1319 1344 class ClassInheritanceTestCase( unittest.TestCase):1320 class ClassInheritanceTestCase(_util.ClassCacheClearingTestCase): 1345 1321 def test_simple(self): 1346 1322 class A(object): … … 1365 1341 self.assertEquals(stream.getvalue(), '\n\x1b\x03B\x03b\x06\teggs\x03a' 1366 1342 '\x06\tspam\x01') 1367 1368 pyamf.unregister_class(A)1369 pyamf.unregister_class(B)1370 1343 1371 1344 def test_deep(self): … … 1397 1370 self.assertEquals(stream.getvalue(), '\n\x1b\x03C\x03c\x06\x07foo\x03a' 1398 1371 '\x06\tspam\x03b\x06\teggs\x01') 1399 1400 pyamf.unregister_class(A)1401 pyamf.unregister_class(B)1402 pyamf.unregister_class(C)1403 1372 1404 1373 def suite(): -
pyamf/trunk/pyamf/tests/test_basic.py
r1080 r1199 13 13 14 14 import pyamf 15 from pyamf.tests.util import ClassCacheClearingTestCase 15 16 16 17 class Spam(object): … … 121 122 self.assertTrue('dynamic' in x) 122 123 123 class ClassAliasTestCase( unittest.TestCase):124 class ClassAliasTestCase(ClassCacheClearingTestCase): 124 125 """ 125 126 Test all functionality relating to the class L{ClassAlias}. … … 213 214 self.assertEquals(x.alias, 'spam.eggs') 214 215 215 pyamf.unregister_class(Spam)216 217 216 def test_anonymous(self): 218 217 pyamf.register_class(Spam) … … 224 223 self.assertEquals(x.alias, '%s.%s' % (Spam.__module__, Spam.__name__,)) 225 224 226 pyamf.unregister_class(Spam)227 228 225 def test_external(self): 229 226 class A(object): … … 267 264 pyamf.register_class(A, metadata=['external']) 268 265 pyamf.register_class(B, metadata=['external']) 269 270 pyamf.unregister_class(A)271 pyamf.unregister_class(B)272 266 273 267 def test_get_attrs(self): … … 319 313 self._obj = Spam() 320 314 self.assertEquals(alias.getAttrs(self._obj), ['foo', 'bar']) 321 322 pyamf.unregister_class(Spam)323 315 324 316 class HelperTestCase(unittest.TestCase): … … 381 373 self.assertEquals(expected, returned) 382 374 383 class RegisterClassTestCase(unittest.TestCase): 384 def setUp(self): 385 import copy 386 387 self.copy = copy.copy(pyamf.CLASS_CACHE) 388 self.unregister = True 389 390 def tearDown(self): 391 if self.unregister: 392 pyamf.unregister_class(Spam) 393 375 class RegisterClassTestCase(ClassCacheClearingTestCase): 394 376 def test_simple(self): 395 377 self.assertTrue('spam.eggs' not in pyamf.CLASS_CACHE.keys()) … … 425 407 metadata=['blah']) 426 408 427 self.unregister = False428 429 409 def test_anonymous(self): 430 410 pyamf.register_class(Spam) … … 444 424 self.assertRaises(TypeError, pyamf.register_class, Spam, attr_func='boo', metadata=['dynamic']) 445 425 446 self.unregister = False447 448 426 def test_has_alias(self): 449 427 self.assertEquals(pyamf.has_alias(Spam), False) … … 452 430 self.assertEquals(pyamf.has_alias(Spam), True) 453 431 454 class UnregisterClassTestCase( unittest.TestCase):432 class UnregisterClassTestCase(ClassCacheClearingTestCase): 455 433 def test_klass(self): 456 434 alias = pyamf.register_class(Spam, 'spam.eggs') … … 467 445 self.assertTrue(alias not in pyamf.CLASS_CACHE) 468 446 469 class ClassLoaderTestCase(unittest.TestCase): 470 def setUp(self): 471 import copy 472 473 self.cl = copy.copy(pyamf.CLASS_LOADERS) 474 475 pyamf.CLASS_LOADERS = [] 476 477 def tearDown(self): 478 pyamf.CLASS_LOADERS = self.cl 479 447 class ClassLoaderTestCase(ClassCacheClearingTestCase): 480 448 def test_register(self): 481 449 self.assertTrue(chr not in pyamf.CLASS_LOADERS) … … 489 457 490 458 def test_unregister(self): 459 self.assertTrue(chr not in pyamf.CLASS_LOADERS) 491 460 pyamf.register_class_loader(chr) 492 461 self.assertTrue(chr in pyamf.CLASS_LOADERS) … … 508 477 pyamf.load_class('spam.eggs') 509 478 self.assertTrue('spam.eggs' in pyamf.CLASS_CACHE.keys()) 510 511 pyamf.unregister_class('spam.eggs')512 479 513 480 def test_load_unknown_class(self): … … 530 497 self.assertTrue('spam.eggs' in pyamf.CLASS_CACHE.keys()) 531 498 532 pyamf.unregister_class('spam.eggs')533 534 499 def test_load_class_bad_return(self): 535 500 def class_loader(x): … … 542 507 def test_load_class_by_module(self): 543 508 pyamf.load_class('__builtin__.tuple') 544 545 pyamf.unregister_class('__builtin__.tuple')546 509 547 510 def test_load_class_by_module_bad(self): -
pyamf/trunk/pyamf/tests/test_gateway.py
r1088 r1199 751 751 from pyamf.tests.gateway import test_django 752 752 753 suite.addTest(test_django.suite())753 #suite.addTest(test_django.suite()) 754 754 755 755 return suite -
pyamf/trunk/pyamf/tests/util.py
r699 r1199 11 11 @since: 0.1.0 12 12 """ 13 14 import unittest, copy 15 import pyamf 16 17 class ClassicSpam: 18 def __readamf__(self, input): 19 pass 20 21 def __writeamf__(self, output): 22 pass 23 24 class Spam(object): 25 """ 26 A generic object to use for object encoding 27 """ 28 def __init__(self, d={}): 29 self.__dict__.update(d) 30 31 def __readamf__(self, input): 32 pass 33 34 def __writeamf__(self, output): 35 pass 36 37 class ClassCacheClearingTestCase(unittest.TestCase): 38 def setUp(self): 39 unittest.TestCase.setUp(self) 40 41 self._class_cache = pyamf.CLASS_CACHE.copy() 42 self._class_loaders = copy.copy(pyamf.CLASS_LOADERS) 43 44 def tearDown(self): 45 unittest.TestCase.tearDown(self) 46 47 pyamf.CLASS_CACHE = self._class_cache 48 pyamf.CLASS_LOADERS = self._class_loaders 13 49 14 50 class EncoderTester(object):
