Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 support #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 39 additions & 34 deletions scripts/crunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

from __future__ import print_function
from future import standard_library
standard_library.install_aliases()
from builtins import str
from builtins import object
import copy
import logging
import optparse
Expand All @@ -13,7 +18,7 @@
import time
import traceback

import cStringIO as StringIO
import io as StringIO

from spitfire.compiler import compiler
from spitfire.compiler import options
Expand Down Expand Up @@ -60,11 +65,11 @@ def __getattr__(self, key):
return self._get_item(key)


sys_modules = sys.modules.keys()
sys_modules = list(sys.modules.keys())


def reset_sys_modules():
for key in sys.modules.keys():
for key in list(sys.modules.keys()):
if key not in sys_modules:
del sys.modules[key]

Expand Down Expand Up @@ -105,18 +110,18 @@ def begin(self):

def end(self):
self.finish_time = time.time()
print >> sys.stderr
print(file=sys.stderr)
if self.num_tests_failed > 0:
sys.stderr.write(self.buffer.getvalue())
print >> sys.stderr, '-' * 70
print >> sys.stderr, 'Ran %d tests in %0.3fs' % (
self.num_tests_run, self.finish_time - self.start_time)
print >> sys.stderr
print('-' * 70, file=sys.stderr)
print('Ran %d tests in %0.3fs' % (
self.num_tests_run, self.finish_time - self.start_time), file=sys.stderr)
print(file=sys.stderr)
if self.num_tests_failed > 0:
print >> sys.stderr, 'FAILED (failures=%d)' % self.num_tests_failed
print('FAILED (failures=%d)' % self.num_tests_failed, file=sys.stderr)
sys.exit(1)
else:
print >> sys.stderr, 'OK'
print('OK', file=sys.stderr)
sys.exit(0)

def process_file(self, filename):
Expand All @@ -137,31 +142,31 @@ def process_file(self, filename):
self.compiler.compile_file(filename)
except Exception as e:
compile_failed = True
print >> buffer, '=' * 70
print >> buffer, 'FAIL:', modulename, '(' + filename + ')'
print >> buffer, '-' * 70
print('=' * 70, file=buffer)
print('FAIL:', modulename, '(' + filename + ')', file=buffer)
print('-' * 70, file=buffer)
traceback.print_exc(None, buffer)
if self.options.debug:
if 'parse_tree' in self.options.debug_flags:
print >> buffer, "parse_tree:"
print("parse_tree:", file=buffer)
visitor.print_tree(self.compiler._parse_tree, output=buffer)
if 'analyzed_tree' in self.options.debug_flags:
print >> buffer, "analyzed_tree:"
print("analyzed_tree:", file=buffer)
visitor.print_tree(self.compiler._analyzed_tree,
output=buffer)
if 'optimized_tree' in self.options.debug_flags:
print >> buffer, "optimized_tree:"
print("optimized_tree:", file=buffer)
visitor.print_tree(self.compiler._optimized_tree,
output=buffer)
if 'hoisted_tree' in self.options.debug_flags:
print >> buffer, "hoisted_tree:"
print("hoisted_tree:", file=buffer)
visitor.print_tree(self.compiler._hoisted_tree,
output=buffer)
if 'source_code' in self.options.debug_flags:
print >> buffer, "source_code:"
print("source_code:", file=buffer)
for i, line in enumerate(self.compiler._source_code.split(
'\n')):
print >> buffer, '% 3s' % (i + 1), line
print('% 3s' % (i + 1), line, file=buffer)

test_failed = False
if not self.options.skip_test:
Expand Down Expand Up @@ -216,10 +221,10 @@ def process_file(self, filename):
if current_output != test_output:
test_failed = True
if self.options.debug:
print >> buffer, "expected output:"
print >> buffer, test_output
print >> buffer, "actual output:"
print >> buffer, current_output
print("expected output:", file=buffer)
print(test_output, file=buffer)
print("actual output:", file=buffer)
print(current_output, file=buffer)

if compile_failed or test_failed:
self.num_tests_failed += 1
Expand All @@ -232,23 +237,23 @@ def process_file(self, filename):
f = open(current_output_path, 'w')
f.write(current_output)
f.close()
print >> buffer, '=' * 70
print >> buffer, 'FAIL:', modulename, '(' + filename + ')'
print >> buffer, '-' * 70
print >> buffer, 'Compare expected and actual output with:'
print >> buffer, ' '.join([' diff -u', test_output_path,
current_output_path])
print >> buffer, 'Show debug information for the test with:'
print('=' * 70, file=buffer)
print('FAIL:', modulename, '(' + filename + ')', file=buffer)
print('-' * 70, file=buffer)
print('Compare expected and actual output with:', file=buffer)
print(' '.join([' diff -u', test_output_path,
current_output_path]), file=buffer)
print('Show debug information for the test with:', file=buffer)
test_cmd = [arg for arg in sys.argv if arg not in self.files]
if '--debug' not in test_cmd:
test_cmd.append('--debug')
test_cmd = ' '.join(test_cmd)
print >> buffer, ' ', test_cmd, filename
print(' ', test_cmd, filename, file=buffer)
if raised_exception:
print >> buffer, '-' * 70
print >> buffer, current_output
print('-' * 70, file=buffer)
print(current_output, file=buffer)
traceback.print_exc(None, buffer)
print >> buffer
print(file=buffer)
self.buffer.write(buffer.getvalue())
else:
if self.options.verbose:
Expand Down
1 change: 1 addition & 0 deletions spitfire/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

from builtins import object
import sys


Expand Down
5 changes: 3 additions & 2 deletions spitfire/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

from builtins import zip
import re
import string
import unicodedata
Expand Down Expand Up @@ -63,8 +64,8 @@
'LATIN CAPITAL LETTER Z WITH ACUTE',
]

char_map = dict(zip(normal_characters, [unicodedata.lookup(name)
for name in mangled_character_names]))
char_map = dict(list(zip(normal_characters, [unicodedata.lookup(name)
for name in mangled_character_names])))


# return a string with interesting unicode characters to make sure
Expand Down