2
0
mirror of https://github.com/boostorg/python.git synced 2026-02-23 03:52:16 +00:00

This commit was manufactured by cvs2svn to create tag

'merged_to_RC_1_30_0'.

[SVN r19627]
This commit is contained in:
nobody
2003-08-16 01:05:44 +00:00
parent b8028729eb
commit f5af86616d
113 changed files with 595 additions and 4935 deletions

View File

@@ -1,8 +1,3 @@
*.pyc
*.exp
*.lib
*.obj
*.arg
*.dll
*.cpp
.sconsign

View File

@@ -1,59 +0,0 @@
import glob
import sys
import os
# constants
if sys.platform == 'win32':
BOOST_ROOT = 'D:/Programming/Libraries/boost-cvs'
STLPORT_ROOT = 'D:/Programming/Libraries/stlport-4.5.3'
PYTHON_ROOT = 'C:/Python'
if BOOST_ROOT:
BOOST_INCLUDE = BOOST_ROOT + '/boost'
BOOST_LIB = BOOST_ROOT + '/lib'
if STLPORT_ROOT:
STLPORT_INCLUDE = STLPORT_ROOT + '/stlport'
STLPORT_LIB = STLPORT_ROOT + '/lib'
if PYTHON_ROOT:
PYTHON_INCLUDE = PYTHON_ROOT + '/include'
PYTHON_LIB = PYTHON_ROOT + '/libs'
LIBS = ['boost_python', 'python22']
INCLUDES = ['../example']
if sys.platform == 'win32':
CXX = 'icl'
CXXFLAGS='/GR /GX /MD /nologo'
INCLUDES += [BOOST_INCLUDE, STLPORT_INCLUDE, PYTHON_INCLUDE]
LIBPATH = [STLPORT_LIB, PYTHON_LIB, BOOST_LIB]
else:
CXX = 'g++'
CXXFLAGS = ''
LIBPATH = []
#INCLUDES = ['..']
# Create the environment
env = Environment(
CXX=CXX,
CXXFLAGS=CXXFLAGS,
CPPPATH=INCLUDES,
LIBS=LIBS,
LIBPATH=LIBPATH)
# Build all the cpp files
modules = [os.path.splitext(os.path.basename(x))[0] for x in glob.glob('../example/*.pyste')]
for module in modules:
multiple = ARGUMENTS.get('multiple', '')
example_cpp = '../example/%s.cpp' % module
if os.path.isfile(example_cpp):
sources = [example_cpp]
else:
sources = []
if multiple:
env.SharedLibrary(target=module, source=sources + glob.glob('_%s/*.cpp'%module))
else:
env.SharedLibrary(target=module, source=sources + ['_%s.cpp' % module])

View File

@@ -1,80 +0,0 @@
import sys
sys.path.append('../src')
from SmartFile import *
import unittest
import tempfile
import os
import time
class SmartFileTest(unittest.TestCase):
FILENAME = tempfile.mktemp()
def setUp(self):
self._Clean()
def tearDown(self):
self._Clean()
def _Clean(self):
try:
os.remove(self.FILENAME)
except OSError: pass
def testNonExistant(self):
"Must override the file, as there's no file in the disk yet"
self.assert_(not os.path.isfile(self.FILENAME))
f = SmartFile(self.FILENAME, 'w')
f.write('Testing 123\nTesting again.')
f.close()
self.assert_(os.path.isfile(self.FILENAME))
def testOverride(self):
"Must override the file, because the contents are different"
contents = 'Contents!\nContents!'
# create the file normally first
f = file(self.FILENAME, 'w')
f.write(contents)
f.close()
file_time = os.path.getmtime(self.FILENAME)
self.assert_(os.path.isfile(self.FILENAME))
time.sleep(2)
f = SmartFile(self.FILENAME, 'w')
f.write(contents + '_')
f.close()
new_file_time = os.path.getmtime(self.FILENAME)
self.assert_(new_file_time != file_time)
def testNoOverride(self):
"Must not override the file, because the contents are the same"
contents = 'Contents!\nContents!'
# create the file normally first
f = file(self.FILENAME, 'w')
f.write(contents)
f.close()
file_time = os.path.getmtime(self.FILENAME)
self.assert_(os.path.isfile(self.FILENAME))
time.sleep(2)
f = SmartFile(self.FILENAME, 'w')
f.write(contents)
f.close()
new_file_time = os.path.getmtime(self.FILENAME)
self.assert_(new_file_time == file_time)
def testAutoClose(self):
"Must be closed when garbage-collected"
def foo():
f = SmartFile(self.FILENAME)
f.write('testing')
self.assert_(not os.path.isfile(self.FILENAME))
foo()
self.assert_(os.path.isfile(self.FILENAME))
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,19 @@
@echo off
setlocal
set MODULE_NAME=%1
set PYSTE_FILE=%2
set BOOST_ROOT=d:/programming/libraries/boost-cvs
set PYTHON_ROOT=c:/python
set STLPORT_ROOT=d:/programming/libraries/stlport-4.5.3
set PYSTE_FILE_DIR=%@PATH[%PYSTE_FILE]
python ../src/pyste.py -I%PYSTE_FILE_DIR --out=%MODULE_NAME.cpp --module=%MODULE_NAME %PYSTE_FILE
icl /nologo /LD /GR /GX -I%PYSTE_FILE_DIR -I%STLPORT_ROOT/stlport -I%BOOST_ROOT/boost -I%PYTHON_ROOT/include %MODULE_NAME.cpp /link /libpath:%PYTHON_ROOT/libs /libpath:%BOOST_ROOT/lib /libpath:%STLPORT_ROOT/lib boost_python.lib
rm %MODULE_NAME.cpp
rm %MODULE_NAME.exp
rm %MODULE_NAME.lib
rm %MODULE_NAME.obj
endlocal

View File

@@ -1,11 +1,11 @@
import unittest
from basic import *
import os
class BasicExampleTest(unittest.TestCase):
def testIt(self):
from basic import C, call_f
# test virtual functions
class D(C):
def f(self, x=10):
return x+1
@@ -21,45 +21,6 @@ class BasicExampleTest(unittest.TestCase):
self.assertEqual(call_f(c, 4), 8)
self.assertEqual(call_f(d), 11)
self.assertEqual(call_f(d, 3), 4)
# test data members
def testValue(value):
self.assertEqual(c.value, value)
self.assertEqual(d.value, value)
self.assertEqual(get_value(c), value)
self.assertEqual(get_value(d), value)
testValue(1)
c.value = 30
d.value = 30
testValue(30)
self.assertEqual(c.const_value, 0)
self.assertEqual(d.const_value, 0)
def set_const_value():
c.const_value = 12
self.assertRaises(AttributeError, set_const_value)
# test static data-members
def testStatic(value):
self.assertEqual(C.static_value, value)
self.assertEqual(c.static_value, value)
self.assertEqual(D.static_value, value)
self.assertEqual(d.static_value, value)
self.assertEqual(get_static(), value)
testStatic(3)
C.static_value = 10
testStatic(10)
self.assertEqual(C.const_static_value, 100)
def set_const_static():
C.const_static_value = 1
self.assertRaises(AttributeError, set_const_static)
# test static function
def test_mul(result, *args):
self.assertEqual(C.mul(*args), result)
self.assertEqual(c.mul(*args), result)
test_mul(6)
test_mul(3, 1)
test_mul(16, 8, 2)
if __name__ == '__main__':

View File

@@ -1,20 +0,0 @@
import unittest
from inherit import *
class InheritExampleTest(unittest.TestCase):
def testIt(self):
a = A_int()
b = B()
self.assert_(isinstance(b, A_int))
self.assert_(issubclass(B, A_int))
a.set(10)
self.assertEqual(a.get(), 10)
b.set(1)
self.assertEqual(b.go(), 1)
self.assertEqual(b.get(), 1)
if __name__ == '__main__':
unittest.main()

View File

@@ -1,18 +0,0 @@
import unittest
from opaque import *
class OpaqueTest(unittest.TestCase):
def testIt(self):
c = new_C()
self.assertEqual(get(c), 10)
a = A()
d = a.new_handle()
self.assertEqual(a.get(d), 3.0)
self.assertEqual(a.f(), 0)
self.assertEqual(a.f(3), 3)
if __name__ == '__main__':
unittest.main()

View File

@@ -19,7 +19,6 @@ class OperatorTest(unittest.TestCase):
self.assertEqual(d(), 10)
self.assertEqual(c(3.0), 13.0)
self.assertEqual(d(6.0), 16.0)
self.assertEqual(str(c), "C")
if __name__ == '__main__':

View File

@@ -1,16 +0,0 @@
import unittest
from smart_ptr import *
class BasicExampleTest(unittest.TestCase):
def testIt(self):
c = NewC()
d = NewD()
c.value = 3
d.Set(c)
c1 = d.Get()
c1.value = 6
self.assertEqual(c.value, 6)
if __name__ == '__main__':
unittest.main()

View File

@@ -6,19 +6,19 @@ class TemplatesTest(unittest.TestCase):
def testIt(self):
fp = FPoint()
fp.i = 3.0
fp.j = 4.0
fp.j = 4
ip = IPoint()
ip.x = 10
ip.y = 3
ip.y = 3.0
self.assertEqual(fp.i, 3.0)
self.assertEqual(fp.j, 4.0)
self.assertEqual(fp.j, 4)
self.assertEqual(ip.x, 10)
self.assertEqual(ip.y, 3)
self.assertEqual(ip.y, 3.0)
self.assertEqual(type(fp.i), float)
self.assertEqual(type(fp.j), float)
self.assertEqual(type(fp.j), int)
self.assertEqual(type(ip.x), int)
self.assertEqual(type(ip.y), int)
self.assertEqual(type(ip.y), float)

View File

@@ -1,28 +0,0 @@
import unittest
from virtual2 import *
class Virtual2Test(unittest.TestCase):
def testIt(self):
a = A()
self.assertEqual(a.f1(), 10)
b = B()
self.assertEqual(b.f1(), 10)
self.assertEqual(b.f2(), 20)
self.assertEqual(call_fs(b), 30)
self.assertEqual(call_f(a), 0)
self.assertEqual(call_f(b), 1)
class C(B):
def f1(self): return 1
def f2(self): return 2
def f(self): return 100
c = C()
self.assertEqual(call_fs(c), 3)
self.assertEqual(call_fs(c), 3)
self.assertEqual(call_f(c), 100)
if __name__ == '__main__':
unittest.main()

View File

@@ -7,14 +7,5 @@ class WrapperTest(unittest.TestCase):
self.assertEqual(Range(10), range(10))
self.assertEqual(C().Mul(10), [x*10 for x in range(10)])
a = A()
self.assertEqual(a.f(), 10)
self.assertEqual(call_foo(a), 10)
class D(A):
def f(self): return 2
d = D()
self.assertEqual(d.f(), 2)
self.assertEqual(call_foo(d), 2)
if __name__ == '__main__':
unittest.main()

View File

@@ -1,7 +0,0 @@
@echo off
call nt_build_all.bat
runtests.py
call nt_clean.bat
call nt_build_all.bat --multiple
runtests.py
call nt_clean.bat

View File

@@ -1,15 +0,0 @@
@echo off
call nt_build_pyste.bat basic %1
call nt_build_pyste.bat enums %1
call nt_build_pyste.bat header_test %1
call nt_build_pyste.bat nested %1
call nt_build_pyste.bat operators %1
call nt_build_pyste.bat smart_ptr %1
call nt_build_pyste.bat templates %1
call nt_build_pyste.bat unions %1
call nt_build_pyste.bat virtual %1
call nt_build_pyste.bat virtual2 %1
call nt_build_pyste.bat wrappertest %1
call nt_build_pyste.bat opaque %1
call nt_build_pyste.bat inherit %1

View File

@@ -1,8 +0,0 @@
@echo off
set BOOST_INCLUDE=D:\Programming\Libraries\boost-cvs\boost
set out=_%1.cpp
if "%2" == "--multiple" set out=_%1
rem python ../src/pyste.py %2 -I%BOOST_INCLUDE -I../example --module=%1 --out=%out ../example/%1.pyste
pyste %2 -I%BOOST_INCLUDE -I../example --module=%1 --out=%out ../example/%1.pyste
scons --quiet multiple=%2 %1.dll

View File

@@ -1,24 +0,0 @@
@echo off
rm -Rf _basic
rm -Rf _enums
rm -Rf _header_test
rm -Rf _nested
rm -Rf _operators
rm -Rf _smart_ptr
rm -Rf _templates
rm -Rf _unions
rm -Rf _virtual
rm -Rf _virtual2
rm -Rf _wrappertest
rm -Rf _opaque
rm -Rf _inherit
rm -f *.cpp
rm -f *.obj
rm -f *.exp
rm -f *.arg
rm -f *.dll
rm -f *.pyc
rm -f *.lib
rm -f ../example/*.obj

View File

@@ -1,5 +1,5 @@
import sys
sys.path.append('../src')
sys.path.append('..')
import unittest
from policies import *
@@ -35,8 +35,7 @@ class PoliciesTest(unittest.TestCase):
self.assertEqual(x.Code(), ret % 'copy_non_const_reference')
x = return_value_policy(manage_new_object)
self.assertEqual(x.Code(), ret % 'manage_new_object')
x = return_value_policy(return_opaque_pointer)
self.assertEqual(x.Code(), ret % 'return_opaque_pointer')
def testReturnWithCustodiam(self):
'test the mix of return_internal with custodian'

20
pyste/tests/test_all.bat Normal file
View File

@@ -0,0 +1,20 @@
@echo off
call build_pyste_nt basic ../example/basic.pyste
call build_pyste_nt enums ../example/enums.pyste
call build_pyste_nt header_test ../example/header_test.pyste
call build_pyste_nt nested ../example/nested.pyste
call build_pyste_nt operators ../example/operators.pyste
call build_pyste_nt templates ../example/templates.pyste
call build_pyste_nt virtual ../example/virtual.pyste
call build_pyste_nt wrappertest ../example/wrappertest.pyste
call build_pyste_nt unions ../example/unions.pyste
runtests.py
if errorlevel != 0 goto end
rm *.dll
rm *.pyc
:end

View File

@@ -1,88 +0,0 @@
#!/usr/bin/python
import os
import glob
import shutil
def build_pyste_files(multiple):
# list all pyste files in the example directory
examples = glob.glob('../example/*.pyste')
# generate the cpp file for each example
for example in examples:
path, filename = os.path.split(example)
module = os.path.splitext(filename)[0]
os.system('python ../src/pyste.py %s -I%s --module=%s %s' % \
(multiple, path, module, example))
def compile_pyste_files(multiple):
if not multiple:
# compile each cpp into a shared library
for cpp in glob.glob('*.cpp'):
print
print 'compiling', cpp
out = os.path.splitext(cpp)[0] + '.so'
cmdline = 'g++ -shared -o %s -I../example ' \
'-I/usr/include/python2.2 -lboost_python %s' % (out, cpp)
os.system(cmdline)
else:
modules = get_modules()
# list cpp files in each module directory
print
for module in modules:
# compile each
for file in glob.glob(module+'/*.cpp'):
print 'compiling', file
out = os.path.splitext(file)[0] + '.obj'
cmdline = 'g++ -shared -c -o %s -I../example ' \
'-I/usr/include/python2.2 %s' % (out, file)
os.system(cmdline)
# generate a dynamic library
print 'linking'
objs = ' '.join([x for x in glob.glob(module+'/*.obj')])
out = module + '.so'
cmdline = 'g++ -shared -o %s -lboost_python %s' % (out, objs)
os.system(cmdline)
def run_tests():
if os.system('python runtests.py') != 0:
raise RuntimeError, 'tests failed'
def cleanup():
extensions = '*.cpp *.so *.pyc'
files = []
for ext in extensions.split():
files += glob.glob(ext)
for file in files:
try:
os.remove(file)
except OSError: pass
modules = get_modules()
for module in modules:
try:
shutil.rmtree(module)
except OSError: pass
def main(multiple):
build_pyste_files(multiple)
compile_pyste_files(multiple)
run_tests()
cleanup()
def get_modules():
def getname(file):
return os.path.splitext(os.path.basename(file))[0]
return [getname(x) for x in glob.glob('../example/*.pyste')]
if __name__ == '__main__':
try:
main('--multiple')
main('')
except RuntimeError, e:
print e