<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import importlib . machinery <EOL> import unittest <EOL> from unittest import mock <EOL> import shutil <EOL> import subprocess <EOL> import sysconfig <EOL> import tempfile <EOL> import textwrap <EOL> from test import support <EOL> from test . script_helper import assert_python_ok , temp_dir <EOL> if not sysconfig . is_python_build ( ) : <EOL> raise unittest . SkipTest ( '<STR_LIT>' ) <EOL> basepath = os . path . join ( os . path . dirname ( os . path . dirname ( os . path . dirname ( __file__ ) ) ) , <EOL> '<STR_LIT>' ) <EOL> scriptsdir = os . path . join ( basepath , '<STR_LIT>' ) <EOL> class ReindentTests ( unittest . TestCase ) : <EOL> script = os . path . join ( scriptsdir , '<STR_LIT>' ) <EOL> def test_noargs ( self ) : <EOL> assert_python_ok ( self . script ) <EOL> def test_help ( self ) : <EOL> rc , out , err = assert_python_ok ( self . script , '<STR_LIT>' ) <EOL> self . assertEqual ( out , b'<STR_LIT>' ) <EOL> self . assertGreater ( err , b'<STR_LIT>' ) <EOL> class PindentTests ( unittest . TestCase ) : <EOL> script = os . path . join ( scriptsdir , '<STR_LIT>' ) <EOL> def assertFileEqual ( self , fn1 , fn2 ) : <EOL> with open ( fn1 ) as f1 , open ( fn2 ) as f2 : <EOL> self . assertEqual ( f1 . readlines ( ) , f2 . readlines ( ) ) <EOL> def pindent ( self , source , * args ) : <EOL> with subprocess . Popen ( <EOL> ( sys . executable , self . script ) + args , <EOL> stdin = subprocess . PIPE , stdout = subprocess . PIPE , <EOL> universal_newlines = True ) as proc : <EOL> out , err = proc . communicate ( source ) <EOL> self . assertIsNone ( err ) <EOL> return out <EOL> def lstriplines ( self , data ) : <EOL> return '<STR_LIT:\n>' . join ( line . lstrip ( ) for line in data . splitlines ( ) ) + '<STR_LIT:\n>' <EOL> def test_selftest ( self ) : <EOL> self . maxDiff = None <EOL> with temp_dir ( ) as directory : <EOL> data_path = os . path . join ( directory , '<STR_LIT>' ) <EOL> with open ( self . script ) as f : <EOL> closed = f . read ( ) <EOL> with open ( data_path , '<STR_LIT:w>' ) as f : <EOL> f . write ( closed ) <EOL> rc , out , err = assert_python_ok ( self . script , '<STR_LIT>' , data_path ) <EOL> self . assertEqual ( out , b'<STR_LIT>' ) <EOL> self . assertEqual ( err , b'<STR_LIT>' ) <EOL> backup = data_path + '<STR_LIT>' <EOL> self . assertTrue ( os . path . exists ( backup ) ) <EOL> with open ( backup ) as f : <EOL> self . assertEqual ( f . read ( ) , closed ) <EOL> with open ( data_path ) as f : <EOL> clean = f . read ( ) <EOL> compile ( clean , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( self . pindent ( clean , '<STR_LIT:-c>' ) , closed ) <EOL> self . assertEqual ( self . pindent ( closed , '<STR_LIT>' ) , clean ) <EOL> rc , out , err = assert_python_ok ( self . script , '<STR_LIT:-c>' , data_path ) <EOL> self . assertEqual ( out , b'<STR_LIT>' ) <EOL> self . assertEqual ( err , b'<STR_LIT>' ) <EOL> with open ( backup ) as f : <EOL> self . assertEqual ( f . read ( ) , clean ) <EOL> with open ( data_path ) as f : <EOL> self . assertEqual ( f . read ( ) , closed ) <EOL> broken = self . lstriplines ( closed ) <EOL> with open ( data_path , '<STR_LIT:w>' ) as f : <EOL> f . write ( broken ) <EOL> rc , out , err = assert_python_ok ( self . script , '<STR_LIT>' , data_path ) <EOL> self . assertEqual ( out , b'<STR_LIT>' ) <EOL> self . assertEqual ( err , b'<STR_LIT>' ) <EOL> with open ( backup ) as f : <EOL> self . assertEqual ( f . read ( ) , broken ) <EOL> with open ( data_path ) as f : <EOL> indented = f . read ( ) <EOL> compile ( indented , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( self . pindent ( broken , '<STR_LIT>' ) , indented ) <EOL> def pindent_test ( self , clean , closed ) : <EOL> self . assertEqual ( self . pindent ( clean , '<STR_LIT:-c>' ) , closed ) <EOL> self . assertEqual ( self . pindent ( closed , '<STR_LIT>' ) , clean ) <EOL> broken = self . lstriplines ( closed ) <EOL> self . assertEqual ( self . pindent ( broken , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:4>' ) , closed ) <EOL> def test_statements ( self ) : <EOL> clean = textwrap . dedent ( """<STR_LIT>""" ) <EOL> closed = textwrap . dedent ( """<STR_LIT>""" ) <EOL> self . pindent_test ( clean , closed ) <EOL> def test_multilevel ( self ) : <EOL> clean = textwrap . dedent ( """<STR_LIT>""" ) <EOL> closed = textwrap . dedent ( """<STR_LIT>""" ) <EOL> self . pindent_test ( clean , closed ) <EOL> def test_preserve_indents ( self ) : <EOL> clean = textwrap . dedent ( """<STR_LIT>""" ) <EOL> closed = textwrap . dedent ( """<STR_LIT>""" ) <EOL> self . assertEqual ( self . pindent ( clean , '<STR_LIT:-c>' ) , closed ) <EOL> self . assertEqual ( self . pindent ( closed , '<STR_LIT>' ) , clean ) <EOL> broken = self . lstriplines ( closed ) <EOL> self . assertEqual ( self . pindent ( broken , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , closed ) <EOL> clean = textwrap . dedent ( """<STR_LIT>""" ) <EOL> closed = textwrap . dedent ( """<STR_LIT>""" ) <EOL> self . assertEqual ( self . pindent ( clean , '<STR_LIT:-c>' ) , closed ) <EOL> self . assertEqual ( self . pindent ( closed , '<STR_LIT>' ) , clean ) <EOL> broken = self . lstriplines ( closed ) <EOL> self . assertEqual ( self . pindent ( broken , '<STR_LIT>' ) , closed ) <EOL> def test_escaped_newline ( self ) : <EOL> clean = textwrap . dedent ( """<STR_LIT>""" ) <EOL> closed = textwrap . dedent ( """<STR_LIT>""" ) <EOL> self . assertEqual ( self . pindent ( clean , '<STR_LIT:-c>' ) , closed ) <EOL> self . assertEqual ( self . pindent ( closed , '<STR_LIT>' ) , clean ) <EOL> def test_empty_line ( self ) : <EOL> clean = textwrap . dedent ( """<STR_LIT>""" ) <EOL> closed = textwrap . dedent ( """<STR_LIT>""" ) <EOL> self . pindent_test ( clean , closed ) <EOL> def test_oneline ( self ) : <EOL> clean = textwrap . dedent ( """<STR_LIT>""" ) <EOL> closed = textwrap . dedent ( """<STR_LIT>""" ) <EOL> self . pindent_test ( clean , closed ) <EOL> class TestSundryScripts ( unittest . TestCase ) : <EOL> whitelist = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> blacklist = [ '<STR_LIT>' ] <EOL> windows_only = [ '<STR_LIT>' ] <EOL> other = [ '<STR_LIT>' ] <EOL> skiplist = blacklist + whitelist + windows_only + other <EOL> def setUp ( self ) : <EOL> cm = support . DirsOnSysPath ( scriptsdir ) <EOL> cm . __enter__ ( ) <EOL> self . addCleanup ( cm . __exit__ ) <EOL> def test_sundry ( self ) : <EOL> for fn in os . listdir ( scriptsdir ) : <EOL> if fn . endswith ( '<STR_LIT>' ) and fn not in self . skiplist : <EOL> __import__ ( fn [ : - <NUM_LIT:3> ] ) <EOL> @ unittest . skipIf ( sys . platform != "<STR_LIT:win32>" , "<STR_LIT>" ) <EOL> def test_sundry_windows ( self ) : <EOL> for fn in self . windows_only : <EOL> __import__ ( fn [ : - <NUM_LIT:3> ] ) <EOL> @ unittest . skipIf ( not support . threading , "<STR_LIT>" ) <EOL> def test_analyze_dxp_import ( self ) : <EOL> if hasattr ( sys , '<STR_LIT>' ) : <EOL> import analyze_dxp <EOL> else : <EOL> with self . assertRaises ( RuntimeError ) : <EOL> import analyze_dxp <EOL> class PdepsTests ( unittest . TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( self ) : <EOL> path = os . path . join ( scriptsdir , '<STR_LIT>' ) <EOL> loader = importlib . machinery . SourceFileLoader ( '<STR_LIT>' , path ) <EOL> self . pdeps = loader . load_module ( ) <EOL> @ classmethod <EOL> def tearDownClass ( self ) : <EOL> if '<STR_LIT>' in sys . modules : <EOL> del sys . modules [ '<STR_LIT>' ] <EOL> def test_process_errors ( self ) : <EOL> with tempfile . TemporaryDirectory ( ) as tmpdir : <EOL> fn = os . path . join ( tmpdir , '<STR_LIT:foo>' ) <EOL> with open ( fn , '<STR_LIT:w>' ) as stream : <EOL> stream . write ( "<STR_LIT>" ) <EOL> self . pdeps . process ( fn , { } ) <EOL> def test_inverse_attribute_error ( self ) : <EOL> self . pdeps . inverse ( { '<STR_LIT:a>' : [ ] } ) <EOL> class Gprof2htmlTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> path = os . path . join ( scriptsdir , '<STR_LIT>' ) <EOL> loader = importlib . machinery . SourceFileLoader ( '<STR_LIT>' , path ) <EOL> self . gprof = loader . load_module ( ) <EOL> oldargv = sys . argv <EOL> def fixup ( ) : <EOL> sys . argv = oldargv <EOL> self . addCleanup ( fixup ) <EOL> sys . argv = [ ] <EOL> def test_gprof ( self ) : <EOL> with mock . patch . object ( self . gprof , '<STR_LIT>' ) as wmock , tempfile . TemporaryDirectory ( ) as tmpdir : <EOL> fn = os . path . join ( tmpdir , '<STR_LIT:abc>' ) <EOL> open ( fn , '<STR_LIT:w>' ) . close ( ) <EOL> sys . argv = [ '<STR_LIT>' , fn ] <EOL> self . gprof . main ( ) <EOL> self . assertTrue ( wmock . open . called ) <EOL> with support . DirsOnSysPath ( os . path . join ( basepath , '<STR_LIT>' ) ) : <EOL> from test_unparse import UnparseTestCase <EOL> from test_unparse import DirectoryTestCase <EOL> def test_main ( ) : <EOL> support . run_unittest ( * [ obj for obj in globals ( ) . values ( ) <EOL> if isinstance ( obj , type ) ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
