<s> import os <EOL> import shutil <EOL> import tempfile <EOL> import unittest <EOL> from click . testing import CliRunner <EOL> from EulerPy import euler <EOL> from EulerPy . problem import Problem <EOL> def EulerRun ( * commands , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return CliRunner ( ) . invoke ( euler . main , commands , ** kwargs ) <EOL> def generateFile ( problem , filename = None , content = None , correct = False ) : <EOL> """<STR_LIT>""" <EOL> p = Problem ( problem ) <EOL> filename = filename or p . filename ( ) <EOL> with open ( filename , '<STR_LIT:w>' ) as f : <EOL> if correct : <EOL> f . write ( '<STR_LIT>' . format ( p . solution ) ) <EOL> elif content : <EOL> f . write ( content ) <EOL> class EulerPyTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . temp_dir = tempfile . mkdtemp ( ) <EOL> os . chdir ( self . temp_dir ) <EOL> eulerDir = os . path . dirname ( os . path . dirname ( __file__ ) ) <EOL> dataDir = os . path . join ( eulerDir , '<STR_LIT>' , '<STR_LIT:data>' ) <EOL> tempData = os . path . join ( os . getcwd ( ) , '<STR_LIT>' , '<STR_LIT:data>' ) <EOL> shutil . copytree ( dataDir , tempData ) <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . temp_dir ) <EOL> class EulerPyNoOption ( EulerPyTest ) : <EOL> def test_empty_directory_install_neutral ( self ) : <EOL> result = EulerRun ( input = '<STR_LIT:\n>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . assertTrue ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> def test_empty_directory_negative ( self ) : <EOL> result = EulerRun ( input = '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> self . assertFalse ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> def test_no_arguments_first_correct ( self ) : <EOL> generateFile ( <NUM_LIT:1> , correct = True ) <EOL> result = EulerRun ( input = '<STR_LIT:\n>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . assertTrue ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> def test_no_arguments_first_incorrect ( self ) : <EOL> generateFile ( <NUM_LIT:1> ) <EOL> result = EulerRun ( input = '<STR_LIT:\n>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> self . assertFalse ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> def test_no_arguments_keep_prefix ( self ) : <EOL> generateFile ( <NUM_LIT:1> , '<STR_LIT>' , correct = True ) <EOL> EulerRun ( input = '<STR_LIT:\n>' ) <EOL> self . assertTrue ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> def test_ambiguous_option_generate ( self ) : <EOL> result = EulerRun ( '<STR_LIT:1>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . assertTrue ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> def test_ambiguous_option_verify ( self ) : <EOL> generateFile ( <NUM_LIT:1> , correct = True ) <EOL> result = EulerRun ( '<STR_LIT:1>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . assertFalse ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> class EulerPyCheat ( EulerPyTest ) : <EOL> def test_cheat_neutral ( self ) : <EOL> result = EulerRun ( '<STR_LIT:-c>' , input = '<STR_LIT:\n>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> def test_cheat_long_flag ( self ) : <EOL> result = EulerRun ( '<STR_LIT>' , input = '<STR_LIT:\n>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> def test_cheat_positive ( self ) : <EOL> result = EulerRun ( '<STR_LIT:-c>' , input = '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> def test_chest_specific ( self ) : <EOL> result = EulerRun ( '<STR_LIT:-c>' , '<STR_LIT:2>' , input = '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> def test_cheat_not_in_solutions ( self ) : <EOL> result = EulerRun ( '<STR_LIT:-c>' , '<STR_LIT>' , input = '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> class EulerPyGenerate ( EulerPyTest ) : <EOL> def test_generate_neutral ( self ) : <EOL> result = EulerRun ( '<STR_LIT>' , input = '<STR_LIT:\n>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . assertTrue ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> def test_generate_negative ( self ) : <EOL> result = EulerRun ( '<STR_LIT>' , input = '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> self . assertFalse ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> def test_generate_specific ( self ) : <EOL> result = EulerRun ( '<STR_LIT>' , '<STR_LIT:5>' , input = '<STR_LIT:\n>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . assertTrue ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> def test_generate_overwrite_positive ( self ) : <EOL> generateFile ( <NUM_LIT:1> ) <EOL> result = EulerRun ( '<STR_LIT>' , '<STR_LIT:1>' , input = '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> with open ( '<STR_LIT>' ) as f : <EOL> self . assertNotEqual ( f . read ( ) , '<STR_LIT>' ) <EOL> def test_generate_overwrite_neutral ( self ) : <EOL> generateFile ( <NUM_LIT:1> ) <EOL> result = EulerRun ( '<STR_LIT>' , '<STR_LIT:1>' , input = '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> with open ( '<STR_LIT>' ) as f : <EOL> self . assertEqual ( f . read ( ) , '<STR_LIT>' ) <EOL> def test_generate_overwrite_skipped ( self ) : <EOL> generateFile ( <NUM_LIT:1> , '<STR_LIT>' ) <EOL> result = EulerRun ( '<STR_LIT>' , '<STR_LIT:1>' , input = '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . assertTrue ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> def test_generate_copy_resources ( self ) : <EOL> result = EulerRun ( '<STR_LIT>' , '<STR_LIT>' , input = '<STR_LIT:\n>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . assertTrue ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> resource = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> self . assertTrue ( os . path . isfile ( resource ) ) <EOL> class EulerPyPreview ( EulerPyTest ) : <EOL> def test_preview ( self ) : <EOL> result = EulerRun ( '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> def test_preview_specific ( self ) : <EOL> result = EulerRun ( '<STR_LIT>' , '<STR_LIT:5>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> def test_preview_next_behaviour ( self ) : <EOL> generateFile ( <NUM_LIT:1> ) <EOL> result = EulerRun ( '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> def test_preview_nonexistent ( self ) : <EOL> result = EulerRun ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> class EulerPySkip ( EulerPyTest ) : <EOL> def test_skip_neutral ( self ) : <EOL> generateFile ( <NUM_LIT:1> ) <EOL> result = EulerRun ( '<STR_LIT>' , input = '<STR_LIT:\n>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> self . assertTrue ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> def test_skip_positive ( self ) : <EOL> generateFile ( <NUM_LIT:1> ) <EOL> result = EulerRun ( '<STR_LIT>' , input = '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . assertFalse ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> def test_skip_prefixed_file ( self ) : <EOL> generateFile ( <NUM_LIT:1> , '<STR_LIT>' ) <EOL> result = EulerRun ( '<STR_LIT>' , input = '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . assertFalse ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> class EulerPyVerify ( EulerPyTest ) : <EOL> def test_verify ( self ) : <EOL> generateFile ( <NUM_LIT:1> ) <EOL> result = EulerRun ( '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> def test_verify_specific ( self ) : <EOL> generateFile ( <NUM_LIT:5> ) <EOL> result = EulerRun ( '<STR_LIT>' , '<STR_LIT:5>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> def test_verify_glob ( self ) : <EOL> generateFile ( <NUM_LIT:1> , '<STR_LIT>' ) <EOL> result = EulerRun ( '<STR_LIT>' , '<STR_LIT:1>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> def test_verify_sorted_glob ( self ) : <EOL> generateFile ( <NUM_LIT:1> , '<STR_LIT>' ) <EOL> generateFile ( <NUM_LIT:1> , '<STR_LIT>' ) <EOL> result = EulerRun ( '<STR_LIT>' , '<STR_LIT:1>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> self . assertNotIn ( '<STR_LIT>' , result . output ) <EOL> def test_verify_correct ( self ) : <EOL> generateFile ( <NUM_LIT:1> , correct = True ) <EOL> result = EulerRun ( '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> def test_verify_non_existent_problem_file ( self ) : <EOL> result = EulerRun ( '<STR_LIT>' , '<STR_LIT:5>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> def test_verify_file_with_multiline_output ( self ) : <EOL> generateFile ( <NUM_LIT:1> , content = '<STR_LIT>' ) <EOL> result = EulerRun ( '<STR_LIT>' , '<STR_LIT:1>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> def test_verify_error_file ( self ) : <EOL> generateFile ( <NUM_LIT:1> , content = '<STR_LIT>' ) <EOL> result = EulerRun ( '<STR_LIT>' , '<STR_LIT:1>' ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> def test_verify_prefixed_file ( self ) : <EOL> generateFile ( <NUM_LIT:1> , '<STR_LIT>' , correct = True ) <EOL> result = EulerRun ( '<STR_LIT>' , '<STR_LIT:1>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> def test_verify_prefixed_unskip ( self ) : <EOL> generateFile ( <NUM_LIT:1> , '<STR_LIT>' , correct = True ) <EOL> result = EulerRun ( '<STR_LIT>' , '<STR_LIT:1>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . assertTrue ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> class EulerPyVerifyAll ( EulerPyTest ) : <EOL> def test_verify_all ( self ) : <EOL> generateFile ( <NUM_LIT:1> , correct = True ) <EOL> generateFile ( <NUM_LIT:2> , '<STR_LIT>' , correct = True ) <EOL> generateFile ( <NUM_LIT:4> ) <EOL> generateFile ( <NUM_LIT:5> , content = '<STR_LIT>' ) <EOL> result = EulerRun ( '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> self . assertTrue ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( os . path . isfile ( '<STR_LIT>' ) ) <EOL> def test_verify_all_no_files ( self ) : <EOL> result = EulerRun ( '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:1> ) <EOL> class EulerPyMisc ( EulerPyTest ) : <EOL> def test_help_option ( self ) : <EOL> result = EulerRun ( '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> self . assertIn ( '<STR_LIT>' , result . output ) <EOL> def test_version_option ( self ) : <EOL> result = EulerRun ( '<STR_LIT>' ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) </s>
