Skip to content

Commit

Permalink
Merge branch 'master' into cpyamf-amf0-772
Browse files Browse the repository at this point in the history
Conflicts:
	pyamf/amf0.py
	pyamf/amf3.py
	pyamf/tests/test_amf0.py
	pyamf/tests/test_amf3.py
	pyamf/tests/test_basic.py
	pyamf/tests/test_util.py
	setup.py
  • Loading branch information
njoyce committed Jul 27, 2010
1 parent 505890a commit 8852040
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 105 deletions.
18 changes: 18 additions & 0 deletions pyamf/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,21 @@ def isNegInf(val):
@since: 0.5
"""
return str(float(val)) == str(NegInf)



def check_for_int(x):
"""
This is a compatibility function that takes a C{float} and converts it to an
C{int} if the values are equal.
"""
try:
y = int(x)
except (OverflowError, ValueError):
pass
else:
# There is no way in AMF0 to distinguish between integers and floats
if x == x and y == x:
return y

return x
4 changes: 2 additions & 2 deletions pyamf/tests/test_amf0.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class ContextTestCase(unittest.TestCase):
def test_create(self):
c = amf0.Context()

self.assertEquals(c.objects, [])
self.assertEquals(len(c.objects), 0)
self.assertEqual(c.objects, [])
self.assertEqual(len(c.objects), 0)

def test_add(self):
x = amf0.Context()
Expand Down
102 changes: 102 additions & 0 deletions pyamf/tests/test_codec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) The PyAMF Project.
# See LICENSE.txt for details.

"""
Tests for AMF utilities.
@since: 0.1.0
"""

import unittest
import sys

import pyamf
from pyamf import codec


class TestObject(object):
def __init__(self):
self.name = 'test'


class IndexedCollectionTestCase(unittest.TestCase):
def setUp(self):
self.collection = codec.IndexedCollection()

def test_clear(self):
o = object()

self.assertEqual(sys.getrefcount(o), 2)
self.collection.append(o)
self.assertEqual(sys.getrefcount(o), 3)

self.collection.clear()

self.assertEqual(sys.getrefcount(o), 2)

def test_delete(self):
o = object()

self.assertEqual(sys.getrefcount(o), 2)
self.collection.append(o)
self.assertEqual(sys.getrefcount(o), 3)

del self.collection

self.assertEqual(sys.getrefcount(o), 2)

def test_append(self):
max = 5
for i in range(0, max):
test_obj = TestObject()

test_obj.name = i

self.assertEqual(sys.getrefcount(test_obj), 2)
self.collection.append(test_obj)
self.assertEqual(sys.getrefcount(test_obj), 3)

self.assertEqual(max, len(self.collection))

for i in range(0, max):
self.assertEqual(i, self.collection[i].name)

def test_get_reference_to(self):
test_obj = TestObject()

self.collection.append(test_obj)

self.assertEqual(sys.getrefcount(test_obj), 3)
idx = self.collection.getReferenceTo(test_obj)
self.assertEqual(sys.getrefcount(test_obj), 3)

self.assertEqual(0, idx)
self.assertEqual(-1, self.collection.getReferenceTo(TestObject()))

def test_get_by_reference(self):
test_obj = TestObject()
idx = self.collection.append(test_obj)

self.assertEqual(id(test_obj), id(self.collection.getByReference(idx)))

idx = self.collection.getReferenceTo(test_obj)

self.assertEqual(id(test_obj), id(self.collection.getByReference(idx)))
self.assertRaises(TypeError, self.collection.getByReference, 'bad ref')

self.assertEqual(None, self.collection.getByReference(74))

def test_get_by_refererence_refcount(self):
test_obj = TestObject()
idx = self.collection.append(test_obj)

o = self.collection.getByReference(idx)

self.assertIdentical(o, test_obj)

def test_array(self):
test_obj = []
idx = self.collection.append(test_obj)
self.assertEqual(id(test_obj), id(self.collection.getByReference(idx)))
91 changes: 2 additions & 89 deletions pyamf/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,93 +825,6 @@ class B(A):
self.assertEqual(util.get_class_alias(B), DummyAlias)


class TestObject(object):
def __init__(self):
self.name = 'test'


class IndexedCollectionTestCase(unittest.TestCase):
def setUp(self):
self.collection = util.IndexedCollection()


def test_clear(self):
o = object()

self.assertEqual(sys.getrefcount(o), 2)
self.collection.append(o)
self.assertEqual(sys.getrefcount(o), 3)

self.collection.clear()

self.assertEqual(sys.getrefcount(o), 2)

def test_delete(self):
o = object()

self.assertEqual(sys.getrefcount(o), 2)
self.collection.append(o)
self.assertEqual(sys.getrefcount(o), 3)

del self.collection

self.assertEqual(sys.getrefcount(o), 2)

def test_append(self):
max = 5
for i in range(0, max):
test_obj = TestObject()

test_obj.name = i

self.assertEqual(sys.getrefcount(test_obj), 2)
self.collection.append(test_obj)
self.assertEqual(sys.getrefcount(test_obj), 3)

self.assertEqual(max, len(self.collection))

for i in range(0, max):
self.assertEqual(i, self.collection[i].name)

def test_get_reference_to(self):
test_obj = TestObject()

self.collection.append(test_obj)

self.assertEqual(sys.getrefcount(test_obj), 3)
idx = self.collection.getReferenceTo(test_obj)
self.assertEqual(sys.getrefcount(test_obj), 3)

self.assertEqual(0, idx)
self.assertEqual(-1, self.collection.getReferenceTo(TestObject()))

def test_get_by_reference(self):
test_obj = TestObject()
idx = self.collection.append(test_obj)

self.assertEqual(id(test_obj), id(self.collection.getByReference(idx)))

idx = self.collection.getReferenceTo(test_obj)

self.assertEqual(id(test_obj), id(self.collection.getByReference(idx)))
self.assertRaises(TypeError, self.collection.getByReference, 'bad ref')

self.assertEqual(None, self.collection.getByReference(74))

def test_get_by_refererence_refcount(self):
test_obj = TestObject()
idx = self.collection.append(test_obj)

o = self.collection.getByReference(idx)

self.assertIdentical(o, test_obj)

def test_array(self):
test_obj = []
idx = self.collection.append(test_obj)
self.assertEqual(id(test_obj), id(self.collection.getByReference(idx)))


class IsClassSealedTestCase(unittest.TestCase):
"""
Tests for L{util.is_class_sealed}
Expand Down Expand Up @@ -1214,8 +1127,8 @@ class __amf__:
'external': None
}

self.assertEquals(util.get_class_meta(A), meta)
self.assertEquals(util.get_class_meta(B), meta)
self.assertEqual(util.get_class_meta(A), meta)
self.assertEqual(util.get_class_meta(B), meta)

def test_synonym(self):
class A:
Expand Down
20 changes: 6 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@

readme = os.path.join(base_path, 'README.txt')

# need to remove all references to imported pyamf modules, as building
# the c extensions change pyamf.util.BufferedByteStream, which blow up
# the tests (at least the first time its built which in case of the
# buildbots is always true)
for k, v in sys.modules.copy().iteritems():
if k and k.startswith('pyamf'):
del sys.modules[k]


class TestCommand(test.test):
"""
Expand Down Expand Up @@ -84,6 +76,11 @@ def get_extensions():
:since: 0.4
"""
if '--disable-ext' in sys.argv:
sys.argv.remove('--disable-ext')

return []

if sys.platform.startswith('java'):
print(80 * '*')
print('WARNING:')
Expand All @@ -94,11 +91,6 @@ def get_extensions():

return []

if '--disable-ext' in sys.argv:
sys.argv.remove('--disable-ext')

return []

ext_modules = []

ext_modules.extend(get_cpyamf_extensions())
Expand Down Expand Up @@ -135,7 +127,7 @@ def get_version():

# need to remove all references to imported pyamf modules, as building
# the c extensions change pyamf.util.BufferedByteStream, which blow up
# the tests (at least the first time its built which in case of the
# the tests (at least the first time its built which in case of the
# buildbots is always true)
for k, v in sys.modules.copy().iteritems():
if k and k.startswith('pyamf'):
Expand Down

0 comments on commit 8852040

Please sign in to comment.