Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(85208)

Delta Between Two Patch Sets: Lib/test/test_sys.py

Issue 11682: PEP 380 reference implementation for 3.3
Left Patch Set: Created 8 years, 1 month ago
Right Patch Set: Created 7 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_pep380.py ('k') | Misc/ACKS » ('j') | Modules/parsermodule.c » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 import unittest, test.support 1 import unittest, test.support
2 import sys, io, os 2 import sys, io, os
3 import struct 3 import struct
4 import subprocess 4 import subprocess
5 import textwrap 5 import textwrap
6 import warnings 6 import warnings
7 import operator 7 import operator
8 import codecs 8 import codecs
9 9
10 # count the number of test runs, used to create unique 10 # count the number of test runs, used to create unique
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 1, 440 1,
441 "sys.hash_info.modulus {} is a non-prime".format( 441 "sys.hash_info.modulus {} is a non-prime".format(
442 sys.hash_info.modulus) 442 sys.hash_info.modulus)
443 ) 443 )
444 self.assertIsInstance(sys.hash_info.inf, int) 444 self.assertIsInstance(sys.hash_info.inf, int)
445 self.assertIsInstance(sys.hash_info.nan, int) 445 self.assertIsInstance(sys.hash_info.nan, int)
446 self.assertIsInstance(sys.hash_info.imag, int) 446 self.assertIsInstance(sys.hash_info.imag, int)
447 447
448 self.assertIsInstance(sys.maxsize, int) 448 self.assertIsInstance(sys.maxsize, int)
449 self.assertIsInstance(sys.maxunicode, int) 449 self.assertIsInstance(sys.maxunicode, int)
450 self.assertEqual(sys.maxunicode, 0x10FFFF)
450 self.assertIsInstance(sys.platform, str) 451 self.assertIsInstance(sys.platform, str)
451 self.assertIsInstance(sys.prefix, str) 452 self.assertIsInstance(sys.prefix, str)
452 self.assertIsInstance(sys.version, str) 453 self.assertIsInstance(sys.version, str)
453 vi = sys.version_info 454 vi = sys.version_info
454 self.assertIsInstance(vi[:], tuple) 455 self.assertIsInstance(vi[:], tuple)
455 self.assertEqual(len(vi), 5) 456 self.assertEqual(len(vi), 5)
456 self.assertIsInstance(vi[0], int) 457 self.assertIsInstance(vi[0], int)
457 self.assertIsInstance(vi[1], int) 458 self.assertIsInstance(vi[1], int)
458 self.assertIsInstance(vi[2], int) 459 self.assertIsInstance(vi[2], int)
459 self.assertIn(vi[3], ("alpha", "beta", "candidate", "final")) 460 self.assertIn(vi[3], ("alpha", "beta", "candidate", "final"))
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 x = 42 663 x = 42
663 def inner(): 664 def inner():
664 return x 665 return x
665 return inner 666 return inner
666 check(get_cell().__closure__[0], size(h + 'P')) 667 check(get_cell().__closure__[0], size(h + 'P'))
667 # code 668 # code
668 check(get_cell().__code__, size(h + '5i9Pi3P')) 669 check(get_cell().__code__, size(h + '5i9Pi3P'))
669 # complex 670 # complex
670 check(complex(0,1), size(h + '2d')) 671 check(complex(0,1), size(h + '2d'))
671 # method_descriptor (descriptor object) 672 # method_descriptor (descriptor object)
672 check(str.lower, size(h + '2PP')) 673 check(str.lower, size(h + '3PP'))
673 # classmethod_descriptor (descriptor object) 674 # classmethod_descriptor (descriptor object)
674 # XXX 675 # XXX
675 # member_descriptor (descriptor object) 676 # member_descriptor (descriptor object)
676 import datetime 677 import datetime
677 check(datetime.timedelta.days, size(h + '2PP')) 678 check(datetime.timedelta.days, size(h + '3PP'))
678 # getset_descriptor (descriptor object) 679 # getset_descriptor (descriptor object)
679 import collections 680 import collections
680 check(collections.defaultdict.default_factory, size(h + '2PP')) 681 check(collections.defaultdict.default_factory, size(h + '3PP'))
681 # wrapper_descriptor (descriptor object) 682 # wrapper_descriptor (descriptor object)
682 check(int.__add__, size(h + '2P2P')) 683 check(int.__add__, size(h + '3P2P'))
683 # method-wrapper (descriptor object) 684 # method-wrapper (descriptor object)
684 check({}.__iter__, size(h + '2P')) 685 check({}.__iter__, size(h + '2P'))
685 # dict 686 # dict
686 check({}, size(h + '3P2P' + 8*'P2P')) 687 check({}, size(h + '3P2P' + 8*'P2P'))
687 longdict = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8} 688 longdict = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8}
688 check(longdict, size(h + '3P2P' + 8*'P2P') + 16*size('P2P')) 689 check(longdict, size(h + '3P2P' + 8*'P2P') + 16*size('P2P'))
689 # dictionary-keyiterator 690 # dictionary-keyiterator
690 check({}.keys(), size(h + 'P')) 691 check({}.keys(), size(h + 'P'))
691 # dictionary-valueiterator 692 # dictionary-valueiterator
692 check({}.values(), size(h + 'P')) 693 check({}.values(), size(h + 'P'))
(...skipping 29 matching lines...) Expand all
722 import inspect 723 import inspect
723 CO_MAXBLOCKS = 20 724 CO_MAXBLOCKS = 20
724 x = inspect.currentframe() 725 x = inspect.currentframe()
725 ncells = len(x.f_code.co_cellvars) 726 ncells = len(x.f_code.co_cellvars)
726 nfrees = len(x.f_code.co_freevars) 727 nfrees = len(x.f_code.co_freevars)
727 extras = x.f_code.co_stacksize + x.f_code.co_nlocals +\ 728 extras = x.f_code.co_stacksize + x.f_code.co_nlocals +\
728 ncells + nfrees - 1 729 ncells + nfrees - 1
729 check(x, size(vh + '13P3i' + CO_MAXBLOCKS*'3i' + 'P' + extras*'P')) 730 check(x, size(vh + '13P3i' + CO_MAXBLOCKS*'3i' + 'P' + extras*'P'))
730 # function 731 # function
731 def func(): pass 732 def func(): pass
732 check(func, size(h + '11P')) 733 check(func, size(h + '12P'))
733 class c(): 734 class c():
734 @staticmethod 735 @staticmethod
735 def foo(): 736 def foo():
736 pass 737 pass
737 @classmethod 738 @classmethod
738 def bar(cls): 739 def bar(cls):
739 pass 740 pass
740 # staticmethod 741 # staticmethod
741 check(foo, size(h + 'P')) 742 check(foo, size(h + 'P'))
742 # classmethod 743 # classmethod
(...skipping 19 matching lines...) Expand all
762 # listreverseiterator (list) 763 # listreverseiterator (list)
763 check(reversed([]), size(h + 'lP')) 764 check(reversed([]), size(h + 'lP'))
764 # long 765 # long
765 check(0, size(vh)) 766 check(0, size(vh))
766 check(1, size(vh) + self.longdigit) 767 check(1, size(vh) + self.longdigit)
767 check(-1, size(vh) + self.longdigit) 768 check(-1, size(vh) + self.longdigit)
768 PyLong_BASE = 2**sys.int_info.bits_per_digit 769 PyLong_BASE = 2**sys.int_info.bits_per_digit
769 check(int(PyLong_BASE), size(vh) + 2*self.longdigit) 770 check(int(PyLong_BASE), size(vh) + 2*self.longdigit)
770 check(int(PyLong_BASE**2-1), size(vh) + 2*self.longdigit) 771 check(int(PyLong_BASE**2-1), size(vh) + 2*self.longdigit)
771 check(int(PyLong_BASE**2), size(vh) + 3*self.longdigit) 772 check(int(PyLong_BASE**2), size(vh) + 3*self.longdigit)
772 # memory 773 # memory (Py_buffer + hash value)
773 check(memoryview(b''), size(h + 'PP2P2i7P')) 774 check(memoryview(b''), size(h + 'PP2P2i7P' + 'P'))
774 # module 775 # module
775 check(unittest, size(h + '3P')) 776 check(unittest, size(h + '3P'))
776 # None 777 # None
777 check(None, size(h + '')) 778 check(None, size(h + ''))
778 # NotImplementedType 779 # NotImplementedType
779 check(NotImplemented, size(h)) 780 check(NotImplemented, size(h))
780 # object 781 # object
781 check(object(), size(h + '')) 782 check(object(), size(h + ''))
782 # property (descriptor object) 783 # property (descriptor object)
783 class C(object): 784 class C(object):
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 # slice 821 # slice
821 check(slice(0), size(h + '3P')) 822 check(slice(0), size(h + '3P'))
822 # super 823 # super
823 check(super(int), size(h + '3P')) 824 check(super(int), size(h + '3P'))
824 # tuple 825 # tuple
825 check((), size(vh)) 826 check((), size(vh))
826 check((1,2,3), size(vh) + 3*self.P) 827 check((1,2,3), size(vh) + 3*self.P)
827 # type 828 # type
828 # (PyTypeObject + PyNumberMethods + PyMappingMethods + 829 # (PyTypeObject + PyNumberMethods + PyMappingMethods +
829 # PySequenceMethods + PyBufferProcs) 830 # PySequenceMethods + PyBufferProcs)
830 s = size(vh + 'P2P15Pl4PP9PP11PI') + size('16Pi17P 3P 10P 2P 2P') 831 s = size(vh + 'P2P15Pl4PP9PP11PI') + size('16Pi17P 3P 10P 2P 3P')
831 check(int, s) 832 check(int, s)
832 # class 833 # class
833 class newstyleclass(object): pass 834 class newstyleclass(object): pass
834 check(newstyleclass, s) 835 check(newstyleclass, s)
835 # unicode 836 # unicode
836 usize = len('\0'.encode('unicode-internal')) 837 # each tuple contains a string and its expected character size
837 samples = ['', '1'*100] 838 # don't put any static strings here, as they may contain
838 # we need to test for both sizes, because we don't know if the string 839 # wchar_t or UTF-8 representations
839 # has been cached 840 samples = ['1'*100, '\xff'*50,
841 '\u0100'*40, '\uffff'*100,
842 '\U00010000'*30, '\U0010ffff'*100]
843 asciifields = h + "PPiP"
844 compactfields = asciifields + "PPP"
845 unicodefields = compactfields + "P"
840 for s in samples: 846 for s in samples:
841 basicsize = size(h + 'PPPiP') + usize * (len(s) + 1) 847 maxchar = ord(max(s))
842 check(s, basicsize) 848 if maxchar < 128:
849 L = size(asciifields) + len(s) + 1
850 elif maxchar < 256:
851 L = size(compactfields) + len(s) + 1
852 elif maxchar < 65536:
853 L = size(compactfields) + 2*(len(s) + 1)
854 else:
855 L = size(compactfields) + 4*(len(s) + 1)
856 check(s, L)
857 # verify that the UTF-8 size is accounted for
858 s = chr(0x4000) # 4 bytes canonical representation
859 check(s, size(compactfields) + 4)
860 # compile() will trigger the generation of the UTF-8
861 # representation as a side effect
862 compile(s, "<stdin>", "eval")
863 check(s, size(compactfields) + 4 + 4)
864 # TODO: add check that forces the presence of wchar_t representation
865 # TODO: add check that forces layout of unicodefields
843 # weakref 866 # weakref
844 import weakref 867 import weakref
845 check(weakref.ref(int), size(h + '2Pl2P')) 868 check(weakref.ref(int), size(h + '2Pl2P'))
846 # weakproxy 869 # weakproxy
847 # XXX 870 # XXX
848 # weakcallableproxy 871 # weakcallableproxy
849 check(weakref.proxy(int), size(h + '2Pl2P')) 872 check(weakref.proxy(int), size(h + '2Pl2P'))
850 873
851 def test_pythontypes(self): 874 def test_pythontypes(self):
852 # check all types defined in Python/ 875 # check all types defined in Python/
(...skipping 18 matching lines...) Expand all
871 # XXX 894 # XXX
872 # sys.flags 895 # sys.flags
873 check(sys.flags, size(vh) + self.P * len(sys.flags)) 896 check(sys.flags, size(vh) + self.P * len(sys.flags))
874 897
875 898
876 def test_main(): 899 def test_main():
877 test.support.run_unittest(SysModuleTest, SizeofTest) 900 test.support.run_unittest(SysModuleTest, SizeofTest)
878 901
879 if __name__ == "__main__": 902 if __name__ == "__main__":
880 test_main() 903 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+