Skip to content

Commit cedea96

Browse files
Refactor tests and skip them on big-endian platforms.
1 parent e294757 commit cedea96

File tree

1 file changed

+19
-50
lines changed

1 file changed

+19
-50
lines changed

Lib/test/test_ctypes/test_structures.py

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -473,96 +473,65 @@ class X(Structure):
473473
self.assertEqual(s.first, got.first)
474474
self.assertEqual(s.second, got.second)
475475

476-
@unittest.skipIf(_architecture() == ('64bit', 'WindowsPE'), "can't test Windows x64 build")
477-
def test_issue18060_a(self):
476+
def _test_issue18060(self, Vector):
478477
# The call to atan2() should succeed if the
479478
# class fields were correctly cloned in the
480479
# subclasses. Otherwise, it will segfault.
481-
#
482-
# This test case calls
483-
# PyCStructUnionType_update_stgdict() for each
484-
# _fields_ assignment, and PyCStgDict_clone()
485-
# for the Mid and Vector class definitions.
486480
if sys.platform == 'win32':
487481
libm = CDLL(find_library('msvcrt.dll'))
488482
else:
489483
libm = CDLL(find_library('m'))
490484

485+
libm.atan2.argtypes = [Vector]
486+
libm.atan2.restype = c_double
487+
488+
arg = Vector(y=0.0, x=-1.0)
489+
self.assertAlmostEqual(libm.atan2(arg), 3.141592653589793)
490+
491+
@unittest.skipIf(_architecture() == ('64bit', 'WindowsPE'), "can't test Windows x64 build")
492+
@unittest.skipUnless(sys.byteorder == 'little', "can't test on this platform")
493+
def test_issue18060_a(self):
494+
# This test case calls
495+
# PyCStructUnionType_update_stgdict() for each
496+
# _fields_ assignment, and PyCStgDict_clone()
497+
# for the Mid and Vector class definitions.
491498
class Base(Structure):
492499
_fields_ = [('y', c_double),
493500
('x', c_double)]
494-
495501
class Mid(Base):
496502
pass
497-
498503
Mid._fields_ = []
499-
500504
class Vector(Mid): pass
501-
502-
libm.atan2.argtypes = [Vector]
503-
libm.atan2.restype = c_double
504-
505-
arg = Vector(y=0.0, x=-1.0)
506-
self.assertAlmostEqual(libm.atan2(arg), 3.141592653589793)
505+
self._test_issue18060(Vector)
507506

508507
@unittest.skipIf(_architecture() == ('64bit', 'WindowsPE'), "can't test Windows x64 build")
508+
@unittest.skipUnless(sys.byteorder == 'little', "can't test on this platform")
509509
def test_issue18060_b(self):
510-
# The call to atan2() should succeed if the
511-
# class fields were correctly cloned in the
512-
# subclasses. Otherwise, it will segfault.
513-
#
514510
# This test case calls
515511
# PyCStructUnionType_update_stgdict() for each
516512
# _fields_ assignment.
517-
if sys.platform == 'win32':
518-
libm = CDLL(find_library('msvcrt.dll'))
519-
else:
520-
libm = CDLL(find_library('m'))
521-
522513
class Base(Structure):
523514
_fields_ = [('y', c_double),
524515
('x', c_double)]
525-
526516
class Mid(Base):
527517
_fields_ = []
528-
529518
class Vector(Mid):
530519
_fields_ = []
531-
532-
libm.atan2.argtypes = [Vector]
533-
libm.atan2.restype = c_double
534-
535-
arg = Vector(y=0.0, x=-1.0)
536-
self.assertAlmostEqual(libm.atan2(arg), 3.141592653589793)
520+
self._test_issue18060(Vector)
537521

538522
@unittest.skipIf(_architecture() == ('64bit', 'WindowsPE'), "can't test Windows x64 build")
523+
@unittest.skipUnless(sys.byteorder == 'little', "can't test on this platform")
539524
def test_issue18060_c(self):
540-
# The call to atan2() should succeed if the
541-
# class fields were correctly cloned in the
542-
# subclasses. Otherwise, it will segfault.
543-
#
544525
# This test case calls
545526
# PyCStructUnionType_update_stgdict() for each
546527
# _fields_ assignment.
547-
if sys.platform == 'win32':
548-
libm = CDLL(find_library('msvcrt.dll'))
549-
else:
550-
libm = CDLL(find_library('m'))
551-
552528
class Base(Structure):
553529
_fields_ = [('y', c_double)]
554-
555530
class Mid(Base):
556531
_fields_ = []
557-
558532
class Vector(Mid):
559533
_fields_ = [('x', c_double)]
560-
561-
libm.atan2.argtypes = [Vector]
562-
libm.atan2.restype = c_double
563-
564-
arg = Vector(y=0.0, x=-1.0)
565-
self.assertAlmostEqual(libm.atan2(arg), 3.141592653589793)
534+
self._test_issue18060(Vector)
566535

567536
def test_array_in_struct(self):
568537
# See bpo-22273

0 commit comments

Comments
 (0)