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

Side by Side Diff: Lib/test/test_sys.py

Issue 14843: support define_macros / undef_macros in setup.cfg
Patch Set: Created 11 months, 2 weeks 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:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_super.py ('k') | Lib/test/test_sysconfig.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 self.assertIn(0, d) 412 self.assertIn(0, d)
413 self.assertTrue(d[0] is sys._getframe()) 413 self.assertTrue(d[0] is sys._getframe())
414 414
415 def test_attributes(self): 415 def test_attributes(self):
416 self.assertIsInstance(sys.api_version, int) 416 self.assertIsInstance(sys.api_version, int)
417 self.assertIsInstance(sys.argv, list) 417 self.assertIsInstance(sys.argv, list)
418 self.assertIn(sys.byteorder, ("little", "big")) 418 self.assertIn(sys.byteorder, ("little", "big"))
419 self.assertIsInstance(sys.builtin_module_names, tuple) 419 self.assertIsInstance(sys.builtin_module_names, tuple)
420 self.assertIsInstance(sys.copyright, str) 420 self.assertIsInstance(sys.copyright, str)
421 self.assertIsInstance(sys.exec_prefix, str) 421 self.assertIsInstance(sys.exec_prefix, str)
422 self.assertIsInstance(sys.base_exec_prefix, str)
423 self.assertIsInstance(sys.executable, str) 422 self.assertIsInstance(sys.executable, str)
424 self.assertEqual(len(sys.float_info), 11) 423 self.assertEqual(len(sys.float_info), 11)
425 self.assertEqual(sys.float_info.radix, 2) 424 self.assertEqual(sys.float_info.radix, 2)
426 self.assertEqual(len(sys.int_info), 2) 425 self.assertEqual(len(sys.int_info), 2)
427 self.assertTrue(sys.int_info.bits_per_digit % 5 == 0) 426 self.assertTrue(sys.int_info.bits_per_digit % 5 == 0)
428 self.assertTrue(sys.int_info.sizeof_digit >= 1) 427 self.assertTrue(sys.int_info.sizeof_digit >= 1)
429 self.assertEqual(type(sys.int_info.bits_per_digit), int) 428 self.assertEqual(type(sys.int_info.bits_per_digit), int)
430 self.assertEqual(type(sys.int_info.sizeof_digit), int) 429 self.assertEqual(type(sys.int_info.sizeof_digit), int)
431 self.assertIsInstance(sys.hexversion, int) 430 self.assertIsInstance(sys.hexversion, int)
432 431
(...skipping 11 matching lines...) Expand all
444 ) 443 )
445 self.assertIsInstance(sys.hash_info.inf, int) 444 self.assertIsInstance(sys.hash_info.inf, int)
446 self.assertIsInstance(sys.hash_info.nan, int) 445 self.assertIsInstance(sys.hash_info.nan, int)
447 self.assertIsInstance(sys.hash_info.imag, int) 446 self.assertIsInstance(sys.hash_info.imag, int)
448 447
449 self.assertIsInstance(sys.maxsize, int) 448 self.assertIsInstance(sys.maxsize, int)
450 self.assertIsInstance(sys.maxunicode, int) 449 self.assertIsInstance(sys.maxunicode, int)
451 self.assertEqual(sys.maxunicode, 0x10FFFF) 450 self.assertEqual(sys.maxunicode, 0x10FFFF)
452 self.assertIsInstance(sys.platform, str) 451 self.assertIsInstance(sys.platform, str)
453 self.assertIsInstance(sys.prefix, str) 452 self.assertIsInstance(sys.prefix, str)
454 self.assertIsInstance(sys.base_prefix, str)
455 self.assertIsInstance(sys.version, str) 453 self.assertIsInstance(sys.version, str)
456 vi = sys.version_info 454 vi = sys.version_info
457 self.assertIsInstance(vi[:], tuple) 455 self.assertIsInstance(vi[:], tuple)
458 self.assertEqual(len(vi), 5) 456 self.assertEqual(len(vi), 5)
459 self.assertIsInstance(vi[0], int) 457 self.assertIsInstance(vi[0], int)
460 self.assertIsInstance(vi[1], int) 458 self.assertIsInstance(vi[1], int)
461 self.assertIsInstance(vi[2], int) 459 self.assertIsInstance(vi[2], int)
462 self.assertIn(vi[3], ("alpha", "beta", "candidate", "final")) 460 self.assertIn(vi[3], ("alpha", "beta", "candidate", "final"))
463 self.assertIsInstance(vi[4], int) 461 self.assertIsInstance(vi[4], int)
464 self.assertIsInstance(vi.major, int) 462 self.assertIsInstance(vi.major, int)
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 stdout = subprocess.PIPE, env=env) 534 stdout = subprocess.PIPE, env=env)
537 out = p.communicate()[0].strip() 535 out = p.communicate()[0].strip()
538 self.assertEqual(out, "\xa2\n".encode("cp424")) 536 self.assertEqual(out, "\xa2\n".encode("cp424"))
539 537
540 env["PYTHONIOENCODING"] = "ascii:replace" 538 env["PYTHONIOENCODING"] = "ascii:replace"
541 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'], 539 p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'],
542 stdout = subprocess.PIPE, env=env) 540 stdout = subprocess.PIPE, env=env)
543 out = p.communicate()[0].strip() 541 out = p.communicate()[0].strip()
544 self.assertEqual(out, b'?') 542 self.assertEqual(out, b'?')
545 543
546 @unittest.skipIf(sys.base_prefix != sys.prefix,
547 'Test is not venv-compatible')
548 def test_executable(self): 544 def test_executable(self):
549 # sys.executable should be absolute 545 # sys.executable should be absolute
550 self.assertEqual(os.path.abspath(sys.executable), sys.executable) 546 self.assertEqual(os.path.abspath(sys.executable), sys.executable)
551 547
552 # Issue #7774: Ensure that sys.executable is an empty string if argv[0] 548 # Issue #7774: Ensure that sys.executable is an empty string if argv[0]
553 # has been set to an non existent program name and Python is unable to 549 # has been set to an non existent program name and Python is unable to
554 # retrieve the real program name 550 # retrieve the real program name
555 551
556 # For a normal installation, it should work without 'cwd' 552 # For a normal installation, it should work without 'cwd'
557 # argument. For test runs in the build directory, see #7774. 553 # argument. For test runs in the build directory, see #7774.
(...skipping 15 matching lines...) Expand all
573 569
574 def test_getfilesystemencoding(self): 570 def test_getfilesystemencoding(self):
575 fs_encoding = sys.getfilesystemencoding() 571 fs_encoding = sys.getfilesystemencoding()
576 if sys.platform == 'darwin': 572 if sys.platform == 'darwin':
577 expected = 'utf-8' 573 expected = 'utf-8'
578 elif sys.platform == 'win32': 574 elif sys.platform == 'win32':
579 expected = 'mbcs' 575 expected = 'mbcs'
580 else: 576 else:
581 expected = None 577 expected = None
582 self.check_fsencoding(fs_encoding, expected) 578 self.check_fsencoding(fs_encoding, expected)
583
584 def test_implementation(self):
585 # This test applies to all implementations equally.
586
587 levels = {'alpha': 0xA, 'beta': 0xB, 'candidate': 0xC, 'release': 0xF}
588
589 self.assertTrue(hasattr(sys.implementation, 'name'))
590 self.assertTrue(hasattr(sys.implementation, 'version'))
591 self.assertTrue(hasattr(sys.implementation, 'hexversion'))
592 self.assertTrue(hasattr(sys.implementation, 'cache_tag'))
593
594 version = sys.implementation.version
595 self.assertEqual(version[:2], (version.major, version.minor))
596
597 hexversion = (version.major << 24 | version.minor << 16 |
598 version.micro << 8 | levels[version.releaselevel] << 4 |
599 version.serial << 0)
600 self.assertEqual(sys.implementation.hexversion, hexversion)
601
602 # PEP 421 requires that .name be lower case.
603 self.assertEqual(sys.implementation.name,
604 sys.implementation.name.lower())
605 579
606 580
607 class SizeofTest(unittest.TestCase): 581 class SizeofTest(unittest.TestCase):
608 582
609 TPFLAGS_HAVE_GC = 1<<14 583 TPFLAGS_HAVE_GC = 1<<14
610 TPFLAGS_HEAPTYPE = 1<<9 584 TPFLAGS_HEAPTYPE = 1<<9
611 585
612 def setUp(self): 586 def setUp(self):
613 self.c = len(struct.pack('c', b' ')) 587 self.c = len(struct.pack('c', b' '))
614 self.H = len(struct.pack('H', 0)) 588 self.H = len(struct.pack('H', 0))
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 check(reversed([]), size(h + 'lP')) 767 check(reversed([]), size(h + 'lP'))
794 # long 768 # long
795 check(0, size(vh)) 769 check(0, size(vh))
796 check(1, size(vh) + self.longdigit) 770 check(1, size(vh) + self.longdigit)
797 check(-1, size(vh) + self.longdigit) 771 check(-1, size(vh) + self.longdigit)
798 PyLong_BASE = 2**sys.int_info.bits_per_digit 772 PyLong_BASE = 2**sys.int_info.bits_per_digit
799 check(int(PyLong_BASE), size(vh) + 2*self.longdigit) 773 check(int(PyLong_BASE), size(vh) + 2*self.longdigit)
800 check(int(PyLong_BASE**2-1), size(vh) + 2*self.longdigit) 774 check(int(PyLong_BASE**2-1), size(vh) + 2*self.longdigit)
801 check(int(PyLong_BASE**2), size(vh) + 3*self.longdigit) 775 check(int(PyLong_BASE**2), size(vh) + 3*self.longdigit)
802 # memoryview 776 # memoryview
803 check(memoryview(b''), size(h + 'PPiP4P2i5P3c2P')) 777 check(memoryview(b''), size(h + 'PPiP4P2i5P3cP'))
804 # module 778 # module
805 check(unittest, size(h + '3P')) 779 check(unittest, size(h + '3P'))
806 # None 780 # None
807 check(None, size(h + '')) 781 check(None, size(h + ''))
808 # NotImplementedType 782 # NotImplementedType
809 check(NotImplemented, size(h)) 783 check(NotImplemented, size(h))
810 # object 784 # object
811 check(object(), size(h + '')) 785 check(object(), size(h + ''))
812 # property (descriptor object) 786 # property (descriptor object)
813 class C(object): 787 class C(object):
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 # XXX 900 # XXX
927 # sys.flags 901 # sys.flags
928 check(sys.flags, size(vh) + self.P * len(sys.flags)) 902 check(sys.flags, size(vh) + self.P * len(sys.flags))
929 903
930 904
931 def test_main(): 905 def test_main():
932 test.support.run_unittest(SysModuleTest, SizeofTest) 906 test.support.run_unittest(SysModuleTest, SizeofTest)
933 907
934 if __name__ == "__main__": 908 if __name__ == "__main__":
935 test_main() 909 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_super.py ('k') | Lib/test/test_sysconfig.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7