[Python-checkins] cpython (2.7): Backported new tests for attribute setting of expat parser.
serhiy.storchaka
python-checkins at python.org
Mon Sep 7 21:56:30 CEST 2015
https://hg.python.org/cpython/rev/b609e391c04d
changeset: 97757:b609e391c04d
branch: 2.7
parent: 97751:d9c4b35e3fdc
user: Serhiy Storchaka <storchaka at gmail.com>
date: Mon Sep 07 22:42:12 2015 +0300
summary:
Backported new tests for attribute setting of expat parser.
files:
Lib/test/test_pyexpat.py | 53 ++++++++++++++++++---------
1 files changed, 35 insertions(+), 18 deletions(-)
diff --git a/Lib/test/test_pyexpat.py b/Lib/test/test_pyexpat.py
--- a/Lib/test/test_pyexpat.py
+++ b/Lib/test/test_pyexpat.py
@@ -13,27 +13,42 @@
class SetAttributeTest(unittest.TestCase):
def setUp(self):
self.parser = expat.ParserCreate(namespace_separator='!')
- self.set_get_pairs = [
- [0, 0],
- [1, 1],
- [2, 1],
- [0, 0],
- ]
+
+ def test_buffer_text(self):
+ self.assertIs(self.parser.buffer_text, False)
+ for x in 0, 1, 2, 0:
+ self.parser.buffer_text = x
+ self.assertIs(self.parser.buffer_text, bool(x))
+
+ def test_namespace_prefixes(self):
+ self.assertIs(self.parser.namespace_prefixes, False)
+ for x in 0, 1, 2, 0:
+ self.parser.namespace_prefixes = x
+ self.assertIs(self.parser.namespace_prefixes, bool(x))
def test_returns_unicode(self):
- for x, y in self.set_get_pairs:
+ self.assertIs(self.parser.returns_unicode, test_support.have_unicode)
+ for x in 0, 1, 2, 0:
self.parser.returns_unicode = x
- self.assertEqual(self.parser.returns_unicode, y)
+ self.assertIs(self.parser.returns_unicode, bool(x))
def test_ordered_attributes(self):
- for x, y in self.set_get_pairs:
+ self.assertIs(self.parser.ordered_attributes, False)
+ for x in 0, 1, 2, 0:
self.parser.ordered_attributes = x
- self.assertEqual(self.parser.ordered_attributes, y)
+ self.assertIs(self.parser.ordered_attributes, bool(x))
def test_specified_attributes(self):
- for x, y in self.set_get_pairs:
+ self.assertIs(self.parser.specified_attributes, False)
+ for x in 0, 1, 2, 0:
self.parser.specified_attributes = x
- self.assertEqual(self.parser.specified_attributes, y)
+ self.assertIs(self.parser.specified_attributes, bool(x))
+
+ def test_invalid_attributes(self):
+ with self.assertRaises(AttributeError):
+ self.parser.foo = 1
+ with self.assertRaises(AttributeError):
+ self.parser.foo
data = '''\
@@ -469,12 +484,14 @@
def test_wrong_size(self):
parser = expat.ParserCreate()
parser.buffer_text = 1
- def f(size):
- parser.buffer_size = size
-
- self.assertRaises(TypeError, f, sys.maxint+1)
- self.assertRaises(ValueError, f, -1)
- self.assertRaises(ValueError, f, 0)
+ with self.assertRaises(ValueError):
+ parser.buffer_size = -1
+ with self.assertRaises(ValueError):
+ parser.buffer_size = 0
+ with self.assertRaises(TypeError):
+ parser.buffer_size = 512.0
+ with self.assertRaises(TypeError):
+ parser.buffer_size = sys.maxint+1
def test_unchanged_size(self):
xml1 = ("<?xml version='1.0' encoding='iso8859'?><s>%s" % ('a' * 512))
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list