<s> """<STR_LIT>""" <EOL> import os <EOL> import unittest <EOL> from retdec import DEFAULT_API_URL <EOL> from retdec . decompilation import Decompilation <EOL> from retdec . decompilation_phase import DecompilationPhase <EOL> from retdec . decompiler import Decompiler <EOL> from retdec . tools . decompiler import NoProgressDisplayer <EOL> from retdec . tools . decompiler import ProgressBarDisplayer <EOL> from retdec . tools . decompiler import ProgressLogDisplayer <EOL> from retdec . tools . decompiler import display_download_progress <EOL> from retdec . tools . decompiler import get_output_dir <EOL> from retdec . tools . decompiler import get_progress_displayer <EOL> from retdec . tools . decompiler import main <EOL> from retdec . tools . decompiler import parse_args <EOL> from tests import mock <EOL> from tests . tools import ToolTestsBase <EOL> class ProgressBarDisplayerTests ( ToolTestsBase ) : <EOL> """<STR_LIT>""" <EOL> def test_display_decompilation_progress_successful_decompilation ( self ) : <EOL> displayer = ProgressBarDisplayer ( ) <EOL> decompilation = mock . Mock ( spec_set = Decompilation ) <EOL> decompilation . id = '<STR_LIT>' <EOL> decompilation . get_completion . return_value = <NUM_LIT:100> <EOL> decompilation . has_finished . return_value = True <EOL> decompilation . has_succeeded . return_value = True <EOL> displayer . display_decompilation_progress ( decompilation ) <EOL> self . assertEqual ( <EOL> self . stdout . getvalue ( ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_display_decompilation_progress_failed_decompilation ( self ) : <EOL> displayer = ProgressBarDisplayer ( ) <EOL> decompilation = mock . Mock ( spec_set = Decompilation ) <EOL> decompilation . id = '<STR_LIT>' <EOL> decompilation . get_completion . return_value = <NUM_LIT:100> <EOL> decompilation . has_finished . return_value = True <EOL> decompilation . has_succeeded . return_value = False <EOL> displayer . display_decompilation_progress ( decompilation ) <EOL> self . assertEqual ( <EOL> self . stdout . getvalue ( ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_display_download_progress_does_nothing ( self ) : <EOL> displayer = ProgressBarDisplayer ( ) <EOL> displayer . display_download_progress ( '<STR_LIT>' ) <EOL> self . assertEqual ( self . stdout . getvalue ( ) , '<STR_LIT>' ) <EOL> def test_repr_returns_correct_value ( self ) : <EOL> displayer = ProgressBarDisplayer ( ) <EOL> self . assertEqual ( <EOL> repr ( displayer ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> class ProgressLogDisplayerTests ( ToolTestsBase ) : <EOL> """<STR_LIT>""" <EOL> def test_display_decompilation_progress_displays_correct_value_successful_decompilation ( self ) : <EOL> displayer = ProgressLogDisplayer ( ) <EOL> d = mock . Mock ( spec_set = Decompilation ) <EOL> d . id = '<STR_LIT>' <EOL> d . has_finished . return_value = True <EOL> d . has_failed . return_value = False <EOL> d . get_phases . return_value = [ <EOL> DecompilationPhase ( <EOL> name = '<STR_LIT>' , <EOL> part = None , <EOL> description = '<STR_LIT>' , <EOL> completion = <NUM_LIT:0> <EOL> ) , <EOL> DecompilationPhase ( <EOL> name = '<STR_LIT>' , <EOL> part = '<STR_LIT>' , <EOL> description = '<STR_LIT>' , <EOL> completion = <NUM_LIT:5> <EOL> ) , <EOL> DecompilationPhase ( <EOL> name = '<STR_LIT>' , <EOL> part = None , <EOL> description = '<STR_LIT>' , <EOL> completion = <NUM_LIT:100> <EOL> ) <EOL> ] <EOL> displayer . display_decompilation_progress ( d ) <EOL> self . assertEqual ( <EOL> self . stdout . getvalue ( ) , """<STR_LIT>""" . lstrip ( ) ) <EOL> def test_display_decompilation_progress_displays_correct_value_failed_decompilation ( self ) : <EOL> displayer = ProgressLogDisplayer ( ) <EOL> d = mock . Mock ( spec_set = Decompilation ) <EOL> d . id = '<STR_LIT>' <EOL> d . has_finished . return_value = True <EOL> d . has_failed . return_value = True <EOL> d . get_phases . return_value = [ <EOL> DecompilationPhase ( <EOL> name = '<STR_LIT>' , <EOL> part = None , <EOL> description = '<STR_LIT>' , <EOL> completion = <NUM_LIT:0> <EOL> ) <EOL> ] <EOL> displayer . display_decompilation_progress ( d ) <EOL> self . assertEqual ( <EOL> self . stdout . getvalue ( ) , """<STR_LIT>""" . lstrip ( ) ) <EOL> def test_display_download_progress_displays_correct_value ( self ) : <EOL> displayer = ProgressLogDisplayer ( ) <EOL> displayer . display_download_progress ( '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> self . stdout . getvalue ( ) , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> ) <EOL> def test_repr_returns_correct_value ( self ) : <EOL> displayer = ProgressLogDisplayer ( ) <EOL> self . assertEqual ( <EOL> repr ( displayer ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> class NoProgressDisplayerTests ( ToolTestsBase ) : <EOL> """<STR_LIT>""" <EOL> def test_display_decompilation_progress_does_nothing ( self ) : <EOL> displayer = NoProgressDisplayer ( ) <EOL> displayer . display_decompilation_progress ( mock . Mock ( ) ) <EOL> self . assertEqual ( self . stdout . getvalue ( ) , '<STR_LIT>' ) <EOL> def test_display_download_progress_does_nothing ( self ) : <EOL> displayer = NoProgressDisplayer ( ) <EOL> displayer . display_download_progress ( '<STR_LIT>' ) <EOL> self . assertEqual ( self . stdout . getvalue ( ) , '<STR_LIT>' ) <EOL> def test_repr_returns_correct_value ( self ) : <EOL> displayer = NoProgressDisplayer ( ) <EOL> self . assertEqual ( <EOL> repr ( displayer ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> class ParseArgsTests ( ToolTestsBase ) : <EOL> """<STR_LIT>""" <EOL> def test_file_is_required ( self ) : <EOL> with self . assertRaises ( SystemExit ) as cm : <EOL> parse_args ( [ '<STR_LIT>' ] ) <EOL> self . assertNotEqual ( cm . exception . code , <NUM_LIT:0> ) <EOL> def test_file_is_parsed_correctly ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( args . input_file , '<STR_LIT>' ) <EOL> def test_api_key_is_parsed_correctly_short_form ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( args . api_key , '<STR_LIT>' ) <EOL> def test_api_key_is_parsed_correctly_long_form ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( args . api_key , '<STR_LIT>' ) <EOL> def test_api_url_is_parsed_correctly_short_form ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( args . api_url , '<STR_LIT>' ) <EOL> def test_api_url_is_parsed_correctly_long_form ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( args . api_url , '<STR_LIT>' ) <EOL> def test_mode_is_set_to_none_when_not_given ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertIsNone ( args . mode ) <EOL> def test_mode_is_parsed_correctly_short_form ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( args . mode , '<STR_LIT>' ) <EOL> def test_mode_is_parsed_correctly_long_form ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( args . mode , '<STR_LIT>' ) <EOL> def test_output_dir_is_set_to_none_when_not_given ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertIsNone ( args . output_dir ) <EOL> def test_output_dir_is_parsed_correctly_short_form ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( args . output_dir , '<STR_LIT>' ) <EOL> def test_output_dir_is_parsed_correctly_long_form ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( args . output_dir , '<STR_LIT>' ) <EOL> def test_quiet_is_set_to_false_when_not_given ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertFalse ( args . quiet ) <EOL> def test_quiet_is_set_to_true_when_given_in_short_form ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( args . quiet ) <EOL> def test_quiet_is_set_to_true_when_given_in_long_form ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( args . quiet ) <EOL> def test_generate_archive_is_set_to_false_when_with_archive_not_given ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertFalse ( args . generate_archive ) <EOL> def test_generate_archive_is_set_to_true_when_with_archive_given ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( args . generate_archive ) <EOL> def test_brief_is_set_to_false_when_not_given ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertFalse ( args . brief ) <EOL> def test_brief_is_set_to_true_when_given_in_short_form ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( args . brief ) <EOL> def test_brief_is_set_to_true_when_given_in_long_form ( self ) : <EOL> args = parse_args ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( args . brief ) <EOL> class FakeArguments : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . __dict__ . update ( kwargs ) <EOL> class GetOutputDirTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_returns_correct_dir_when_output_dir_is_not_given ( self ) : <EOL> input_file = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> args = FakeArguments ( input_file = input_file , output_dir = None ) <EOL> output_dir = get_output_dir ( args ) <EOL> self . assertEqual ( <EOL> output_dir , <EOL> os . path . join ( os . getcwd ( ) , '<STR_LIT>' ) <EOL> ) <EOL> self . assertTrue ( os . path . isabs ( output_dir ) ) <EOL> def test_returns_correct_dir_when_output_dir_is_given ( self ) : <EOL> input_file = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> args = FakeArguments ( input_file = input_file , output_dir = '<STR_LIT>' ) <EOL> output_dir = get_output_dir ( args ) <EOL> self . assertEqual ( <EOL> output_dir , <EOL> os . path . join ( os . getcwd ( ) , '<STR_LIT>' ) <EOL> ) <EOL> self . assertTrue ( os . path . isabs ( output_dir ) ) <EOL> class GetProgressCallbackTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_returns_progress_log_displayer_by_default ( self ) : <EOL> args = FakeArguments ( quiet = False , brief = False ) <EOL> displayer = get_progress_displayer ( args ) <EOL> self . assertIsInstance ( displayer , ProgressLogDisplayer ) <EOL> def test_returns_progress_bar_displayer_if_brief_is_set ( self ) : <EOL> args = FakeArguments ( quiet = False , brief = True ) <EOL> displayer = get_progress_displayer ( args ) <EOL> self . assertIsInstance ( displayer , ProgressBarDisplayer ) <EOL> def test_returns_no_progress_displayer_if_quiet_is_set ( self ) : <EOL> args = FakeArguments ( quiet = True , brief = False ) <EOL> displayer = get_progress_displayer ( args ) <EOL> self . assertIsInstance ( displayer , NoProgressDisplayer ) <EOL> class DisplayDownloadProgressTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_calls_display_on_displayer_with_file_name ( self ) : <EOL> displayer = mock . Mock ( spec_set = ProgressLogDisplayer ) <EOL> display_download_progress ( displayer , '<STR_LIT>' ) <EOL> displayer . display_download_progress . assert_called_once_with ( '<STR_LIT>' ) <EOL> class MainTests ( ToolTestsBase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( ) . setUp ( ) <EOL> self . decompiler = mock . MagicMock ( spec_set = Decompiler ) <EOL> self . DecompilerMock = mock . Mock ( ) <EOL> self . DecompilerMock . return_value = self . decompiler <EOL> self . patch ( <EOL> '<STR_LIT>' , <EOL> self . DecompilerMock <EOL> ) <EOL> def get_started_decompilation ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . decompiler . start_decompilation ( ) <EOL> def test_performs_correct_actions_when_only_api_key_and_input_file_are_given ( self ) : <EOL> main ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . DecompilerMock . assert_called_once_with ( <EOL> api_url = DEFAULT_API_URL , <EOL> api_key = '<STR_LIT>' <EOL> ) <EOL> self . decompiler . start_decompilation . assert_called_once_with ( <EOL> input_file = '<STR_LIT>' , <EOL> mode = None , <EOL> generate_archive = False <EOL> ) <EOL> decompilation = self . get_started_decompilation ( ) <EOL> self . assertEqual ( <EOL> len ( decompilation . wait_until_finished . mock_calls ) , <NUM_LIT:1> <EOL> ) <EOL> decompilation . save_hll_code . assert_called_once_with ( os . getcwd ( ) ) <EOL> decompilation . save_dsm_code . assert_called_once_with ( os . getcwd ( ) ) <EOL> def call_main_with_standard_arguments_and ( self , * additional_args ) : <EOL> """<STR_LIT>""" <EOL> standard_args = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> main ( standard_args + additional_args ) <EOL> def assert_decompilation_was_started_also_with ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> decompilation_args = self . decompiler . start_decompilation . call_args <EOL> for arg in args : <EOL> self . assertIn ( arg , decompilation_args [ <NUM_LIT:0> ] ) <EOL> for key , value in kwargs . items ( ) : <EOL> self . assertIn ( key , decompilation_args [ <NUM_LIT:1> ] ) <EOL> msg = "<STR_LIT>" . format ( key ) <EOL> self . assertEqual ( decompilation_args [ <NUM_LIT:1> ] [ key ] , value , msg ) <EOL> def test_generates_and_saves_archive_when_requested ( self ) : <EOL> self . call_main_with_standard_arguments_and ( <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assert_decompilation_was_started_also_with ( <EOL> generate_archive = True <EOL> ) <EOL> decompilation = self . get_started_decompilation ( ) <EOL> decompilation . wait_until_archive_is_generated . assert_called_once_with ( ) <EOL> decompilation . save_archive . assert_called_once_with ( os . getcwd ( ) ) </s>
