Skip to content
Permalink
Browse files

Merge pull request #868 from fniephaus/flake8

More Flake8 fixes
  • Loading branch information
timfel committed Mar 18, 2017
2 parents 751eb8b + 8e2fe6b commit ce546198831a46748542e4225659d356a438b8eb
Showing with 405 additions and 285 deletions.
  1. +0 −3 .travis.yml
  2. +1 −1 targettopaz.py
  3. +2 −2 tasks/base.py
  4. +2 −0 tasks/travis.py
  5. +3 −3 tests/jit/conftest.py
  6. +1 −0 tests/modules/ffi/base.py
  7. +3 −3 tests/modules/ffi/conftest.py
  8. +50 −34 tests/modules/ffi/test_abstract_memory.py
  9. +0 −1 tests/modules/ffi/test_callback.py
  10. +13 −8 tests/modules/ffi/test_data_converter.py
  11. +12 −5 tests/modules/ffi/test_dynamic_library.py
  12. +9 −2 tests/modules/ffi/test_ffi.py
  13. +16 −11 tests/modules/ffi/test_function.py
  14. +1 −1 tests/modules/ffi/test_function_type.py
  15. +6 −5 tests/modules/ffi/test_memory_pointer.py
  16. +15 −5 tests/modules/ffi/test_pointer.py
  17. +22 −6 tests/modules/ffi/test_type.py
  18. +3 −2 tests/modules/ffi/test_variadic_invoker.py
  19. +23 −23 tests/modules/test_marshal.py
  20. +3 −5 tests/modules/test_math.py
  21. +1 −1 topaz/lexer.py
  22. +2 −3 topaz/modules/fcntl.py
  23. +2 −0 topaz/modules/ffi/__init__.py
  24. +7 −4 topaz/modules/ffi/_callback.py
  25. +27 −21 topaz/modules/ffi/abstract_memory.py
  26. +4 −2 topaz/modules/ffi/data_converter.py
  27. +13 −9 topaz/modules/ffi/dynamic_library.py
  28. +4 −6 topaz/modules/ffi/ffi.py
  29. +2 −5 topaz/modules/ffi/function.py
  30. +15 −10 topaz/modules/ffi/function_type.py
  31. +5 −4 topaz/modules/ffi/memory_pointer.py
  32. +12 −1 topaz/modules/ffi/misc.py
  33. +5 −0 topaz/modules/ffi/pointer.py
  34. +59 −48 topaz/modules/ffi/type.py
  35. +4 −8 topaz/modules/ffi/variadic_invoker.py
  36. +21 −17 topaz/modules/topaz.py
  37. +2 −0 topaz/objects/fiberobject.py
  38. +29 −19 topaz/objects/timeobject.py
  39. +1 −2 topaz/parser.py
  40. +1 −0 topaz/utils/packing/pack.py
  41. +4 −5 topaz/utils/regexp.py
@@ -16,9 +16,6 @@ matrix:
# This times out because untranslated is so slow :/
- python: pypy-5.3.1
env: TEST_TYPE=rubyspec_untranslated
# We're tracking this, but not failing for it right now :(
- python: pypy-5.3.1
env: TEST_TYPE=flake8
include:
- os: osx
language: generic
@@ -15,7 +15,7 @@ def jitpolicy(driver):

def handle_config(config, translateconfig):
from rpython.translator.platform import host_factory
max_stack_size = 11 << 18 # 2.8 Megs
max_stack_size = 11 << 18 # 2.8 Megs
if host_factory.name == 'msvc':
host_factory.cflags += ('/DMAX_STACK_SIZE=%d' % max_stack_size,)
elif host_factory.name in ('linux', 'darwin'):
@@ -2,8 +2,8 @@

import invoke


invoke.run = os.system
if os.environ.get('TRAVIS_OS_NAME') == 'osx':
invoke.run = os.system


class BaseTest(object):
@@ -116,9 +116,11 @@ def run_translate_jit_tests(env):
run_specs("`pwd`/bin/topaz")
invoke.run("PYTHONPATH={rpython_path}:$PYTHONPATH py.test --topaz=bin/topaz tests/jit/".format(**env))


def run_translate_jit(env):
invoke.run("PYTHONPATH={rpython_path}:$PYTHONPATH python {rpython_path}/rpython/bin/rpython --batch -Ojit targettopaz.py".format(**env))


def run_specs(binary, prefix=""):
invoke.run("{prefix}../mspec/bin/mspec run -G fails -t {binary} --config=topaz.mspec".format(
prefix=prefix,
@@ -1,4 +1,3 @@
import os
import py
import sys

@@ -12,7 +11,8 @@ def __init__(self, trace, expected_ops, exception):
self.exception = exception

def find_test_file(self):
import traceback, re
import re
import traceback
stk = traceback.extract_stack()
stk.reverse()
for filename, lineno, funcname, text in stk:
@@ -21,7 +21,7 @@ def find_test_file(self):
return None, None

def get_updated_contents(self, filename, lineno):
lno = lineno - 10 # heuristic ;)
lno = lineno - 10 # heuristic ;)
with open(filename) as f:
contents = f.readlines()
newline = "\r\n" if contents[0].endswith("\r\n") else "\n"
@@ -1,5 +1,6 @@
from tests.base import BaseTopazTest


class BaseFFITest(BaseTopazTest):
def ask(self, space, question):
w_answer = space.execute(question)
@@ -2,22 +2,22 @@
import subprocess
import sys

from rpython.rtyper.lltypesystem.ll2ctypes import ALLOCATED

def pytest_funcarg__ffis(request, space):
system, _, _, _, cpu = os.uname() # not for windows
system, _, _, _, cpu = os.uname() # not for windows
space.execute("""
RUBY_ENGINE = 'topaz'
RUBY_PLATFORM = '%s-%s'
load 'ffi.rb'
""" % (cpu, system.lower()))
return space


def pytest_funcarg__libtest_so():
ext = 'dylib' if sys.platform == 'darwin' else 'so'
self_dir = os.path.join(os.path.dirname(__file__))
makefile = os.path.join('libtest', 'GNUmakefile')
subprocess.call(["make" , "-f", makefile], cwd=self_dir)
subprocess.call(["make", "-f", makefile], cwd=self_dir)
rel_to_libtest_so = os.path.join('build', 'libtest.' + ext)
libtest_so = os.path.abspath(os.path.join(self_dir, rel_to_libtest_so))
return libtest_so
@@ -6,7 +6,6 @@
from pypy.module._cffi_backend import misc

import sys
import pytest

test_types = [ffitype.INT8, ffitype.INT16, ffitype.INT32, ffitype.INT64,
ffitype.UINT8, ffitype.UINT16, ffitype.UINT32, ffitype.UINT64,
@@ -23,38 +22,44 @@
minval = {}
maxval = {}
for bits in [8, 16, 32, 64]:
minval['int' + str(bits)] = int(-2**(bits-1))
minval['int' + str(bits)] = int(-2**(bits - 1))
minval['uint' + str(bits)] = 0
maxval['int' + str(bits)] = int(2**(bits-1) - 1)
maxval['int' + str(bits)] = int(2**(bits - 1) - 1)
# for some reason int(2**64 -1) is not accepted as biggest uint64
maxval['uint' + str(bits)] = int(2**(bits-1) - 1)
minval['long'] = int(-2**(8*rffi.sizeof(rffi.LONG)))
maxval['uint' + str(bits)] = int(2**(bits - 1) - 1)
minval['long'] = int(-2**(8 * rffi.sizeof(rffi.LONG)))
minval['ulong'] = 0
maxval['long'] = int(2**(8*rffi.sizeof(rffi.LONG)) - 1)
maxval['ulong'] = int(2**(8*rffi.sizeof(rffi.LONG)-1) - 1)
maxval['long'] = int(2**(8 * rffi.sizeof(rffi.LONG)) - 1)
maxval['ulong'] = int(2**(8 * rffi.sizeof(rffi.LONG) - 1) - 1)
minval['float32'] = 1.1754943508222875e-38
maxval['float32'] = 3.4028234663852886e+38
minval['float64'] = sys.float_info.min
maxval['float64'] = sys.float_info.max


def new_cast_method(typ):
ctype = ffitype.lltypes[typ]

def cast_method(memory):
return rffi.cast(ffitype.lltype.Ptr(rffi.CArray(ctype)), memory.ptr)
return cast_method


def new_numberof_method(typ):
csize = ffitype.lltype_sizes[typ]
if csize & (csize - 1) == 0: # csize is a power of 2
shift = 0
while 1 << shift < csize: shift += 1
while 1 << shift < csize:
shift += 1

def numberof_method(self):
return self.sizeof_memory >> shift
else:
def numberof_method(self):
return self.sizeof_memory / csize
return numberof_method


def put_method_test_code(typename):
# For some reason, str(some_float) cuts off a few digits.
# Only repr prints the entire float.
@@ -66,9 +71,10 @@ def put_method_test_code(typename):
mem_ptr.put_TYPE(FFI::Type::UPPER.size, MAX)
mem_ptr
""".replace('TYPE', typename).
replace('UPPER', typename.upper()).
replace('MIN', strfunc(minval[typename])).
replace('MAX', strfunc(maxval[typename])))
replace('UPPER', typename.upper()).
replace('MIN', strfunc(minval[typename])).
replace('MAX', strfunc(maxval[typename])))


def get_method_test_code(typename):
strfunc = ((lambda x: repr(x)) if 'float' in typename else
@@ -81,9 +87,10 @@ def get_method_test_code(typename):
mem_ptr.put_TYPE(pos_4, MAX)
[mem_ptr.get_TYPE(pos_3), mem_ptr.get_TYPE(pos_4)]
""".replace('TYPE', typename).
replace('UPPER', typename.upper()).
replace('MIN', strfunc(minval[typename])).
replace('MAX', strfunc(maxval[typename])))
replace('UPPER', typename.upper()).
replace('MIN', strfunc(minval[typename])).
replace('MAX', strfunc(maxval[typename])))


class TestAbstractMemory_put_methods(BaseFFITest):
def test_they_put_a_single_value_into_the_given_offset(self, space):
@@ -106,7 +113,7 @@ def test_they_refuse_negative_offsets(self, space):
sizeof_t = ffitype.lltype_sizes[t]
with self.raises(space, 'IndexError',
"Memory access offset=-1 size=%s is out of bounds"
% sizeof_t):
% sizeof_t):
space.execute("""
FFI::MemoryPointer.new(:T, 1).put_T(-1, 230)
""".replace('T', tn.lower()))
@@ -115,13 +122,15 @@ def test_they_refuse_too_large_offsets(self, space):
for t in test_types:
tn = ffitype.type_names[t]
sizeof_t = ffitype.lltype_sizes[t]
with self.raises(space, 'IndexError',
"Memory access offset=1000 size=%s is out of bounds"
% sizeof_t):
with self.raises(
space, 'IndexError',
("Memory access offset=1000 size=%s is out of bounds" %
sizeof_t)):
space.execute("""
FFI::MemoryPointer.new(:T, 3).put_T(1000, 15)
""".replace('T', tn.lower()))


class TestAbstractMemory_write_methods(BaseFFITest):
def test_they_are_like_calling_put_with_0_as_1st_arg(self, space):
for t in test_types:
@@ -135,24 +144,26 @@ def test_they_are_like_calling_put_with_0_as_1st_arg(self, space):
casted_ptr = cast_method(w_mem_ptr)
assert casted_ptr[0] == 'y' if tn == 'INT8' else 121


class TestAbstractMemory_get_methods(BaseFFITest):
def test_they_get_a_single_value_from_the_given_offset(self, space):
for tn in [ffitype.type_names[t].lower()
for t in test_types]:
w_res = space.execute(get_method_test_code(tn))
assert self.unwrap(space, w_res) == [minval[tn], maxval[tn]]


class TestAbstractMemory_read_methods(BaseFFITest):
def test_they_are_like_calling_get_with_0(self, space):
for tn in [ffitype.type_names[t].lower()
for t in test_types]:
for tn in [ffitype.type_names[t].lower() for t in test_types]:
w_res = space.execute("""
mem_ptr = FFI::MemoryPointer.new(:T, 1)
mem_ptr.write_T(1)
mem_ptr.read_T
""".replace('T', tn))
assert self.unwrap(space, w_res) == 1


class TestAbstractMemory_put_pointer(BaseFFITest):
def test_it_puts_a_single_pointer_into_the_given_offset(self, space):
w_mem_ptr = space.execute("""
@@ -167,6 +178,7 @@ def test_it_puts_a_single_pointer_into_the_given_offset(self, space):
assert w_adr_ptr[0] == 88
assert w_adr_ptr[1] == 55


class TestAbstractMemory_get_pointer(BaseFFITest):
def test_it_gets_a_single_pointer_from_the_given_offset(self, space):
assert self.ask(space, """
@@ -196,6 +208,7 @@ def test_it_doesnt_loose_the_content(self, space):
""")
assert self.unwrap(space, w_res) == 300


class TestAbstractMemory_write_pointer(BaseFFITest):
def test_it_is_like_calling_put_pointer_with_0_as_1st_arg(self, space):
w_res = space.execute("""
@@ -205,6 +218,7 @@ def test_it_is_like_calling_put_pointer_with_0_as_1st_arg(self, space):
""")
assert self.unwrap(space, w_res) == 11


class TestAbstractMemory_write_uint64(BaseFFITest):
def test_it_is_like_calling_put_uint64_with_0_as_1st_arg(self, space):
w_res = space.execute("""
@@ -214,6 +228,7 @@ def test_it_is_like_calling_put_uint64_with_0_as_1st_arg(self, space):
""")
assert self.unwrap(space, w_res) == 14


class TestAbstractMemory_read_pointer(BaseFFITest):
def test_it_is_like_calling_get_pointer_with_0(self, space):
w_res = space.execute("""
@@ -223,6 +238,7 @@ def test_it_is_like_calling_get_pointer_with_0(self, space):
""")
assert self.unwrap(space, w_res) == 13


class TestAbstractMemory_read_uint64(BaseFFITest):
def test_it_is_like_calling_get_uint64_with_0(self, space):
w_res = space.execute("""
@@ -232,20 +248,20 @@ def test_it_is_like_calling_get_uint64_with_0(self, space):
""")
assert self.unwrap(space, w_res) == 12


class TestAbstractMemory(BaseFFITest):
def test_it_defines_the_following_aliases(self, space):
for aliases in [
('int8', 'char'),
('uint8', 'uchar'),
('int16', 'short'),
('uint16', 'ushort'),
('int32', 'int'),
('uint32', 'uint'),
('int64', 'long_long'),
('uint64', 'ulong_long'),
('float32', 'float'),
('float64', 'double')
]:
('int8', 'char'),
('uint8', 'uchar'),
('int16', 'short'),
('uint16', 'ushort'),
('int32', 'int'),
('uint32', 'uint'),
('int64', 'long_long'),
('uint64', 'ulong_long'),
('float32', 'float'),
('float64', 'double')]:
assert self.ask(space, """
FFI::AbstractMemory.instance_method(:put_%s) ==
FFI::AbstractMemory.instance_method(:put_%s)
@@ -269,11 +285,11 @@ def test_it_defines_long_methods_in_the_following_way(self, space):
FFI::AbstractMemory.instance_method(:PREFIXintSIZEOF_LONG_IN_BITS)
""".replace('SIZEOF_LONG_IN_BITS', str(8 * rffi.sizeof(rffi.LONG)))
signed_meths = ['put_', 'get_', 'write_', 'read_']
unsigned_meths = [meth+'u' for meth in signed_meths]
unsigned_meths = [meth + 'u' for meth in signed_meths]
for prefix in signed_meths + unsigned_meths:
assert self.ask(space, question.replace('PREFIX', prefix))

#class TestAbstractMemory__put_array_of_int32(BaseFFITest):
# class TestAbstractMemory__put_array_of_int32(BaseFFITest):
# def test_it_writes_into_array(self, space):
# w_mem_ptr = space.execute("""
# mem_ptr = FFI::MemoryPointer.new(:int32, 10)
@@ -316,7 +332,7 @@ def test_it_defines_long_methods_in_the_following_way(self, space):
# mem_ptr.put_array_of_int32(0, [1, 2, 3])
# """)
#
#class TestAbstractMemory__get_array_of_int32(BaseFFITest):
# class TestAbstractMemory__get_array_of_int32(BaseFFITest):
# def test_it_reads_from_array(self, space):
# w_res = space.execute("""
# mem_ptr = FFI::MemoryPointer.new(:int32, 10)
@@ -1,4 +1,3 @@
import os
import py

from topaz.modules.ffi import _callback

0 comments on commit ce54619

Please sign in to comment.
You can’t perform that action at this time.