diff --git a/build/filemgr.py b/build/filemgr.py index 690956db..5e32460e 100644 --- a/build/filemgr.py +++ b/build/filemgr.py @@ -56,9 +56,9 @@ bpl_exa + "/vector_wrapper.h", bpl_exa + "/richcmp1.cpp", bpl_exa + "/richcmp2.cpp", bpl_exa + "/richcmp3.cpp", -bpl_exa + "/tst_richcmp1.py", -bpl_exa + "/tst_richcmp2.py", -bpl_exa + "/tst_richcmp3.py", +bpl_exa + "/test_richcmp1.py", +bpl_exa + "/test_richcmp2.py", +bpl_exa + "/test_richcmp3.py", ) defs = ( diff --git a/build/irix_CC.mak b/build/irix_CC.mak index 3b0badb7..1fbe3388 100644 --- a/build/irix_CC.mak +++ b/build/irix_CC.mak @@ -130,6 +130,9 @@ test: $(PYEXE) test_pickle2.py $(PYEXE) test_pickle3.py $(PYEXE) test_cross_module.py + $(PYEXE) test_richcmp1.py + $(PYEXE) test_richcmp2.py + $(PYEXE) test_richcmp3.py clean: rm -f $(OBJ) libboost_python.a libboost_python.a.input diff --git a/build/linux_gcc.mak b/build/linux_gcc.mak index 4eae38cf..3fe407a0 100644 --- a/build/linux_gcc.mak +++ b/build/linux_gcc.mak @@ -131,6 +131,9 @@ test: $(PYEXE) test_pickle2.py $(PYEXE) test_pickle3.py $(PYEXE) test_cross_module.py + $(PYEXE) test_richcmp1.py + $(PYEXE) test_richcmp2.py + $(PYEXE) test_richcmp3.py clean: rm -f $(OBJ) libboost_python.a libboost_python.a.input diff --git a/build/mingw32.mak b/build/mingw32.mak index fa22fca6..0b0fbe2a 100644 --- a/build/mingw32.mak +++ b/build/mingw32.mak @@ -182,6 +182,9 @@ test: $(PYEXE) test_pickle2.py $(PYEXE) test_pickle3.py $(PYEXE) test_cross_module.py + $(PYEXE) test_richcmp1.py + $(PYEXE) test_richcmp2.py + $(PYEXE) test_richcmp3.py clean: del *.o diff --git a/build/tru64_cxx.mak b/build/tru64_cxx.mak index 63251819..8f3d3abf 100644 --- a/build/tru64_cxx.mak +++ b/build/tru64_cxx.mak @@ -145,6 +145,9 @@ test: $(PYEXE) test_pickle2.py $(PYEXE) test_pickle3.py $(PYEXE) test_cross_module.py + $(PYEXE) test_richcmp1.py + $(PYEXE) test_richcmp2.py + $(PYEXE) test_richcmp3.py clean: rm -f $(OBJ) libboost_python.a libboost_python.a.input diff --git a/build/vc60.mak b/build/vc60.mak index b1718b9a..f545015b 100644 --- a/build/vc60.mak +++ b/build/vc60.mak @@ -114,14 +114,17 @@ test: $(PYEXE) test_pickle2.py $(PYEXE) test_pickle3.py $(PYEXE) test_cross_module.py --broken-auto-ptr + $(PYEXE) test_richcmp1.py + $(PYEXE) test_richcmp2.py + $(PYEXE) test_richcmp3.py clean: - del *.obj - del *.lib - del *.exp - del *.idb - del *.pyd - del *.pyc + -del *.obj + -del *.lib + -del *.exp + -del *.idb + -del *.pyd + -del *.pyc softlinks: python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) softlinks diff --git a/example/richcmp1.cpp b/example/richcmp1.cpp index 4a9cafff..4dd74e1b 100644 --- a/example/richcmp1.cpp +++ b/example/richcmp1.cpp @@ -52,7 +52,7 @@ namespace vects { # undef VECTOR_BINARY_OPERATORS }; -} // namespace vects +} // namespace namespace { diff --git a/example/richcmp2.cpp b/example/richcmp2.cpp index a4d0005a..213852b3 100644 --- a/example/richcmp2.cpp +++ b/example/richcmp2.cpp @@ -24,11 +24,13 @@ namespace { int m_code; }; +#if PYTHON_API_VERSION >= 1010 boost::python::ref NotImplemented(const code&, const code&) { return boost::python::ref(Py_NotImplemented, boost::python::ref::increment_count); } +#endif } namespace { @@ -41,10 +43,12 @@ namespace { py_code.def(boost::python::constructor()); py_code.def(boost::python::operators<( boost::python::op_eq | boost::python::op_ne)>()); +#if PYTHON_API_VERSION >= 1010 py_code.def(NotImplemented, "__lt__"); py_code.def(NotImplemented, "__le__"); py_code.def(NotImplemented, "__gt__"); py_code.def(NotImplemented, "__ge__"); +#endif } } // namespace diff --git a/example/test_richcmp1.py b/example/test_richcmp1.py new file mode 100644 index 00000000..d25fcc9c --- /dev/null +++ b/example/test_richcmp1.py @@ -0,0 +1,40 @@ +r'''>>> import richcmp1 + >>> d1 = richcmp1.dvect((0, 1, 3, 3, 6, 7)) + >>> d2 = richcmp1.dvect((1, 2, 3, 4, 5, 6)) + >>> print d1.as_tuple() + (0.0, 1.0, 3.0, 3.0, 6.0, 7.0) + >>> print d2.as_tuple() + (1.0, 2.0, 3.0, 4.0, 5.0, 6.0) + >>> print (d1 < d2).as_tuple() + (1, 1, 0, 1, 0, 0) + >>> print (d1 <= d2).as_tuple() + (1, 1, 1, 1, 0, 0) + >>> print (d1 == d2).as_tuple() + (0, 0, 1, 0, 0, 0) + >>> print (d1 != d2).as_tuple() + (1, 1, 0, 1, 1, 1) + >>> print (d1 > d2).as_tuple() + (0, 0, 0, 0, 1, 1) + >>> print (d1 >= d2).as_tuple() + (0, 0, 1, 0, 1, 1) + >>> try: d1 == richcmp1.dvect((1, 2, 3, 4, 5)) + ... except ValueError, e: print str(e) + ... + vectors have different sizes +''' + +def run(args = None): + if args is not None: + import sys + sys.argv = args + import doctest, test_richcmp1 + return doctest.testmod(test_richcmp1) + +if __name__ == '__main__': + import sys + if ( hasattr(sys, 'version_info') + and ( (sys.version_info[0] == 2 and sys.version_info[1] >= 1) + or sys.version_info[0] > 2)): + sys.exit(run()[0]) + else: + print "Python version 2.1 or higher required. Test skipped." diff --git a/example/test_richcmp2.py b/example/test_richcmp2.py new file mode 100644 index 00000000..859928c3 --- /dev/null +++ b/example/test_richcmp2.py @@ -0,0 +1,41 @@ +r'''>>> import richcmp2 + >>> c1 = richcmp2.code(1) + >>> c2 = richcmp2.code(2) + >>> c3 = richcmp2.code(2) + >>> print c1 == c2 + 0 + >>> print c1 != c2 + 1 + >>> print c2 == c3 + 1 + >>> print c2 != c3 + 0 + >>> print c1 < c2 + 1 + >>> print c1 <= c2 + 1 + >>> print c1 == c2 + 0 + >>> print c1 != c2 + 1 + >>> print c1 > c2 + 0 + >>> print c1 >= c2 + 0 +''' + +def run(args = None): + if args is not None: + import sys + sys.argv = args + import doctest, test_richcmp1 + return doctest.testmod(test_richcmp1) + +if __name__ == '__main__': + import sys + if ( hasattr(sys, 'version_info') + and ( (sys.version_info[0] == 2 and sys.version_info[1] >= 1) + or sys.version_info[0] > 2)): + sys.exit(run()[0]) + else: + print "Python version 2.1 or higher required. Test skipped." diff --git a/example/test_richcmp3.py b/example/test_richcmp3.py new file mode 100644 index 00000000..a769af17 --- /dev/null +++ b/example/test_richcmp3.py @@ -0,0 +1,77 @@ +r'''>>> import richcmp3 + >>> + >>> iv = richcmp3.ivect((1,2,3,4,5)) + >>> print iv.as_tuple() + (1, 2, 3, 4, 5) + >>> dv = richcmp3.dvect((2,-2,3,8,-5)) + >>> print dv.as_tuple() + (2.0, -2.0, 3.0, 8.0, -5.0) + >>> + >>> print (iv+dv).as_tuple() + (3.0, 0.0, 6.0, 12.0, 0.0) + >>> print (iv+3).as_tuple() + (4, 5, 6, 7, 8) + >>> print (3+iv).as_tuple() + (4, 5, 6, 7, 8) + >>> + >>> print "vect vs. vect Comparisons:" + vect vs. vect Comparisons: + >>> print (iv < dv).as_tuple() + (1, 0, 0, 1, 0) + >>> print (iv <= dv).as_tuple() + (1, 0, 1, 1, 0) + >>> print (iv == dv).as_tuple() + (0, 0, 1, 0, 0) + >>> print (iv != dv).as_tuple() + (1, 1, 0, 1, 1) + >>> print (iv > dv).as_tuple() + (0, 1, 0, 0, 1) + >>> print (iv >= dv).as_tuple() + (0, 1, 1, 0, 1) + >>> + >>> print "vect vs. scalar Comparisons:" + vect vs. scalar Comparisons: + >>> print (iv < 3).as_tuple() + (1, 1, 0, 0, 0) + >>> print (iv <= 3).as_tuple() + (1, 1, 1, 0, 0) + >>> print (iv == 3).as_tuple() + (0, 0, 1, 0, 0) + >>> print (iv != 3).as_tuple() + (1, 1, 0, 1, 1) + >>> print (iv > 3).as_tuple() + (0, 0, 0, 1, 1) + >>> print (iv >= 3).as_tuple() + (0, 0, 1, 1, 1) + >>> + >>> print "scalar vs. vect Comparisons:" + scalar vs. vect Comparisons: + >>> print (3 < iv).as_tuple() + (0, 0, 0, 1, 1) + >>> print (3 <= iv).as_tuple() + (0, 0, 1, 1, 1) + >>> print (3 == iv).as_tuple() + (0, 0, 1, 0, 0) + >>> print (3 != iv).as_tuple() + (1, 1, 0, 1, 1) + >>> print (3 > iv).as_tuple() + (1, 1, 0, 0, 0) + >>> print (3 >= iv).as_tuple() + (1, 1, 1, 0, 0) +''' + +def run(args = None): + if args is not None: + import sys + sys.argv = args + import doctest, test_richcmp3 + return doctest.testmod(test_richcmp3) + +if __name__ == '__main__': + import sys + if ( hasattr(sys, 'version_info') + and ( (sys.version_info[0] == 2 and sys.version_info[1] >= 1) + or sys.version_info[0] > 2)): + sys.exit(run()[0]) + else: + print "Python version 2.1 or higher required. Test skipped." diff --git a/example/tst_richcmp1.py b/example/tst_richcmp1.py deleted file mode 100644 index 53264afe..00000000 --- a/example/tst_richcmp1.py +++ /dev/null @@ -1,13 +0,0 @@ -import richcmp1 -d1 = richcmp1.dvect((0, 1, 3, 3, 6, 7)) -d2 = richcmp1.dvect((1, 2, 3, 4, 5, 6)) -print d1.as_tuple() -print d2.as_tuple() -print (d1 < d2).as_tuple() -print (d1 <= d2).as_tuple() -print (d1 == d2).as_tuple() -print (d1 != d2).as_tuple() -print (d1 > d2).as_tuple() -print (d1 >= d2).as_tuple() -try: d1 == richcmp1.dvect((1, 2, 3, 4, 5)) -except ValueError, e: print str(e) diff --git a/example/tst_richcmp2.py b/example/tst_richcmp2.py deleted file mode 100644 index 77a2ff53..00000000 --- a/example/tst_richcmp2.py +++ /dev/null @@ -1,14 +0,0 @@ -import richcmp2 -c1 = richcmp2.code(1) -c2 = richcmp2.code(2) -c3 = richcmp2.code(2) -print c1 == c2 -print c1 != c2 -print c2 == c3 -print c2 != c3 -print c1 < c2 -print c1 <= c2 -print c1 == c2 -print c1 != c2 -print c1 > c2 -print c1 >= c2 diff --git a/example/tst_richcmp3.py b/example/tst_richcmp3.py deleted file mode 100644 index 2c13fd19..00000000 --- a/example/tst_richcmp3.py +++ /dev/null @@ -1,60 +0,0 @@ -import richcmp3,sys -global iv,dv -iv = richcmp3.ivect((1,2,3,4,5)) -print iv.as_tuple() -dv = richcmp3.dvect((2,-2,3,8,-5)) -print dv.as_tuple() - -print (iv+dv).as_tuple() -print (iv+3).as_tuple() -print (3+iv).as_tuple() - -def python_2_1(): - print "\nvect vs. vect Comparisons:" - print (iv < dv).as_tuple() - print (iv <= dv).as_tuple() - print (iv == dv).as_tuple() - print (iv != dv).as_tuple() - print (iv > dv).as_tuple() - print (iv >= dv).as_tuple() - - print "\nvect vs. scalar Comparisons:" - print (iv < 3).as_tuple() - print (iv <= 3).as_tuple() - print (iv == 3).as_tuple() - print (iv != 3).as_tuple() - print (iv > 3).as_tuple() - print (iv >= 3).as_tuple() - - print "\nscalar vs. vect Comparisons:" - print (3 < iv).as_tuple() - print (3 <= iv).as_tuple() - print (3 == iv).as_tuple() - print (3 != iv).as_tuple() - print (3 > iv).as_tuple() - print (3 >= iv).as_tuple() - -def python_pre_2_1(): - print "\nvect vs. vect Comparisons:" - print (iv.__lt__(dv)).as_tuple() - print (iv.__le__(dv)).as_tuple() - print (iv.__eq__(dv)).as_tuple() - print (iv.__ne__(dv)).as_tuple() - print (iv.__gt__(dv)).as_tuple() - print (iv.__ge__(dv)).as_tuple() - - print "\nvect vs. scalar Comparisons:" - print (iv.__lt__(3)).as_tuple() - print (iv.__le__(3)).as_tuple() - print (iv.__eq__(3)).as_tuple() - print (iv.__ne__(3)).as_tuple() - print (iv.__gt__(3)).as_tuple() - print (iv.__ge__(3)).as_tuple() - - print "\nscalar vs. vect Comparisons:" - -if __name__=='__main__': - if sys.version_info[0]>=2 and sys.version_info[1]>=1: - python_2_1() - else: - python_pre_2_1()