[Python-checkins] r54133 - sandbox/trunk/pep3101/test_simpleformat.py sandbox/trunk/pep3101/unicodeformat.c
patrick.maupin
python-checkins at python.org
Mon Mar 5 05:02:13 CET 2007
Author: patrick.maupin
Date: Mon Mar 5 05:02:08 2007
New Revision: 54133
Modified:
sandbox/trunk/pep3101/test_simpleformat.py
sandbox/trunk/pep3101/unicodeformat.c
Log:
Added tests for {!useall} and made them pass.
Also, removed call that was failing for Eric under Python 2.3.
Modified: sandbox/trunk/pep3101/test_simpleformat.py
==============================================================================
--- sandbox/trunk/pep3101/test_simpleformat.py (original)
+++ sandbox/trunk/pep3101/test_simpleformat.py Mon Mar 5 05:02:08 2007
@@ -273,6 +273,23 @@
pep3101.format("{foo} {global3} {global1}"),
"27 50 10")
+ def test_check_unused(self):
+ mydict = dict(foo=1, foo2=1)
+ bar = 3
+ bar2 = 4
+ s = '{0} {1} {foo} {bar}'
+ s2 = '{!useall}' + s
+ self.formatEquals('a b 1 3', s, 'a', 'b', bar=bar, _dict=mydict)
+ self.formatEquals('a b 1 3', s2, 'a', 'b', bar=bar, _dict=mydict)
+ self.formatEquals('a b 1 3', s, 'a', 'b', 3, bar=bar, _dict=mydict)
+ self.formatRaises(ValueError, s2, 'a', 'b', 3, bar=bar, _dict=mydict)
+ self.formatEquals('a b 1 3', s, 'a', 'b', bar=bar, _dict=mydict, sam=27)
+ self.formatRaises(ValueError, s2, 'a', 'b', bar=bar, _dict=mydict, sam=27)
+ self.formatEquals('a b 1 3', s, 'a', 'b', bar=bar, foo=1)
+ self.formatEquals('a b 1 3', s, 'a', 'b', bar=bar, foo=1)
+ self.formatEquals('a b 1 3', s, 'a', 'b', bar=bar, foo=1, sam=27)
+ self.formatRaises(ValueError, s2, 'a', 'b', bar=bar, foo=1, sam=27)
+
def test_main():
test_support.run_unittest(FormatTest)
Modified: sandbox/trunk/pep3101/unicodeformat.c
==============================================================================
--- sandbox/trunk/pep3101/unicodeformat.c (original)
+++ sandbox/trunk/pep3101/unicodeformat.c Mon Mar 5 05:02:08 2007
@@ -63,7 +63,6 @@
#define PySet_Discard PyDict_DelItem
#define PySet_New PyDict_Copy
#define PySet_GET_SIZE PyDict_Size
-#define PySet_Contains PyDict_Contains
#endif
@@ -1703,6 +1702,7 @@
case '#':
return get_specifier(fs, 0);
case '!':
+ fs->fmtstr.ptr++;
return process_metadata(fs);
default: {
PyObject *myobj = get_field_and_spec(fs);
@@ -1894,7 +1894,7 @@
"_hook",
NULL};
- int num_unused, i, contains;
+ int i, num_unused;
PyObject *used = fs->keyword_arg_set;
if (result != NULL) {
num_unused = fs->positional_arg_set;
@@ -1903,13 +1903,13 @@
i = 0;
while (num_unused && (ignore[i] != NULL)) {
PyObject *temp= PyString_FromString(ignore[i++]);
- if ((temp==NULL) ||
- ((contains = PySet_Contains(used, temp)) < 0)) {
+ if (temp==NULL) {
Py_DECREF(used);
- Py_XDECREF(temp);
return NULL;
}
- num_unused -= contains;
+ PySet_Discard(used, temp);
+ Py_DECREF(temp);
+ num_unused = PySet_GET_SIZE(used);
}
}
if (num_unused) {
More information about the Python-checkins
mailing list