FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-105751: test_ctypes.test_numbers uses top level imports by vstinner · Pull Request #105762 · python/cpython · GitHub

/ cpython Public
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
40 changes: 8 additions & 32 deletions Lib/test/test_ctypes/test_numbers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from ctypes import *
import unittest
import struct
import sys
import unittest
from array import array
from operator import truth
from ctypes import *
from ctypes import _SimpleCData

def valid_ranges(*types):
# given a sequence of numeric types, collect their _type_
Expand All @@ -21,29 +25,11 @@ def valid_ranges(*types):

ArgType = type(byref(c_int(0)))

unsigned_types = [c_ubyte, c_ushort, c_uint, c_ulong]
unsigned_types = [c_ubyte, c_ushort, c_uint, c_ulong, c_ulonglong]
signed_types = [c_byte, c_short, c_int, c_long, c_longlong]

bool_types = []

bool_types = [c_bool]
float_types = [c_double, c_float]

try:
c_ulonglong
c_longlong
except NameError:
pass
else:
unsigned_types.append(c_ulonglong)
signed_types.append(c_longlong)

try:
c_bool
except NameError:
pass
else:
bool_types.append(c_bool)

unsigned_ranges = valid_ranges(*unsigned_types)
signed_ranges = valid_ranges(*signed_types)
bool_values = [True, False, 0, 1, -1, 5000, 'test', [], [1]]
Expand Down Expand Up @@ -71,7 +57,6 @@ def test_signed_values(self):
self.assertEqual(t(h).value, h)

def test_bool_values(self):
from operator import truth
for t, v in zip(bool_types, bool_values):
self.assertEqual(t(v).value, truth(v))

Expand Down Expand Up @@ -161,7 +146,6 @@ def test_alignments(self):
(code, align))

def test_int_from_address(self):
from array import array
for t in signed_types + unsigned_types:
# the array module doesn't support all format codes
# (no 'q' or 'Q')
Expand All @@ -182,7 +166,6 @@ def test_int_from_address(self):


def test_float_from_address(self):
from array import array
for t in float_types:
a = array(t._type_, [3.14])
v = t.from_address(a.buffer_info()[0])
Expand All @@ -193,9 +176,6 @@ def test_float_from_address(self):
self.assertIs(type(v), t)

def test_char_from_address(self):
from ctypes import c_char
from array import array

a = array('b', [0])
a[0] = ord('x')
v = c_char.from_address(a.buffer_info()[0])
Expand All @@ -208,8 +188,6 @@ def test_char_from_address(self):
# array does not support c_bool / 't'
@unittest.skip('test disabled')
def test_bool_from_address(self):
from ctypes import c_bool
from array import array
a = array(c_bool._type_, [True])
v = t.from_address(a.buffer_info()[0])
self.assertEqual(v.value, a[0])
Expand All @@ -225,7 +203,6 @@ def test_init(self):
self.assertRaises(TypeError, c_int, c_long(42))

def test_float_overflow(self):
import sys
big_int = int(sys.float_info.max) * 2
for t in float_types + [c_longdouble]:
self.assertRaises(OverflowError, t, big_int)
Expand All @@ -238,7 +215,6 @@ def test_float_overflow(self):
def test_perf(self):
check_perf()

from ctypes import _SimpleCData
class c_int_S(_SimpleCData):
_type_ = "i"
__slots__ = []
Expand Down

Back | FazBrowse Home | New Git URL