<s> import os <EOL> import platform <EOL> import subprocess <EOL> import sys <EOL> import unittest <EOL> import warnings <EOL> from test import support <EOL> class PlatformTest ( unittest . TestCase ) : <EOL> def test_architecture ( self ) : <EOL> res = platform . architecture ( ) <EOL> @ support . skip_unless_symlink <EOL> def test_architecture_via_symlink ( self ) : <EOL> if sys . platform == "<STR_LIT:win32>" : <EOL> os . environ [ "<STR_LIT>" ] = "<STR_LIT>" . format ( <EOL> os . path . dirname ( sys . executable ) , os . environ [ "<STR_LIT>" ] ) <EOL> def get ( python ) : <EOL> cmd = [ python , '<STR_LIT:-c>' , <EOL> '<STR_LIT>' ] <EOL> p = subprocess . Popen ( cmd , stdout = subprocess . PIPE ) <EOL> return p . communicate ( ) <EOL> real = os . path . realpath ( sys . executable ) <EOL> link = os . path . abspath ( support . TESTFN ) <EOL> os . symlink ( real , link ) <EOL> try : <EOL> self . assertEqual ( get ( real ) , get ( link ) ) <EOL> finally : <EOL> os . remove ( link ) <EOL> def test_platform ( self ) : <EOL> for aliased in ( False , True ) : <EOL> for terse in ( False , True ) : <EOL> res = platform . platform ( aliased , terse ) <EOL> def test_system ( self ) : <EOL> res = platform . system ( ) <EOL> def test_node ( self ) : <EOL> res = platform . node ( ) <EOL> def test_release ( self ) : <EOL> res = platform . release ( ) <EOL> def test_version ( self ) : <EOL> res = platform . version ( ) <EOL> def test_machine ( self ) : <EOL> res = platform . machine ( ) <EOL> def test_processor ( self ) : <EOL> res = platform . processor ( ) <EOL> def setUp ( self ) : <EOL> self . save_version = sys . version <EOL> self . save_mercurial = sys . _mercurial <EOL> self . save_platform = sys . platform <EOL> def tearDown ( self ) : <EOL> sys . version = self . save_version <EOL> sys . _mercurial = self . save_mercurial <EOL> sys . platform = self . save_platform <EOL> def test_sys_version ( self ) : <EOL> for input , output in ( <EOL> ( '<STR_LIT>' , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:1>' , '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ) : <EOL> ( name , version , branch , revision , buildno , builddate , compiler ) = platform . _sys_version ( input ) <EOL> self . assertEqual ( <EOL> ( name , version , '<STR_LIT>' , '<STR_LIT>' , buildno , builddate , compiler ) , output ) <EOL> sys_versions = { <EOL> ( "<STR_LIT>" , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , self . save_platform ) <EOL> : <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) , <EOL> ( "<STR_LIT>" , None , "<STR_LIT>" ) <EOL> : <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , None , "<STR_LIT>" ) <EOL> : <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , None , "<STR_LIT>" ) <EOL> : <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , "<STR_LIT>" ) <EOL> : <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , self . save_platform ) <EOL> : <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> "<STR_LIT>" ) <EOL> } <EOL> for ( version_tag , subversion , sys_platform ) , info in sys_versions . items ( ) : <EOL> sys . version = version_tag <EOL> if subversion is None : <EOL> if hasattr ( sys , "<STR_LIT>" ) : <EOL> del sys . _mercurial <EOL> else : <EOL> sys . _mercurial = subversion <EOL> if sys_platform is not None : <EOL> sys . platform = sys_platform <EOL> self . assertEqual ( platform . python_implementation ( ) , info [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( platform . python_version ( ) , info [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( platform . python_branch ( ) , info [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( platform . python_revision ( ) , info [ <NUM_LIT:3> ] ) <EOL> self . assertEqual ( platform . python_build ( ) , info [ <NUM_LIT:4> ] ) <EOL> self . assertEqual ( platform . python_compiler ( ) , info [ <NUM_LIT:5> ] ) <EOL> def test_system_alias ( self ) : <EOL> res = platform . system_alias ( <EOL> platform . system ( ) , <EOL> platform . release ( ) , <EOL> platform . version ( ) , <EOL> ) <EOL> def test_uname ( self ) : <EOL> res = platform . uname ( ) <EOL> self . assertTrue ( any ( res ) ) <EOL> self . assertEqual ( res [ <NUM_LIT:0> ] , res . system ) <EOL> self . assertEqual ( res [ <NUM_LIT:1> ] , res . node ) <EOL> self . assertEqual ( res [ <NUM_LIT:2> ] , res . release ) <EOL> self . assertEqual ( res [ <NUM_LIT:3> ] , res . version ) <EOL> self . assertEqual ( res [ <NUM_LIT:4> ] , res . machine ) <EOL> self . assertEqual ( res [ <NUM_LIT:5> ] , res . processor ) <EOL> @ unittest . skipUnless ( sys . platform . startswith ( '<STR_LIT>' ) , "<STR_LIT>" ) <EOL> def test_uname_win32_ARCHITEW6432 ( self ) : <EOL> try : <EOL> with support . EnvironmentVarGuard ( ) as environ : <EOL> if '<STR_LIT>' in environ : <EOL> del environ [ '<STR_LIT>' ] <EOL> environ [ '<STR_LIT>' ] = '<STR_LIT:foo>' <EOL> platform . _uname_cache = None <EOL> system , node , release , version , machine , processor = platform . uname ( ) <EOL> self . assertEqual ( machine , '<STR_LIT:foo>' ) <EOL> environ [ '<STR_LIT>' ] = '<STR_LIT:bar>' <EOL> platform . _uname_cache = None <EOL> system , node , release , version , machine , processor = platform . uname ( ) <EOL> self . assertEqual ( machine , '<STR_LIT:bar>' ) <EOL> finally : <EOL> platform . _uname_cache = None <EOL> def test_java_ver ( self ) : <EOL> res = platform . java_ver ( ) <EOL> if sys . platform == '<STR_LIT>' : <EOL> self . assertTrue ( all ( res ) ) <EOL> def test_win32_ver ( self ) : <EOL> res = platform . win32_ver ( ) <EOL> def test_mac_ver ( self ) : <EOL> res = platform . mac_ver ( ) <EOL> if platform . uname ( ) . system == '<STR_LIT>' : <EOL> fd = os . popen ( '<STR_LIT>' , '<STR_LIT:r>' ) <EOL> real_ver = None <EOL> for ln in fd : <EOL> if ln . startswith ( '<STR_LIT>' ) : <EOL> real_ver = ln . strip ( ) . split ( ) [ - <NUM_LIT:1> ] <EOL> break <EOL> fd . close ( ) <EOL> self . assertFalse ( real_ver is None ) <EOL> result_list = res [ <NUM_LIT:0> ] . split ( '<STR_LIT:.>' ) <EOL> expect_list = real_ver . split ( '<STR_LIT:.>' ) <EOL> len_diff = len ( result_list ) - len ( expect_list ) <EOL> if len_diff > <NUM_LIT:0> : <EOL> expect_list . extend ( [ '<STR_LIT:0>' ] * len_diff ) <EOL> self . assertEqual ( result_list , expect_list ) <EOL> self . assertEqual ( res [ <NUM_LIT:1> ] , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if sys . byteorder == '<STR_LIT>' : <EOL> self . assertIn ( res [ <NUM_LIT:2> ] , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> else : <EOL> self . assertEqual ( res [ <NUM_LIT:2> ] , '<STR_LIT>' ) <EOL> @ unittest . skipUnless ( sys . platform == '<STR_LIT>' , "<STR_LIT>" ) <EOL> def test_mac_ver_with_fork ( self ) : <EOL> pid = os . fork ( ) <EOL> if pid == <NUM_LIT:0> : <EOL> info = platform . mac_ver ( ) <EOL> os . _exit ( <NUM_LIT:0> ) <EOL> else : <EOL> cpid , sts = os . waitpid ( pid , <NUM_LIT:0> ) <EOL> self . assertEqual ( cpid , pid ) <EOL> self . assertEqual ( sts , <NUM_LIT:0> ) <EOL> def test_dist ( self ) : <EOL> res = platform . dist ( ) <EOL> def test_libc_ver ( self ) : <EOL> import os <EOL> if os . path . isdir ( sys . executable ) and os . path . exists ( sys . executable + '<STR_LIT>' ) : <EOL> executable = sys . executable + '<STR_LIT>' <EOL> else : <EOL> executable = sys . executable <EOL> res = platform . libc_ver ( executable ) <EOL> def test_parse_release_file ( self ) : <EOL> for input , output in ( <EOL> ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT:5>' , '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT:4>' , '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT:4>' , None ) ) , <EOL> ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ) : <EOL> self . assertEqual ( platform . _parse_release_file ( input ) , output ) <EOL> def test_popen ( self ) : <EOL> mswindows = ( sys . platform == "<STR_LIT:win32>" ) <EOL> if mswindows : <EOL> command = '<STR_LIT>' . format ( sys . executable ) <EOL> else : <EOL> command = "<STR_LIT>" . format ( sys . executable ) <EOL> with warnings . catch_warnings ( ) : <EOL> warnings . simplefilter ( "<STR_LIT:ignore>" , DeprecationWarning ) <EOL> with platform . popen ( command ) as stdout : <EOL> hello = stdout . read ( ) . strip ( ) <EOL> stdout . close ( ) <EOL> self . assertEqual ( hello , "<STR_LIT>" ) <EOL> data = '<STR_LIT>' <EOL> if mswindows : <EOL> command = '<STR_LIT>' <EOL> else : <EOL> command = "<STR_LIT>" <EOL> command = command . format ( sys . executable ) <EOL> with warnings . catch_warnings ( ) : <EOL> warnings . simplefilter ( "<STR_LIT:ignore>" , DeprecationWarning ) <EOL> with platform . popen ( command , '<STR_LIT:w>' ) as stdin : <EOL> stdout = stdin . write ( data ) <EOL> ret = stdin . close ( ) <EOL> self . assertIsNotNone ( ret ) <EOL> if os . name == '<STR_LIT>' : <EOL> returncode = ret <EOL> else : <EOL> returncode = ret >> <NUM_LIT:8> <EOL> self . assertEqual ( returncode , len ( data ) ) <EOL> def test_main ( ) : <EOL> support . run_unittest ( <EOL> PlatformTest <EOL> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test_main ( ) </s>
