Re-use common constructor test

This commit is contained in:
Antoine Pitrou committed 2018-10-09 15:03:16 +02:00
1 parent 463e52d4fd
commit 7507891da6
3 files changed
+15 -23

No files matched your search

+11 -9
View File
@@ -23,7 +23,8 @@
cdef class MemoryPool:
def __init__(self):
raise TypeError("Do not call {}'s constructor directly"
raise TypeError("Do not call {}'s constructor directly, "
"use pyarrow.*_memory_pool instead."
.format(self.__class__.__name__))
cdef void init(self, CMemoryPool* pool):
@@ -60,13 +61,10 @@ cdef class LoggingMemoryPool(MemoryPool):
unique_ptr[CLoggingMemoryPool] logging_pool
def __init__(self):
raise TypeError("Do not call {}'s constructor directly"
raise TypeError("Do not call {}'s constructor directly, "
"use pyarrow.logging_memory_pool instead."
.format(self.__class__.__name__))
def __cinit__(self, MemoryPool pool):
self.logging_pool.reset(new CLoggingMemoryPool(pool.pool))
self.init(self.logging_pool.get())
cdef class ProxyMemoryPool(MemoryPool):
"""
@@ -77,8 +75,8 @@ cdef class ProxyMemoryPool(MemoryPool):
unique_ptr[CProxyMemoryPool] proxy_pool
def __init__(self):
raise TypeError("Do not call {}'s constructor directly. "
"Use pyarrow.proxy_memory_pool instead."
raise TypeError("Do not call {}'s constructor directly, "
"use pyarrow.proxy_memory_pool instead."
.format(self.__class__.__name__))
@@ -105,7 +103,11 @@ def logging_memory_pool(MemoryPool parent):
Create and return a MemoryPool instance that redirects to the
*parent*, but also dumps allocation logs on stderr.
"""
return LoggingMemoryPool.__new__(LoggingMemoryPool, parent)
cdef LoggingMemoryPool out = LoggingMemoryPool.__new__(
LoggingMemoryPool, parent)
out.logging_pool.reset(new CLoggingMemoryPool(parent.pool))
out.init(out.logging_pool.get())
return out
def set_memory_pool(MemoryPool pool):
-13
View File
@@ -17,8 +17,6 @@
import contextlib
import pytest
import pyarrow as pa
@@ -53,17 +51,6 @@ def check_allocated_bytes(pool):
assert pool.max_memory() == new_max_memory
def test_cannot_use_constructors():
with pytest.raises(TypeError):
pa.MemoryPool()
with pytest.raises(TypeError):
pa.ProxyMemoryPool()
with pytest.raises(TypeError):
pa.LoggingMemoryPool()
def test_default_allocated_bytes():
pool = pa.default_memory_pool()
with allocate_bytes(pool, 1024):
+4 -1
View File
@@ -117,7 +117,10 @@ def test_cpu_count():
pa.StructValue,
pa.DictionaryValue,
pa.ipc.Message,
pa.ipc.MessageReader
pa.ipc.MessageReader,
pa.MemoryPool,
pa.LoggingMemoryPool,
pa.ProxyMemoryPool,
])
def test_extension_type_constructor_errors(klass):
# ARROW-2638: prevent calling extension class constructors directly