def test_not_equals(self): cases = [ NEA( 'unexpected driver type', expected=sut.matches_command( sut.equals_shell_command_driver( CommandDriverForShell('command')), asrt.equals(['arg'])), actual=Command(CommandDriverForSystemProgram('command'), ['arg']), ), NEA( 'unexpected driver data', expected=sut.matches_command( sut.equals_system_program_command_driver( CommandDriverForSystemProgram('expected')), asrt.equals([])), actual=Command(CommandDriverForSystemProgram('unexpected'), []), ), NEA( 'unexpected argument', expected=sut.matches_command( sut.equals_system_program_command_driver( CommandDriverForSystemProgram('command')), asrt.equals(['expected'])), actual=Command(CommandDriverForSystemProgram('command'), ['expected', 'unexpected']), ), ] for case in cases: with self.subTest(case.name): assert_that_assertion_fails(case.expected, case.actual)
def ret_val(tcds: TestCaseDs) -> Assertion[Command]: return asrt_command.matches_command( asrt_command.matches_executable_file_command_driver( asrt.equals(tcds.hds.case_dir / interpreter_exe_file) ), asrt.equals(arguments + [str(tcds.hds.act_dir / source_file_relative_hds_name)]) )
def ret_val(tcds: TestCaseDs) -> Assertion[Command]: return asrt_command.matches_command( asrt_command.matches_executable_file_command_driver( asrt.equals(tcds.hds.case_dir / interpreter_exe_file) ), matches_elements_except_last(asrt.equals(arguments)) )
def runTest(self): # ARRANGE # program_symbol = StringConstantSymbolContext( 'program_name_symbol', 'the-program', default_restrictions=asrt_rest.is__string__w_all_indirect_refs_are_strings(), ) argument_list_symbol = ListConstantSymbolContext( 'arguments_symbol', ['1st', '2nd'], ) symbols = [program_symbol, argument_list_symbol] expected_command = asrt_command.matches_command( driver=asrt_command.matches_system_program_command_driver( asrt.equals(program_symbol.str_value) ), arguments=asrt.equals(argument_list_symbol.constant), ) # ACT & ASSERT # check_successful_execution( self, arguments=command_line( program_symbol.name__sym_ref_syntax, program_arguments.simple(argument_list_symbol.name__sym_ref_syntax), ), expected_command=expected_command, symbols=SymbolContext.symbol_table_of_contexts(symbols), symbol_usages=SymbolContext.usages_assertion_of_contexts(symbols) )
def runTest(self): # ARRANGE # expected_file_name = 'quoted file name.src' act_phase_instructions = [instr([str(surrounded_by_hard_quotes(expected_file_name))]), instr([''])] executor_that_records_arguments = CommandExecutorThatRecordsArguments() arrangement = integration_check.arrangement_w_tcds( hds_contents=contents_in(RelHdsOptionType.REL_HDS_ACT, DirContents([ File.empty(expected_file_name)])), process_execution=ProcessExecutionArrangement( os_services=os_services_access.new_for_cmd_exe(executor_that_records_arguments) ) ) expectation = integration_check.Expectation() # ACT # integration_check.check_execution(self, ACTOR_THAT_RUNS_PYTHON_PROGRAM_FILE, act_phase_instructions, arrangement, expectation) # ASSERT # expected_command = asrt_command.matches_command( driver=asrt_command.matches_executable_file_command_driver(asrt.anything_goes()), arguments=asrt.matches_sequence([ asrt_path.str_as_path(asrt_path.name_equals(expected_file_name)) ]) ) expected_command.apply_with_message( self, executor_that_records_arguments.command, 'command', )
def expected_program(env: AssertionResolvingEnvironment) -> Assertion[Program]: return asrt_pgm_val.matches_program( asrt_command.matches_command( driver=program_ref_case.expected_command_driver(env), arguments=asrt.is_empty_sequence, ), stdin=asrt_pgm_val.is_no_stdin(), transformer=asrt_pgm_val.is_no_transformation(), )
def runTest(self): # ARRANGE # argument_1 = 'argument-1' argument_2 = 'argument-2' illegally_quoted = 'abc{} cde'.format(HARD_QUOTE_CHAR) list_symbol = ListConstantSymbolContext( 'list_symbol', ['1st', '2nd with space'], ) cases = [ ArgumentsCase( 'no arguments', ab.empty(), asrt.is_empty_sequence, ), ArgumentsCase( 'simple arguments', ab.sequence__r([ program_arguments.simple(argument_1), program_arguments.simple(argument_2), ]), asrt.equals([argument_1, argument_2]), ), ArgumentsCase( 'list symbol reference', program_arguments.simple(list_symbol.name__sym_ref_syntax), asrt.equals(list_symbol.constant_list), [list_symbol], ), ArgumentsCase( 'special PROGRAM-ARGUMENT', program_arguments.remaining_part_of_current_line_as_literal(illegally_quoted), asrt.equals([illegally_quoted]), ), ] program_name = 'program' for case in cases: expected_command = asrt_command.matches_command( driver=asrt_command.matches_system_program_command_driver( asrt.equals(program_name) ), arguments=case.expected_arguments ) with self.subTest(case.name): # ACT & ASSERT # check_successful_execution( self, arguments=command_line( program_name, case.arguments, ), expected_command=expected_command, symbols=SymbolContext.symbol_table_of_contexts(case.symbols), symbol_usages=SymbolContext.usages_assertion_of_contexts(case.symbols) )
def expected_program( env: AssertionResolvingEnvironment) -> Assertion[Program]: return asrt_pgm_val.matches_program( asrt_command.matches_command( driver=command_driver.expected_command_driver(env), arguments=asrt.equals(all_arguments)), stdin=asrt_pgm_val.is_no_stdin(), transformer=asrt_pgm_val.is_no_transformation(), )
def expected_program( env: AssertionResolvingEnvironment) -> Assertion[Program]: return asrt_pgm_val.matches_program( asrt_command.matches_command( driver=pgm_and_args_case.expected_command_driver(env), arguments=asrt.is_empty_sequence), stdin=asrt.matches_singleton_sequence( asrt_str_src.matches__str( asrt.equals(str_src_contents), )), transformer=asrt_pgm_val.is_no_transformation(), )
def test_equals(self): cases = [ NEA( 'shell', expected=sut.matches_command( sut.equals_shell_command_driver( CommandDriverForShell('command line')), asrt.equals(['arg'])), actual=Command(CommandDriverForShell('command line'), ['arg']), ), NEA( 'without arguments', expected=sut.matches_command( sut.equals_system_program_command_driver( CommandDriverForSystemProgram('program')), asrt.equals([])), actual=Command(CommandDriverForSystemProgram('program'), []), ), ] for case in cases: with self.subTest(case.name): case.expected.apply_without_message(self, case.actual)
def sdv_assertion( self, tcds: TestCaseDs, arguments: Assertion[Sequence[str]], arguments_symbols: Sequence[SymbolContext] = (), ) -> Assertion[SymbolDependentValue]: expected_command = asrt_command.matches_command( driver=self.expected_command_driver(tcds), arguments=arguments) symbols = tuple(self.symbols) + tuple(arguments_symbols) return matches_sdv( asrt.is_instance(CommandSdv), symbols=SymbolContext.symbol_table_of_contexts(symbols), references=SymbolContext.references_assertion_of_contexts(symbols), resolved_value=asrt.is_instance_with( CommandDdv, matches_dir_dependent_value(lambda _: expected_command)), )
def get_command_assertion(tcds: TestCaseDs) -> Assertion[Command]: symbols = SymbolTable.empty() return asrt_command.matches_command( asrt.anything_goes(), asrt.equals( interpreter_arguments_symbol.constant_list + [ str(relativity_configurations.ATC_FILE .named_file_conf(exe_file.name) .path_sdv .resolve(symbols) .value_of_any_dependency__d(tcds) .primitive ), argument_to_act_file, ] ) )
def runTest(self): # ARRANGE # atc_file_name = 'existing-file.py' arg_1 = 'un-quoted' arg_2 = 'single quoted' arg_3 = 'double quoted' act_line_1 = '{} {} {} {}'.format( atc_file_name, arg_1, surrounded_by_hard_quotes(arg_2), surrounded_by_soft_quotes(arg_3), ) atc_line_2 = '' act_phase_instructions = [instr([act_line_1]), instr([atc_line_2])] executor_that_records_arguments = CommandExecutorThatRecordsArguments() arrangement = integration_check.arrangement_w_tcds( hds_contents=contents_in(RelHdsOptionType.REL_HDS_ACT, DirContents([ File.empty(atc_file_name)])), process_execution=ProcessExecutionArrangement( os_services=os_services_access.new_for_cmd_exe(executor_that_records_arguments) ) ) expected_command = asrt_command.matches_command( driver=asrt_command.matches_executable_file_command_driver(asrt.anything_goes()), arguments=asrt.matches_sequence([ asrt_path.str_as_path(asrt_path.name_equals(atc_file_name)), asrt.equals(arg_1), asrt.equals(arg_2), asrt.equals(arg_3), ]) ) expectation = integration_check.Expectation( after_execution=ExecutedCommandAssertion(executor_that_records_arguments, lambda tcds: expected_command) ) # ACT & ASSERT # integration_check.check_execution(self, ACTOR_THAT_RUNS_PYTHON_PROGRAM_FILE, act_phase_instructions, arrangement, expectation)
def runTest(self): # ARRANGE # executable_file = sys.executable command_executor = CommandExecutorThatRecordsArguments() arrangement = Arrangement( source=remaining_source('= ' + actor_utils.COMMAND_LINE_ACTOR_NAME), act_phase_source_lines=[executable_file], os_services=os_services_access.new_for_cmd_exe(command_executor), ) expected_command = asrt_command.matches_command( driver=asrt_command.matches_executable_file_command_driver( asrt_path.path_as_str(asrt.equals(executable_file)), ), arguments=asrt.is_empty_sequence) expectation = Expectation(symbol_usages=asrt.is_empty_sequence, after_execution=ExecutedCommandAssertion( command_executor, lambda tcds: expected_command)) # ACT & ASSERT # check_actor_execution(self, arrangement, expectation)
def get_command_assertion(tcds: TestCaseDs) -> Assertion[Command]: symbols = SymbolTable.empty() return asrt_command.matches_command( asrt.anything_goes(), asrt.equals([ str(relativity_configurations.ATC_FILE .named_file_conf(exe_file.name) .path_sdv .resolve(symbols) .value_of_any_dependency__d(tcds) .primitive ), str(existing_path_relativity .named_file_conf(existing_path_argument.name) .path_sdv .resolve(symbols) .value_of_any_dependency__d(tcds) .primitive ), text_until_end_of_line, ]) )
def runTest(self): # ARRANGE # for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference(): with self.subTest(command=pgm_and_args_case.name): # ACT & ASSERT # CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input( self, equivalent_source_variants__for_consume_until_end_of_last_line__s__nsc, pgm_and_args_case.pgm_and_args, pgm_and_args_case.mk_arrangement(SymbolContext.symbol_table_of_contexts(pgm_and_args_case.symbols)), MultiSourceExpectation( symbol_references=SymbolContext.references_assertion_of_contexts(pgm_and_args_case.symbols), primitive=lambda env: ( asrt_pgm_val.matches_program( asrt_command.matches_command( driver=pgm_and_args_case.expected_command_driver(env), arguments=asrt.is_empty_sequence ), stdin=asrt_pgm_val.is_no_stdin(), transformer=asrt_pgm_val.is_no_transformation(), ) ) ) )
def test_stdin_in_referenced_program_and_as_source_argument(self): # ARRANGE # str_src_contents__of_argument = 'the_str_src_contents__of_argument' str_src_contents__of_referenced_pgm = 'the_str_src_contents__of_program' stdin_argument_syntax = str_src_abs_stx.StringSourceOfStringAbsStx.of_str( str_src_contents__of_argument) stdin_sdv__of_referenced = str_src_sdvs.ConstantStringStringSourceSdv( string_sdvs.str_constant(str_src_contents__of_referenced_pgm)) referenced_program__system_program = 'the-system-program' referenced_program__sdv = program_sdvs.system_program( string_sdvs.str_constant(referenced_program__system_program), stdin=[stdin_sdv__of_referenced], ) referenced_program = ProgramSymbolContext.of_sdv( 'REFERENCED_PROGRAM', referenced_program__sdv) symbols__symbol_table = [referenced_program] symbols__expected_references = [referenced_program] arguments_cases = [ NameAndValue( 'no arguments', [], ), NameAndValue( 'single argument', ['arg1'], ) ] for arguments_case in arguments_cases: with self.subTest(arguments=arguments_case.name): program_w_stdin = FullProgramAbsStx( ProgramOfSymbolReferenceAbsStx(referenced_program.name, [ ArgumentOfRichStringAbsStx.of_str(arg) for arg in arguments_case.value ]), stdin=stdin_argument_syntax, ) expected_primitive = asrt_pgm_val.matches_program( asrt_command.matches_command( driver=asrt_command. matches_system_program_command_driver( asrt.equals(referenced_program__system_program)), arguments=asrt.equals(arguments_case.value), ), stdin=asrt.matches_sequence([ asrt_str_src.matches__str( asrt.equals(str_src_contents__of_referenced_pgm)), asrt_str_src.matches__str( asrt.equals(str_src_contents__of_argument)), ]), transformer=asrt_pgm_val.is_no_transformation(), ) # ACT & ASSERT # CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input( self, equivalent_source_variants__for_expr_parse__s__nsc, program_w_stdin, arrangement_w_tcds( symbols=SymbolContext.symbol_table_of_contexts( symbols__symbol_table), ), MultiSourceExpectation.of_const( symbol_references=SymbolContext. references_assertion_of_contexts( symbols__expected_references), primitive=expected_primitive, ))
def test_list_of_arguments_and_symbol_references(self): arg_wo_space = 'arg_wo_space' arg_w_space = 'an arg w space' string_symbol_1 = StringConstantSymbolContext( 'STRING_SYMBOL_1', 'value of string symbol 1', default_restrictions=asrt_data_rest.is__w_str_rendering(), ) string_symbol_2 = StringConstantSymbolContext( 'STRING_SYMBOL_2', 'value of string symbol 2', default_restrictions=asrt_data_rest.is__w_str_rendering(), ) arguments_cases = [ ArgumentsCase( 'one / wo symbol references', arguments=[ ArgumentOfRichStringAbsStx.of_str(arg_w_space, QuoteType.SOFT) ], expected_arguments=[arg_w_space], symbols=(), ), ArgumentsCase( 'two / wo symbol references', arguments=[ ArgumentOfRichStringAbsStx.of_str(arg_wo_space), ArgumentOfRichStringAbsStx.of_str(arg_w_space, QuoteType.HARD) ], expected_arguments=[arg_wo_space, arg_w_space], symbols=(), ), ArgumentsCase( 'three / w symbol references', arguments=[ ArgumentOfSymbolReferenceAbsStx(string_symbol_1.name), ArgumentOfRichStringAbsStx.of_str(arg_w_space, QuoteType.HARD), ArgumentOfSymbolReferenceAbsStx(string_symbol_2.name) ], expected_arguments=[ string_symbol_1.str_value, arg_w_space, string_symbol_2.str_value ], symbols=[string_symbol_1, string_symbol_2], ), ] # ARRANGE # for pgm_and_args_case in pgm_and_args_cases.cases__w_argument_list__excluding_program_reference( ): for arguments_case in arguments_cases: pgm_w_args = PgmAndArgsWArgumentsAbsStx( pgm_and_args_case.pgm_and_args, arguments_case.arguments) expected_arguments = asrt.equals( arguments_case.expected_arguments) symbols = list(pgm_and_args_case.symbols) + list( arguments_case.symbols) expectation = MultiSourceExpectation( symbol_references=SymbolContext. references_assertion_of_contexts(symbols), primitive=lambda env: (asrt_pgm_val.matches_program( asrt_command.matches_command( driver=pgm_and_args_case.expected_command_driver( env), arguments=expected_arguments, ), stdin=asrt_pgm_val.is_no_stdin(), transformer=asrt_pgm_val.is_no_transformation(), ))) with self.subTest(command=pgm_and_args_case.name, arguments=arguments_case.name): # ACT & ASSERT # CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input( self, equivalent_source_variants__for_consume_until_end_of_last_line__s__nsc, pgm_w_args, pgm_and_args_case.mk_arrangement( SymbolContext.symbol_table_of_contexts(symbols)), expectation, )
def test_transformation_in_referenced_program_and_as_source_argument(self): # ARRANGE # transformer__in_referenced_program = StringTransformerPrimitiveSymbolContext( 'TRANSFORMER_IN_REFERENCED_PROGRAM', string_transformers.delete_everything()) referenced_program__system_program = 'the-system-program' referenced_program__sdv = program_sdvs.system_program( string_sdvs.str_constant(referenced_program__system_program), transformations=[transformer__in_referenced_program.reference_sdv]) referenced_program = ProgramSymbolContext.of_sdv( 'REFERENCED_PROGRAM', referenced_program__sdv) transformer__in_source = StringTransformerPrimitiveSymbolContext( 'TRANSFORMER_IN_SOURCE', string_transformers.to_uppercase()) symbols__symbol_table = [ referenced_program, transformer__in_referenced_program, transformer__in_source ] symbols__expected_references = [ referenced_program, transformer__in_source ] arguments_cases = [ NameAndValue( 'no arguments', [], ), NameAndValue( 'single argument', ['arg1'], ) ] for arguments_case in arguments_cases: with self.subTest(arguments=arguments_case.name): program_w_transformer = FullProgramAbsStx( ProgramOfSymbolReferenceAbsStx(referenced_program.name, [ ArgumentOfRichStringAbsStx.of_str(arg) for arg in arguments_case.value ]), transformation=transformer__in_source.abstract_syntax) expected_primitive = asrt_pgm_val.matches_program( asrt_command.matches_command( driver=asrt_command. matches_system_program_command_driver( asrt.equals(referenced_program__system_program)), arguments=asrt.equals(arguments_case.value), ), stdin=asrt_pgm_val.is_no_stdin(), transformer=asrt.matches_sequence([ asrt.is_(transformer__in_referenced_program.primitive), asrt.is_(transformer__in_source.primitive), ]), ) # ACT & ASSERT # CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input( self, equivalent_source_variants__for_expr_parse__s__nsc, program_w_transformer, arrangement_wo_tcds( symbols=SymbolContext.symbol_table_of_contexts( symbols__symbol_table), ), MultiSourceExpectation.of_const( symbol_references=SymbolContext. references_assertion_of_contexts( symbols__expected_references), primitive=expected_primitive, ))