[Python-checkins] r79355 - in python/branches/py3k-jit: JIT_TODO.txt Makefile.pre.in Modules/_testcapimodule.c Unittests Unittests/DatetimeTest.cc Unittests/DictTest.cc Unittests/GetArgsTest.cc Unittests/ListTest.cc Unittests/ObjectTest.cc Unittests/README.txt Unittests/UnicodeTest.cc Unittests/pytest.h Unittests/pytest_main.cc configure configure.in
collin.winter
python-checkins at python.org
Tue Mar 23 23:57:04 CET 2010
Author: collin.winter
Date: Tue Mar 23 23:57:04 2010
New Revision: 79355
Log:
Import googletest 1.4.0 via svn:externals; port tests from _testcapimodule.c to googletest-based unittests. googletest will be used by C++ unittests for the JIT.
Reviewed at http://codereview.appspot.com/701041/show by Jeffrey Yasskin and Brett Cannon.
Added:
python/branches/py3k-jit/Unittests/
python/branches/py3k-jit/Unittests/DatetimeTest.cc
python/branches/py3k-jit/Unittests/DictTest.cc
python/branches/py3k-jit/Unittests/GetArgsTest.cc
python/branches/py3k-jit/Unittests/ListTest.cc
python/branches/py3k-jit/Unittests/ObjectTest.cc
python/branches/py3k-jit/Unittests/README.txt
python/branches/py3k-jit/Unittests/UnicodeTest.cc
python/branches/py3k-jit/Unittests/pytest.h
python/branches/py3k-jit/Unittests/pytest_main.cc
Modified:
python/branches/py3k-jit/ (props changed)
python/branches/py3k-jit/JIT_TODO.txt
python/branches/py3k-jit/Makefile.pre.in
python/branches/py3k-jit/Modules/_testcapimodule.c
python/branches/py3k-jit/configure
python/branches/py3k-jit/configure.in
Modified: python/branches/py3k-jit/JIT_TODO.txt
==============================================================================
--- python/branches/py3k-jit/JIT_TODO.txt (original)
+++ python/branches/py3k-jit/JIT_TODO.txt Tue Mar 23 23:57:04 2010
@@ -24,10 +24,6 @@
- r688
Some of these may need public discussion.
- Add support to configure/Makefile.pre.in for building against installed LLVM.
-- Add C/C++ unittests:
- - Create a Unittests/ directory.
- - Import googletest 1.4.0.
- - Start writing tests.
- Import general-purpose utility code:
- Stats.{h,cc}
- PySmallPtrSet
@@ -47,3 +43,7 @@
- r563 (r72777, r72778)
- r268 (r70672, r70673)
- r246 (r79044, r79045)
+- Add C/C++ unittests:
+ - Create a Unittests/ directory.
+ - Import googletest 1.4.0.
+ - Start writing tests.
\ No newline at end of file
Modified: python/branches/py3k-jit/Makefile.pre.in
==============================================================================
--- python/branches/py3k-jit/Makefile.pre.in (original)
+++ python/branches/py3k-jit/Makefile.pre.in Tue Mar 23 23:57:04 2010
@@ -696,6 +696,36 @@
######################################################################
+# The C/C++ unittests are optional, that is, 'make test' should still work
+# even without a C++ compiler. All commands are prefixed with - to make this
+# happen.
+
+UNITTEST_SRCS := $(LIBRARY) \
+ $(srcdir)/Unittests/DatetimeTest.cc \
+ $(srcdir)/Unittests/DictTest.cc \
+ $(srcdir)/Unittests/GetArgsTest.cc \
+ $(srcdir)/Unittests/ListTest.cc \
+ $(srcdir)/Unittests/ObjectTest.cc \
+ $(srcdir)/Unittests/UnicodeTest.cc \
+ $(srcdir)/Unittests/pytest_main.cc \
+ Unittests/googletest/gtest.o
+
+Unittests/googletest/gtest.o:
+ -$(CXX) -c $(PY_CXXFLAGS) -I$(srcdir)/Unittests/googletest \
+ -I$(srcdir)/Unittests/googletest/include -o $@ \
+ $(srcdir)/Unittests/googletest/src/gtest-all.cc
+
+# The python-config line needs to come last, or this will be broken on Linux.
+AllUnitTests: $(UNITTEST_SRCS) $(srcdir)/Unittests/*.h build_all python-config
+ -$(CXX) $(CPPFLAGS) -I$(srcdir)/Unittests/googletest/include -o $@ \
+ $(UNITTEST_SRCS) -L. $(LDFLAGS) \
+ `$(RUNSHARED) ./$(BUILDPYTHON) ./python-config --cflags --libs`
+
+
+ctest: AllUnitTests
+ -$(RUNSHARED) ./AllUnitTests
+
+
# Test the interpreter (twice, once without .pyc files, once with)
# In the past, we've had problems where bugs in the marshalling or
# elsewhere caused bytecode read from .pyc files to behave differently
@@ -707,12 +737,12 @@
TESTOPTS= -l $(EXTRATESTOPTS)
TESTPROG= $(srcdir)/Lib/test/regrtest.py
TESTPYTHON= $(RUNSHARED) ./$(BUILDPYTHON) -E -bb
-test: all platform
+test: all platform ctest
-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
-$(TESTPYTHON) $(TESTPROG) $(TESTOPTS)
$(TESTPYTHON) $(TESTPROG) $(TESTOPTS)
-testall: all platform
+testall: all platform ctest
-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
$(TESTPYTHON) $(srcdir)/Lib/compileall.py
-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
@@ -721,7 +751,7 @@
# Run the unitests for both architectures in a Universal build on OSX
# Must be run on an Intel box.
-testuniversal: all platform
+testuniversal: all platform ctest
if [ `arch` != 'i386' ];then \
echo "This can only be used on OSX/i386" ;\
exit 1 ;\
@@ -734,7 +764,7 @@
# Like testall, but with a single pass only
# run an optional script to include some information about the build environment
-buildbottest: all platform
+buildbottest: all platform ctest
- at if which pybuildbot.identify >/dev/null 2>&1; then \
pybuildbot.identify "CC='$(CC)'" "CXX='$(CXX)'"; \
fi
@@ -744,14 +774,14 @@
test_multibytecodec test_urllib2_localnet test_itertools \
test_multiprocessing test_mailbox test_socket test_poll \
test_select test_zipfile
-quicktest: all platform
+quicktest: all platform ctest
-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
-$(TESTPYTHON) $(TESTPROG) $(QUICKTESTOPTS)
$(TESTPYTHON) $(TESTPROG) $(QUICKTESTOPTS)
MEMTESTOPTS= $(QUICKTESTOPTS) -x test_dl test___all__ test_fork1 \
test_longexp
-memtest: all platform
+memtest: all platform ctest
-rm -f $(srcdir)/Lib/test/*.py[co]
-$(TESTPYTHON) $(TESTPROG) $(MEMTESTOPTS)
$(TESTPYTHON) $(TESTPROG) $(MEMTESTOPTS)
Modified: python/branches/py3k-jit/Modules/_testcapimodule.c
==============================================================================
--- python/branches/py3k-jit/Modules/_testcapimodule.c (original)
+++ python/branches/py3k-jit/Modules/_testcapimodule.c Tue Mar 23 23:57:04 2010
@@ -10,7 +10,6 @@
#include "Python.h"
#include <float.h>
#include "structmember.h"
-#include "datetime.h"
#ifdef WITH_THREAD
#include "pythread.h"
@@ -73,108 +72,6 @@
return Py_None;
}
-static PyObject*
-test_list_api(PyObject *self)
-{
- PyObject* list;
- int i;
-
- /* SF bug 132008: PyList_Reverse segfaults */
-#define NLIST 30
- list = PyList_New(NLIST);
- if (list == (PyObject*)NULL)
- return (PyObject*)NULL;
- /* list = range(NLIST) */
- for (i = 0; i < NLIST; ++i) {
- PyObject* anint = PyLong_FromLong(i);
- if (anint == (PyObject*)NULL) {
- Py_DECREF(list);
- return (PyObject*)NULL;
- }
- PyList_SET_ITEM(list, i, anint);
- }
- /* list.reverse(), via PyList_Reverse() */
- i = PyList_Reverse(list); /* should not blow up! */
- if (i != 0) {
- Py_DECREF(list);
- return (PyObject*)NULL;
- }
- /* Check that list == range(29, -1, -1) now */
- for (i = 0; i < NLIST; ++i) {
- PyObject* anint = PyList_GET_ITEM(list, i);
- if (PyLong_AS_LONG(anint) != NLIST-1-i) {
- PyErr_SetString(TestError,
- "test_list_api: reverse screwed up");
- Py_DECREF(list);
- return (PyObject*)NULL;
- }
- }
- Py_DECREF(list);
-#undef NLIST
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static int
-test_dict_inner(int count)
-{
- Py_ssize_t pos = 0, iterations = 0;
- int i;
- PyObject *dict = PyDict_New();
- PyObject *v, *k;
-
- if (dict == NULL)
- return -1;
-
- for (i = 0; i < count; i++) {
- v = PyLong_FromLong(i);
- PyDict_SetItem(dict, v, v);
- Py_DECREF(v);
- }
-
- while (PyDict_Next(dict, &pos, &k, &v)) {
- PyObject *o;
- iterations++;
-
- i = PyLong_AS_LONG(v) + 1;
- o = PyLong_FromLong(i);
- if (o == NULL)
- return -1;
- if (PyDict_SetItem(dict, k, o) < 0) {
- Py_DECREF(o);
- return -1;
- }
- Py_DECREF(o);
- }
-
- Py_DECREF(dict);
-
- if (iterations != count) {
- PyErr_SetString(
- TestError,
- "test_dict_iteration: dict iteration went wrong ");
- return -1;
- } else {
- return 0;
- }
-}
-
-static PyObject*
-test_dict_iteration(PyObject* self)
-{
- int i;
-
- for (i = 0; i < 200; i++) {
- if (test_dict_inner(i) < 0) {
- return NULL;
- }
- }
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
/* Issue #4701: Check that PyObject_Hash implicitly calls
* PyType_Ready if it hasn't already been called
@@ -778,52 +675,6 @@
return Py_None;
}
-/* Test the L code for PyArg_ParseTuple. This should deliver a PY_LONG_LONG
- for both long and int arguments. The test may leak a little memory if
- it fails.
-*/
-static PyObject *
-test_L_code(PyObject *self)
-{
- PyObject *tuple, *num;
- PY_LONG_LONG value;
-
- tuple = PyTuple_New(1);
- if (tuple == NULL)
- return NULL;
-
- num = PyLong_FromLong(42);
- if (num == NULL)
- return NULL;
-
- PyTuple_SET_ITEM(tuple, 0, num);
-
- value = -1;
- if (PyArg_ParseTuple(tuple, "L:test_L_code", &value) < 0)
- return NULL;
- if (value != 42)
- return raiseTestError("test_L_code",
- "L code returned wrong value for long 42");
-
- Py_DECREF(num);
- num = PyLong_FromLong(42);
- if (num == NULL)
- return NULL;
-
- PyTuple_SET_ITEM(tuple, 0, num);
-
- value = -1;
- if (PyArg_ParseTuple(tuple, "L:test_L_code", &value) < 0)
- return NULL;
- if (value != 42)
- return raiseTestError("test_L_code",
- "L code returned wrong value for int 42");
-
- Py_DECREF(tuple);
- Py_INCREF(Py_None);
- return Py_None;
-}
-
#endif /* ifdef HAVE_LONG_LONG */
/* Test tuple argument processing */
@@ -956,239 +807,6 @@
}
#endif
-/* This function not only tests the 'k' getargs code, but also the
- PyLong_AsUnsignedLongMask() and PyLong_AsUnsignedLongMask() functions. */
-static PyObject *
-test_k_code(PyObject *self)
-{
- PyObject *tuple, *num;
- unsigned long value;
-
- tuple = PyTuple_New(1);
- if (tuple == NULL)
- return NULL;
-
- /* a number larger than ULONG_MAX even on 64-bit platforms */
- num = PyLong_FromString("FFFFFFFFFFFFFFFFFFFFFFFF", NULL, 16);
- if (num == NULL)
- return NULL;
-
- value = PyLong_AsUnsignedLongMask(num);
- if (value != ULONG_MAX)
- return raiseTestError("test_k_code",
- "PyLong_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF");
-
- PyTuple_SET_ITEM(tuple, 0, num);
-
- value = 0;
- if (PyArg_ParseTuple(tuple, "k:test_k_code", &value) < 0)
- return NULL;
- if (value != ULONG_MAX)
- return raiseTestError("test_k_code",
- "k code returned wrong value for long 0xFFF...FFF");
-
- Py_DECREF(num);
- num = PyLong_FromString("-FFFFFFFF000000000000000042", NULL, 16);
- if (num == NULL)
- return NULL;
-
- value = PyLong_AsUnsignedLongMask(num);
- if (value != (unsigned long)-0x42)
- return raiseTestError("test_k_code",
- "PyLong_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF");
-
- PyTuple_SET_ITEM(tuple, 0, num);
-
- value = 0;
- if (PyArg_ParseTuple(tuple, "k:test_k_code", &value) < 0)
- return NULL;
- if (value != (unsigned long)-0x42)
- return raiseTestError("test_k_code",
- "k code returned wrong value for long -0xFFF..000042");
-
- Py_DECREF(tuple);
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-
-/* Test the s and z codes for PyArg_ParseTuple.
-*/
-static PyObject *
-test_s_code(PyObject *self)
-{
- /* Unicode strings should be accepted */
- PyObject *tuple, *obj;
- char *value;
-
- tuple = PyTuple_New(1);
- if (tuple == NULL)
- return NULL;
-
- obj = PyUnicode_Decode("t\xeate", strlen("t\xeate"),
- "latin-1", NULL);
- if (obj == NULL)
- return NULL;
-
- PyTuple_SET_ITEM(tuple, 0, obj);
-
- /* These two blocks used to raise a TypeError:
- * "argument must be string without null bytes, not str"
- */
- if (PyArg_ParseTuple(tuple, "s:test_s_code1", &value) < 0)
- return NULL;
-
- if (PyArg_ParseTuple(tuple, "z:test_s_code2", &value) < 0)
- return NULL;
-
- Py_DECREF(tuple);
- Py_RETURN_NONE;
-}
-
-static PyObject *
-test_bug_7414(PyObject *self)
-{
- /* Issue #7414: for PyArg_ParseTupleAndKeywords, 'C' code wasn't being
- skipped properly in skipitem() */
- int a = 0, b = 0, result;
- char *kwlist[] = {"a", "b", NULL};
- PyObject *tuple = NULL, *dict = NULL, *b_str;
-
- tuple = PyTuple_New(0);
- if (tuple == NULL)
- goto failure;
- dict = PyDict_New();
- if (dict == NULL)
- goto failure;
- b_str = PyUnicode_FromString("b");
- if (b_str == NULL)
- goto failure;
- result = PyDict_SetItemString(dict, "b", b_str);
- Py_DECREF(b_str);
- if (result < 0)
- goto failure;
-
- result = PyArg_ParseTupleAndKeywords(tuple, dict, "|CC",
- kwlist, &a, &b);
- if (!result)
- goto failure;
-
- if (a != 0)
- return raiseTestError("test_bug_7414",
- "C format code not skipped properly");
- if (b != 'b')
- return raiseTestError("test_bug_7414",
- "C format code returned wrong value");
-
- Py_DECREF(dict);
- Py_DECREF(tuple);
- Py_RETURN_NONE;
-
- failure:
- Py_XDECREF(dict);
- Py_XDECREF(tuple);
- return NULL;
-}
-
-
-static volatile int x;
-
-/* Test the u and u# codes for PyArg_ParseTuple. May leak memory in case
- of an error.
-*/
-static PyObject *
-test_u_code(PyObject *self)
-{
- PyObject *tuple, *obj;
- Py_UNICODE *value;
- Py_ssize_t len;
-
- /* issue4122: Undefined reference to _Py_ascii_whitespace on Windows */
- /* Just use the macro and check that it compiles */
- x = Py_UNICODE_ISSPACE(25);
-
- tuple = PyTuple_New(1);
- if (tuple == NULL)
- return NULL;
-
- obj = PyUnicode_Decode("test", strlen("test"),
- "ascii", NULL);
- if (obj == NULL)
- return NULL;
-
- PyTuple_SET_ITEM(tuple, 0, obj);
-
- value = 0;
- if (PyArg_ParseTuple(tuple, "u:test_u_code", &value) < 0)
- return NULL;
- if (value != PyUnicode_AS_UNICODE(obj))
- return raiseTestError("test_u_code",
- "u code returned wrong value for u'test'");
- value = 0;
- if (PyArg_ParseTuple(tuple, "u#:test_u_code", &value, &len) < 0)
- return NULL;
- if (value != PyUnicode_AS_UNICODE(obj) ||
- len != PyUnicode_GET_SIZE(obj))
- return raiseTestError("test_u_code",
- "u# code returned wrong values for u'test'");
-
- Py_DECREF(tuple);
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-/* Test Z and Z# codes for PyArg_ParseTuple */
-static PyObject *
-test_Z_code(PyObject *self)
-{
- PyObject *tuple, *obj;
- Py_UNICODE *value1, *value2;
- Py_ssize_t len1, len2;
-
- tuple = PyTuple_New(2);
- if (tuple == NULL)
- return NULL;
-
- obj = PyUnicode_FromString("test");
- PyTuple_SET_ITEM(tuple, 0, obj);
- Py_INCREF(Py_None);
- PyTuple_SET_ITEM(tuple, 1, Py_None);
-
- /* swap values on purpose */
- value1 = NULL;
- value2 = PyUnicode_AS_UNICODE(obj);
-
- /* Test Z for both values */
- if (PyArg_ParseTuple(tuple, "ZZ:test_Z_code", &value1, &value2) < 0)
- return NULL;
- if (value1 != PyUnicode_AS_UNICODE(obj))
- return raiseTestError("test_Z_code",
- "Z code returned wrong value for 'test'");
- if (value2 != NULL)
- return raiseTestError("test_Z_code",
- "Z code returned wrong value for None");
-
- value1 = NULL;
- value2 = PyUnicode_AS_UNICODE(obj);
- len1 = -1;
- len2 = -1;
-
- /* Test Z# for both values */
- if (PyArg_ParseTuple(tuple, "Z#Z#:test_Z_code", &value1, &len1,
- &value2, &len2) < 0)
- return NULL;
- if (value1 != PyUnicode_AS_UNICODE(obj) ||
- len1 != PyUnicode_GET_SIZE(obj))
- return raiseTestError("test_Z_code",
- "Z# code returned wrong values for 'test'");
- if (value2 != NULL ||
- len2 != 0)
- return raiseTestError("test_Z_code",
- "Z# code returned wrong values for None'");
-
- Py_DECREF(tuple);
- Py_RETURN_NONE;
-}
static PyObject *
test_widechar(PyObject *self)
@@ -1235,32 +853,6 @@
}
static PyObject *
-test_empty_argparse(PyObject *self)
-{
- /* Test that formats can begin with '|'. See issue #4720. */
- PyObject *tuple, *dict = NULL;
- static char *kwlist[] = {NULL};
- int result;
- tuple = PyTuple_New(0);
- if (!tuple)
- return NULL;
- if ((result = PyArg_ParseTuple(tuple, "|:test_empty_argparse")) < 0)
- goto done;
- dict = PyDict_New();
- if (!dict)
- goto done;
- result = PyArg_ParseTupleAndKeywords(tuple, dict, "|:test_empty_argparse", kwlist);
- done:
- Py_DECREF(tuple);
- Py_XDECREF(dict);
- if (result < 0)
- return NULL;
- else {
- Py_RETURN_NONE;
- }
-}
-
-static PyObject *
codec_incrementalencoder(PyObject *self, PyObject *args)
{
const char *encoding, *errors = NULL;
@@ -1323,18 +915,6 @@
return Py_None;
}
-/* Example passing NULLs to PyObject_Str(NULL). */
-
-static PyObject *
-test_null_strings(PyObject *self)
-{
- PyObject *o1 = PyObject_Str(NULL), *o2 = PyObject_Str(NULL);
- PyObject *tuple = PyTuple_Pack(2, o1, o2);
- Py_XDECREF(o1);
- Py_XDECREF(o2);
- return tuple;
-}
-
static PyObject *
raise_exception(PyObject *self, PyObject *args)
{
@@ -1363,30 +943,6 @@
}
-static int test_run_counter = 0;
-
-static PyObject *
-test_datetime_capi(PyObject *self, PyObject *args) {
- if (PyDateTimeAPI) {
- if (test_run_counter) {
- /* Probably regrtest.py -R */
- Py_RETURN_NONE;
- }
- else {
- PyErr_SetString(PyExc_AssertionError,
- "PyDateTime_CAPI somehow initialized");
- return NULL;
- }
- }
- test_run_counter++;
- PyDateTime_IMPORT;
- if (PyDateTimeAPI)
- Py_RETURN_NONE;
- else
- return NULL;
-}
-
-
#ifdef WITH_THREAD
/* test_thread_state spawns a thread of its own, and that thread releases
@@ -1553,22 +1109,6 @@
}
-static PyObject *
-test_unicode_compare_with_ascii(PyObject *self) {
- PyObject *py_s = PyUnicode_FromStringAndSize("str0円", 4);
- int result;
- if (py_s == NULL)
- return NULL;
- result = PyUnicode_CompareWithASCIIString(py_s, "str");
- Py_DECREF(py_s);
- if (!result) {
- PyErr_SetString(TestError, "Python string ending in NULL "
- "should not compare equal to c string.");
- return NULL;
- }
- Py_RETURN_NONE;
-};
-
/* This is here to provide a docstring for test_descr. */
static PyObject *
test_with_docstring(PyObject *self)
@@ -2009,24 +1549,16 @@
{"raise_exception", raise_exception, METH_VARARGS},
{"raise_memoryerror", (PyCFunction)raise_memoryerror, METH_NOARGS},
{"test_config", (PyCFunction)test_config, METH_NOARGS},
- {"test_datetime_capi", test_datetime_capi, METH_NOARGS},
- {"test_list_api", (PyCFunction)test_list_api, METH_NOARGS},
- {"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS},
{"test_lazy_hash_inheritance", (PyCFunction)test_lazy_hash_inheritance,METH_NOARGS},
{"test_broken_memoryview", (PyCFunction)test_broken_memoryview,METH_NOARGS},
{"test_long_api", (PyCFunction)test_long_api, METH_NOARGS},
{"test_long_and_overflow", (PyCFunction)test_long_and_overflow,
METH_NOARGS},
{"test_long_numbits", (PyCFunction)test_long_numbits, METH_NOARGS},
- {"test_k_code", (PyCFunction)test_k_code, METH_NOARGS},
- {"test_empty_argparse", (PyCFunction)test_empty_argparse,METH_NOARGS},
- {"test_bug_7414", (PyCFunction)test_bug_7414, METH_NOARGS},
- {"test_null_strings", (PyCFunction)test_null_strings, METH_NOARGS},
{"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS},
{"test_with_docstring", (PyCFunction)test_with_docstring, METH_NOARGS,
PyDoc_STR("This is a pretty normal docstring.")},
{"test_string_to_double", (PyCFunction)test_string_to_double, METH_NOARGS},
- {"test_unicode_compare_with_ascii", (PyCFunction)test_unicode_compare_with_ascii, METH_NOARGS},
{"test_capsule", (PyCFunction)test_capsule, METH_NOARGS},
{"getargs_tuple", getargs_tuple, METH_VARARGS},
{"getargs_keywords", (PyCFunction)getargs_keywords,
@@ -2046,15 +1578,11 @@
{"test_longlong_api", test_longlong_api, METH_NOARGS},
{"test_long_long_and_overflow",
(PyCFunction)test_long_long_and_overflow, METH_NOARGS},
- {"test_L_code", (PyCFunction)test_L_code, METH_NOARGS},
{"codec_incrementalencoder",
(PyCFunction)codec_incrementalencoder, METH_VARARGS},
{"codec_incrementaldecoder",
(PyCFunction)codec_incrementaldecoder, METH_VARARGS},
#endif
- {"test_s_code", (PyCFunction)test_s_code, METH_NOARGS},
- {"test_u_code", (PyCFunction)test_u_code, METH_NOARGS},
- {"test_Z_code", (PyCFunction)test_Z_code, METH_NOARGS},
{"test_widechar", (PyCFunction)test_widechar, METH_NOARGS},
#ifdef WITH_THREAD
{"_test_thread_state", test_thread_state, METH_VARARGS},
Added: python/branches/py3k-jit/Unittests/DatetimeTest.cc
==============================================================================
--- (empty file)
+++ python/branches/py3k-jit/Unittests/DatetimeTest.cc Tue Mar 23 23:57:04 2010
@@ -0,0 +1,22 @@
+#include "Python.h"
+#include "datetime.h"
+
+#include "gtest/gtest.h"
+#include "pytest.h"
+
+// Grab common setup/teardown routines.
+class DatetimeTest : public ::testing::Test {
+public:
+ DatetimeTest(): setup_teardown_(ImportSite) {}
+
+private:
+ PythonSetupTeardown setup_teardown_;
+};
+
+
+TEST_F(DatetimeTest, ImportCApi)
+{
+ PyDateTime_IMPORT;
+
+ EXPECT_TRUE(PyDateTimeAPI != NULL);
+}
\ No newline at end of file
Added: python/branches/py3k-jit/Unittests/DictTest.cc
==============================================================================
--- (empty file)
+++ python/branches/py3k-jit/Unittests/DictTest.cc Tue Mar 23 23:57:04 2010
@@ -0,0 +1,46 @@
+#include "Python.h"
+
+#include "gtest/gtest.h"
+#include "pytest.h"
+
+// Value-parameterized testing, gtest-style. See
+// http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide for more.
+class DictIterationTest : public ::testing::TestWithParam<int> {
+ PythonSetupTeardown setup_teardown_;
+};
+
+TEST_P(DictIterationTest, TestIteration)
+{
+ Py_ssize_t pos = 0, iterations = 0;
+ int i;
+ int count = this->GetParam();
+ PyObject *v, *k;
+
+ PyObject *dict = PyDict_New();
+ ASSERT_TRUE(dict != NULL);
+
+ for (i = 0; i < count; i++) {
+ v = PyLong_FromLong(i);
+ EXPECT_GE(PyDict_SetItem(dict, v, v), 0);
+ Py_DECREF(v);
+ }
+
+ while (PyDict_Next(dict, &pos, &k, &v)) {
+ iterations++;
+
+ i = PyLong_AS_LONG(v) + 1;
+ PyObject *o = PyLong_FromLong(i);
+ EXPECT_TRUE(o != NULL);
+ EXPECT_GE(PyDict_SetItem(dict, k, o), 0);
+
+ Py_DECREF(o);
+ }
+
+ Py_DECREF(dict);
+
+ EXPECT_EQ(count, iterations) << "dict iteration went wrong";
+}
+
+INSTANTIATE_TEST_CASE_P(DictIterationTest,
+ DictIterationTest,
+ ::testing::Range(0, 200, /* step= */ 10));
\ No newline at end of file
Added: python/branches/py3k-jit/Unittests/GetArgsTest.cc
==============================================================================
--- (empty file)
+++ python/branches/py3k-jit/Unittests/GetArgsTest.cc Tue Mar 23 23:57:04 2010
@@ -0,0 +1,221 @@
+/// Tests for Python/getargs.c.
+#include "Python.h"
+
+#include "gtest/gtest.h"
+#include "pytest.h"
+
+// Grab common setup/teardown routines.
+class GetArgsTest : public ::testing::Test {
+ PythonSetupTeardown setup_teardown_;
+};
+
+
+// Test that formats can begin with '|'. See issue #4720.
+TEST_F(GetArgsTest, EmptyFormat)
+{
+ PyObject *tuple = PyTuple_New(0);
+ PyObject *dict = PyDict_New();
+ ASSERT_TRUE(tuple != NULL);
+ ASSERT_TRUE(dict != NULL);
+
+ // Test PyArg_ParseTuple.
+ EXPECT_GE(PyArg_ParseTuple(tuple, "|:EmptyFormat"), 0);
+
+ // Same test, for PyArg_ParseTupleAndKeywords.
+ static char *kwlist[] = {NULL};
+ int result = PyArg_ParseTupleAndKeywords(tuple, dict,
+ "|:EmptyFormat",
+ kwlist);
+ EXPECT_GE(result, 0);
+
+ Py_XDECREF(tuple);
+ Py_XDECREF(dict);
+}
+
+
+// Unicode strings should be accepted for the s and z format codes.
+TEST_F(GetArgsTest, FormatCodes_s_And_z)
+{
+ PyObject *tuple, *obj;
+ char *value;
+
+ tuple = PyTuple_New(1);
+ ASSERT_TRUE(tuple != NULL);
+
+ obj = PyUnicode_Decode("t\xeate", strlen("t\xeate"), "latin-1", NULL);
+ ASSERT_TRUE(obj != NULL);
+
+ PyTuple_SET_ITEM(tuple, 0, obj);
+
+ // These two blocks used to raise a TypeError:
+ // "argument must be string without null bytes, not str"
+ EXPECT_GE(PyArg_ParseTuple(tuple, "s:FormatCodes_s_And_z", &value), 0);
+ EXPECT_GE(PyArg_ParseTuple(tuple, "z:FormatCodes_s_And_z", &value), 0);
+
+ Py_XDECREF(tuple);
+}
+
+
+// Issue #7414: for PyArg_ParseTupleAndKeywords, 'C' code wasn't being
+// skipped properly in skipitem().
+TEST_F(GetArgsTest, FormatCode_C)
+{
+ int a = 0, b = 0, result;
+ char *kwlist[] = {"a", "b", NULL};
+ PyObject *tuple = NULL, *dict = NULL, *b_str;
+
+ tuple = PyTuple_New(0);
+ dict = PyDict_New();
+ b_str = PyUnicode_FromString("b");
+ ASSERT_TRUE(tuple != NULL);
+ ASSERT_TRUE(dict != NULL);
+ ASSERT_TRUE(b_str != NULL);
+
+ result = PyDict_SetItemString(dict, "b", b_str);
+ Py_XDECREF(b_str);
+ EXPECT_GE(result, 0);
+
+ result = PyArg_ParseTupleAndKeywords(tuple, dict, "|CC", kwlist, &a, &b);
+ EXPECT_GE(result, 0);
+ EXPECT_EQ(0, a) << "C format code not skipped properly";
+ EXPECT_EQ('b', b) << "C format code returned wrong value";
+
+ Py_XDECREF(dict);
+ Py_XDECREF(tuple);
+}
+
+// Test the u and u# codes for PyArg_ParseTuple.
+TEST_F(GetArgsTest, FormatCode_u)
+{
+ PyObject *tuple, *obj;
+ Py_UNICODE *value;
+ Py_ssize_t len;
+
+ tuple = PyTuple_New(1);
+ ASSERT_TRUE(tuple != NULL);
+
+ obj = PyUnicode_Decode("test", strlen("test"), "ascii", NULL);
+ ASSERT_TRUE(obj != NULL);
+
+ PyTuple_SET_ITEM(tuple, 0, obj);
+
+ value = 0;
+ EXPECT_GE(PyArg_ParseTuple(tuple, "u:FormatCode_u", &value), 0);
+ EXPECT_EQ(value, PyUnicode_AS_UNICODE(obj));
+
+ value = 0;
+ EXPECT_GE(PyArg_ParseTuple(tuple, "u#:FormatCode_u", &value, &len), 0);
+ EXPECT_EQ(value, PyUnicode_AS_UNICODE(obj));
+ EXPECT_EQ(len, PyUnicode_GET_SIZE(obj));
+
+ Py_DECREF(tuple);
+}
+
+// Test the L code for PyArg_ParseTuple. This should deliver a PY_LONG_LONG
+// for both long and int arguments.
+TEST_F(GetArgsTest, FormatCode_L)
+{
+ PY_LONG_LONG value;
+
+ PyObject *tuple = PyTuple_New(1);
+ ASSERT_TRUE(tuple != NULL);
+
+ PyObject *num = PyLong_FromLong(42);
+ ASSERT_TRUE(num != NULL);
+
+ PyTuple_SET_ITEM(tuple, 0, num);
+
+ value = -1;
+ EXPECT_GE(PyArg_ParseTuple(tuple, "L:FormatCode_L", &value), 0);
+ EXPECT_EQ(42, value) << "L code returned wrong value for long 42";
+
+ Py_DECREF(num);
+ num = PyLong_FromLong(42);
+ EXPECT_TRUE(num != NULL);
+
+ PyTuple_SET_ITEM(tuple, 0, num);
+
+ value = -1;
+ EXPECT_GE(PyArg_ParseTuple(tuple, "L:FormatCode_L", &value), 0);
+ EXPECT_EQ(42, value) << "L code returned wrong value for int 42";
+
+ Py_DECREF(tuple);
+}
+
+// Test the K code for PyArg_ParseTuple.
+TEST_F(GetArgsTest, FormatCode_K)
+{
+ unsigned long value;
+
+ PyObject *tuple = PyTuple_New(1);
+ ASSERT_TRUE(tuple != NULL);
+
+ // A number larger than ULONG_MAX even on 64-bit platforms.
+ PyObject *num = PyLong_FromString("FFFFFFFFFFFFFFFFFFFFFFFF", NULL, 16);
+ ASSERT_TRUE(num != NULL);
+
+ value = PyLong_AsUnsignedLongMask(num);
+ EXPECT_EQ(ULONG_MAX, value) << "wrong value for long 0xFFF...FFF";
+
+ PyTuple_SET_ITEM(tuple, 0, num);
+
+ value = 0;
+ EXPECT_GE(PyArg_ParseTuple(tuple, "k:FormatCode_k", &value), 0);
+ EXPECT_EQ(ULONG_MAX, value) << "k code gave wrong value for 0xFFF...FFF";
+
+ Py_DECREF(num);
+ num = PyLong_FromString("-FFFFFFFF000000000000000042", NULL, 16);
+ ASSERT_TRUE(num != NULL);
+
+ value = PyLong_AsUnsignedLongMask(num);
+ EXPECT_EQ((unsigned long)-0x42, value)
+ << "wrong value for long -0xFFF..000042";
+
+ PyTuple_SET_ITEM(tuple, 0, num);
+
+ value = 0;
+ EXPECT_GE(PyArg_ParseTuple(tuple, "k:FormatCode_k", &value), 0);
+ EXPECT_EQ((unsigned long)-0x42, value)
+ << "k code returned wrong value for long -0xFFF..000042";
+
+ Py_DECREF(tuple);
+}
+
+
+// Test the Z and Z# codes for PyArg_ParseTuple.
+TEST_F(GetArgsTest, FormatCode_Z)
+{
+ PyObject *tuple = PyTuple_New(2);
+ ASSERT_TRUE(tuple != NULL);
+
+ PyObject *obj = PyUnicode_FromString("test");
+ PyTuple_SET_ITEM(tuple, 0, obj);
+ Py_INCREF(Py_None);
+ PyTuple_SET_ITEM(tuple, 1, Py_None);
+
+ // Swap values on purpose.
+ Py_UNICODE *value1 = NULL;
+ Py_UNICODE *value2 = PyUnicode_AS_UNICODE(obj);
+
+ /* Test Z for both values. */
+ EXPECT_GE(PyArg_ParseTuple(tuple, "ZZ:FormatCode_Z", &value1, &value2), 0);
+ EXPECT_EQ(value1, PyUnicode_AS_UNICODE(obj))
+ << "Z code returned wrong value for 'test'";
+ EXPECT_TRUE(value2 == NULL) << "Z code returned wrong value for None";
+
+ value1 = NULL;
+ value2 = PyUnicode_AS_UNICODE(obj);
+ Py_ssize_t len1 = -1;
+ Py_ssize_t len2 = -1;
+
+ // Test Z# for both values.
+ EXPECT_GE(PyArg_ParseTuple(tuple, "Z#Z#:FormatCode_Z", &value1, &len1,
+ &value2, &len2), 0);
+ EXPECT_EQ(PyUnicode_AS_UNICODE(obj), value1);
+ EXPECT_EQ(PyUnicode_GET_SIZE(obj), len1);
+ EXPECT_TRUE(value2 == NULL);
+ EXPECT_EQ(0, len2);
+
+ Py_DECREF(tuple);
+
+}
\ No newline at end of file
Added: python/branches/py3k-jit/Unittests/ListTest.cc
==============================================================================
--- (empty file)
+++ python/branches/py3k-jit/Unittests/ListTest.cc Tue Mar 23 23:57:04 2010
@@ -0,0 +1,39 @@
+#include "Python.h"
+
+#include "gtest/gtest.h"
+#include "pytest.h"
+
+// Grab common setup/teardown routines.
+class ListTest : public ::testing::Test {
+ PythonSetupTeardown setup_teardown_;
+};
+
+// Regression test for http://bugs.python.org/issue232008 (segfault in
+// PyList_Reverse).
+TEST_F(ListTest, Bug232008)
+{
+ int i;
+ const int list_size = 30;
+
+ PyObject *list = PyList_New(list_size);
+ ASSERT_TRUE(list != NULL);
+
+ // list = range(list_size)
+ for (i = 0; i < list_size; ++i) {
+ PyObject *an_int = PyLong_FromLong(i);
+ EXPECT_TRUE(an_int != NULL);
+ PyList_SET_ITEM(list, i, an_int);
+ }
+
+ // list.reverse(), via PyList_Reverse().
+ i = PyList_Reverse(list); // Should not blow up!
+ EXPECT_EQ(0, i);
+
+ // Check that list == range(29, -1, -1) now.
+ for (i = 0; i < list_size; ++i) {
+ PyObject *an_int = PyList_GET_ITEM(list, i);
+ EXPECT_EQ(list_size - 1 - i, PyLong_AS_LONG(an_int))
+ << "reverse screwed up";
+ }
+ Py_DECREF(list);
+}
Added: python/branches/py3k-jit/Unittests/ObjectTest.cc
==============================================================================
--- (empty file)
+++ python/branches/py3k-jit/Unittests/ObjectTest.cc Tue Mar 23 23:57:04 2010
@@ -0,0 +1,22 @@
+/// Tests for code in Objects/object.c.
+#include "Python.h"
+
+#include "gtest/gtest.h"
+#include "pytest.h"
+
+// Grab common setup/teardown routines.
+class ObjectTest : public ::testing::Test {
+ PythonSetupTeardown setup_teardown_;
+};
+
+
+// Test passing NULL to PyObject_Str. This should produce a "<NULL>" string.
+TEST_F(ObjectTest, PyObject_Str_NullArg)
+{
+ PyObject *str = PyObject_Str(NULL);
+ ASSERT_TRUE(str != NULL);
+
+ EXPECT_EQ(0, PyUnicode_CompareWithASCIIString(str, "<NULL>"));
+
+ Py_DECREF(str);
+}
\ No newline at end of file
Added: python/branches/py3k-jit/Unittests/README.txt
==============================================================================
--- (empty file)
+++ python/branches/py3k-jit/Unittests/README.txt Tue Mar 23 23:57:04 2010
@@ -0,0 +1,16 @@
+### README.txt for the Unittests/ directory.
+
+This directory contains C and C++ unittests implemented using Google's
+open-source C++ testing framework, googletest. googletest is bundled with
+Python via Subversion's svn:externals property.
+
+To run the C unittests, run `make ctest`. This target is run as part of
+`make test` and other testing targets. The C unittests will not be run if no
+C++ compiler is available.
+
+
+googletest site: http://code.google.com/p/googletest/
+
+Documentation:
+- Basic tutorial: http://code.google.com/p/googletest/wiki/GoogleTestPrimer
+- Advanced: http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide
\ No newline at end of file
Added: python/branches/py3k-jit/Unittests/UnicodeTest.cc
==============================================================================
--- (empty file)
+++ python/branches/py3k-jit/Unittests/UnicodeTest.cc Tue Mar 23 23:57:04 2010
@@ -0,0 +1,33 @@
+/// Tests for Python's unicode support.
+#include "Python.h"
+
+#include "gtest/gtest.h"
+#include "pytest.h"
+
+// Grab common setup/teardown routines.
+class UnicodeTest : public ::testing::Test {
+ PythonSetupTeardown setup_teardown_;
+};
+
+
+// issue4122: Undefined reference to _Py_ascii_whitespace on Windows.
+// Just use the macro and check that it compiles.
+TEST_F(UnicodeTest, IsSpace)
+{
+ EXPECT_FALSE(Py_UNICODE_ISSPACE(25));
+}
+
+
+// Python strings ending with '0円' should not be equivalent to their C
+// counterparts in PyUnicode_CompareWithASCIIString.
+TEST_F(UnicodeTest, CompareWithAscii)
+{
+ PyObject *py_s = PyUnicode_FromStringAndSize("str0円", 4);
+ ASSERT_TRUE(py_s != NULL);
+
+ EXPECT_NE(0, PyUnicode_CompareWithASCIIString(py_s, "str"))
+ << "Python string ending in NULL "
+ "should not compare equal to c string.";
+
+ Py_DECREF(py_s);
+}
\ No newline at end of file
Added: python/branches/py3k-jit/Unittests/pytest.h
==============================================================================
--- (empty file)
+++ python/branches/py3k-jit/Unittests/pytest.h Tue Mar 23 23:57:04 2010
@@ -0,0 +1,38 @@
+#ifndef UNITTESTS_PYTEST_H_
+#define UNITTESTS_PYTEST_H_
+
+#include "Python.h"
+
+typedef enum {
+ ImportSite = 0, // Import site.py (the default).
+ NoSite // Do not import site.py (python -S).
+} NoSiteFlag;
+
+/// RAII-style class for common Python setup/teardown test fixture routines.
+/// By default, PythonSetupTeardown will not import site.py (like Python's -S
+/// option). If you need site.py, use PythonSetupTeardown(ImportSite).
+class PythonSetupTeardown {
+public:
+ PythonSetupTeardown(NoSiteFlag no_site_flag = NoSite)
+ {
+ this->orig_no_site_flag_ = Py_NoSiteFlag;
+ Py_NoSiteFlag = no_site_flag;
+ Py_Initialize();
+ }
+
+ ~PythonSetupTeardown()
+ {
+ if (PyErr_Occurred()) {
+ PyErr_Print();
+ PyErr_Clear();
+ }
+ Py_Finalize();
+ Py_NoSiteFlag = this->orig_no_site_flag_;
+ }
+
+private:
+ // Original value of Py_NoSiteFlag.
+ bool orig_no_site_flag_;
+};
+
+#endif
\ No newline at end of file
Added: python/branches/py3k-jit/Unittests/pytest_main.cc
==============================================================================
--- (empty file)
+++ python/branches/py3k-jit/Unittests/pytest_main.cc Tue Mar 23 23:57:04 2010
@@ -0,0 +1,45 @@
+// Copyright 2006, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Modified for Python to pass the name of this program.
+
+#include <iostream>
+
+#include <gtest/gtest.h>
+
+#include "Python.h"
+
+int main(int argc, char **argv) {
+ std::cout << "Running main() from gtest_main.cc\n";
+
+ Py_SetProgramName((wchar_t *)argv[0]);
+
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
Modified: python/branches/py3k-jit/configure
==============================================================================
--- python/branches/py3k-jit/configure (original)
+++ python/branches/py3k-jit/configure Tue Mar 23 23:57:04 2010
@@ -1,5 +1,5 @@
#! /bin/sh
-# From configure.in Revision: 78821 .
+# From configure.in Revision: 78998 .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.61 for python 3.2.
#
@@ -27311,12 +27311,12 @@
done
-SRCDIRS="Parser Grammar Objects Python Modules Mac"
+SRCDIRS="Parser Grammar Objects Python Modules Mac Unittests Unittests/googletest"
{ echo "$as_me:$LINENO: checking for build directories" >&5
echo $ECHO_N "checking for build directories... $ECHO_C" >&6; }
for dir in $SRCDIRS; do
if test ! -d $dir; then
- mkdir $dir
+ mkdir -p $dir
fi
done
{ echo "$as_me:$LINENO: result: done" >&5
Modified: python/branches/py3k-jit/configure.in
==============================================================================
--- python/branches/py3k-jit/configure.in (original)
+++ python/branches/py3k-jit/configure.in Tue Mar 23 23:57:04 2010
@@ -4078,11 +4078,11 @@
done
AC_SUBST(SRCDIRS)
-SRCDIRS="Parser Grammar Objects Python Modules Mac"
+SRCDIRS="Parser Grammar Objects Python Modules Mac Unittests Unittests/googletest"
AC_MSG_CHECKING(for build directories)
for dir in $SRCDIRS; do
if test ! -d $dir; then
- mkdir $dir
+ mkdir -p $dir
fi
done
AC_MSG_RESULT(done)
More information about the Python-checkins
mailing list