2007-02-15 11:19:17 +00:00
|
|
|
from os.path import isfile, splitext, basename
|
|
|
|
from os import system, remove
|
|
|
|
from glob import glob
|
|
|
|
|
|
|
|
from logilab.common.testlib import TestCase, unittest_main
|
|
|
|
|
|
|
|
class RPyCompilation(TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.trscript = self.find_pypy()
|
|
|
|
|
|
|
|
def find_pypy(self):
|
2007-02-15 17:01:16 +00:00
|
|
|
#trscript = '/home/adim/local/svn/pypy-dist/pypy/translator/goal/translate.py'
|
|
|
|
trscript = '/home/syt/pypy-dist/pypy/translator/goal/translate.py'
|
2007-02-15 11:19:17 +00:00
|
|
|
if not isfile(trscript):
|
|
|
|
self.skip('translate.py not found')
|
|
|
|
return trscript
|
|
|
|
|
2007-02-15 17:01:16 +00:00
|
|
|
def _compile_fail(self, filename):
|
2007-02-15 11:19:17 +00:00
|
|
|
status = system('%s --batch %s' % (self.trscript, filename))
|
|
|
|
try:
|
|
|
|
self.assertNotEquals(status, 0, "%s translation succeed !!" % filename)
|
|
|
|
except AssertionError:
|
|
|
|
exefile = '%s-c' % splitext(basename(filename))[0]
|
|
|
|
status = system('./%s' % exefile)
|
|
|
|
remove(exefile)
|
|
|
|
self.assertNotEquals(status, 0, "%s run succeed !!" % exefile)
|
|
|
|
|
2007-02-15 17:01:16 +00:00
|
|
|
def _compile_success(self, filename):
|
|
|
|
status = system('%s --batch %s' % (self.trscript, filename))
|
2007-02-15 17:36:01 +00:00
|
|
|
self.assertEquals(status, 0, "%s translation failed !!" % filename)
|
2007-02-15 17:01:16 +00:00
|
|
|
exefile = '%s-c' % splitext(basename(filename))[0]
|
|
|
|
status = system('./%s' % exefile)
|
|
|
|
remove(exefile)
|
2007-02-15 17:36:01 +00:00
|
|
|
self.assertEquals(status, 0, "%s run failed !!" % exefile)
|
2007-02-15 17:01:16 +00:00
|
|
|
|
2007-02-15 11:19:17 +00:00
|
|
|
|
|
|
|
def test_translations(self):
|
2007-02-15 17:01:16 +00:00
|
|
|
for filename in glob('rpythoninput/func_*.py'):
|
|
|
|
if filename.startswith('rpythoninput/func_noerror'):
|
|
|
|
yield self._compile_success, filename
|
|
|
|
else:
|
|
|
|
yield self._compile_fail, filename
|
2007-02-15 11:19:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
if not '-cc' in sys.argv:
|
|
|
|
sys.argv.append('-cc')
|
|
|
|
unittest_main()
|