def test_with_explicit_non_cd_relativity_and_source_layout_variants(self): # ARRANGE # relativity = RelOptionType.REL_TMP for is_after_act_phase in [False, True]: checker = embryo_checker(is_after_act_phase) for case in path_name_variants.SOURCE_LAYOUT_CASES: path_argument = RelOptPathArgument(case.input_value, relativity) with self.subTest(case.name, is_after_act_phase=is_after_act_phase): with self.subTest(case.name): # ACT & ASSERT # checker.check__w_source_variants( self, path_argument.as_str, Arrangement.phase_agnostic(tcds=TcdsArrangement( tcds_contents=tcds_populators. TcdsPopulatorForRelOptionType( relativity, DirContents( [Dir.empty(case.expected_value)]))), ), MultiSourceExpectation.phase_agnostic( side_effects_on_tcds=CwdAssertion( relativity, case.expected_value, )))
def _expect_validation_error_and_symbol_usages( relativity_option_conf: rel_opt_conf.RelativityOptionConfiguration, expected_symbol_usage: list) -> MultiSourceExpectation: expected_symbol_usages_assertion = asrt.matches_sequence( expected_symbol_usage) if relativity_option_conf.exists_pre_sds: return MultiSourceExpectation.phase_agnostic( validation=ValidationAssertions.pre_sds_fails__w_any_msg(), symbol_usages=expected_symbol_usages_assertion, ) else: return MultiSourceExpectation.phase_agnostic( validation=ValidationAssertions.post_sds_fails__w_any_msg(), symbol_usages=expected_symbol_usages_assertion, )
def test_check_non_zero_exit_code(self): EXECUTION_CHECKER.check__w_source_variants( self, pgm_args.interpret_py_source_line('exit(1)').as_str, Arrangement.phase_agnostic(tcds=TcdsArrangement(), ), MultiSourceExpectation.phase_agnostic( main_result=result_assertions.equals(1, '')))
def runTest(self): # ARRANGE # cases = [ NameAndValue( 'pre sds', ( RelOptionType.REL_HDS_CASE, ValidationAssertions.pre_sds_fails__w_any_msg(), ), ), NameAndValue( 'post sds', ( RelOptionType.REL_ACT, ValidationAssertions.post_sds_fails__w_any_msg(), ), ), ] for case in cases: with self.subTest(case.name): CHECKER.check__w_source_variants( self, command_line( 'program', program_arguments.existing_path( path_arguments.RelOptPathArgument('name', case.value[0]), ) ).as_str, Arrangement.phase_agnostic(), MultiSourceExpectation.phase_agnostic( validation=case.value[1], ), )
def test_copy_file__destination_is_existing_directory(self): # ARRANGE # src = 'src-file' dst = 'dst-dir' file_to_install = File(src, 'contents') home_dir_contents = [file_to_install] act_dir_contents = [Dir.empty(dst)] act_dir_contents_after = [Dir(dst, [file_to_install])] for parser_case in _EXECUTION_CHECKERS: with self.subTest(parser=parser_case.name): # ACT & ASSERT # parser_case.value.check__w_source_variants( self, args.copy( defs.DEFAULT_SRC_REL_OPT.path_argument_of_rel_name(src), defs.DEFAULT_DST_REL_OPT.path_argument_of_rel_name(dst) ).as_str, Arrangement.phase_agnostic( tcds=TcdsArrangement( pre_population_action=MAKE_SUB_DIR_OF_SDS_CURRENT_DIRECTORY, hds_contents=defs.DEFAULT_SRC_REL_OPT.populator_for_relativity_option_root__hds( DirContents(home_dir_contents) ), sds_contents=defs.DEFAULT_DST_REL_OPT.populator_for_relativity_option_root__sds( DirContents(act_dir_contents) ), ), ), MultiSourceExpectation.phase_agnostic( main_side_effects_on_sds=sds_contents_check.cwd_contains_exactly( DirContents(act_dir_contents_after)) ), )
def runTest(self): string_72_plus = StringSymbolContext.of_constant( 'SYMBOL_72_PLUS', '72+', default_restrictions=asrt_data_rest. is__string__w_all_indirect_refs_are_strings(), ) string_5 = StringSymbolContext.of_constant( 'SYMBOL_5', '5', default_restrictions=asrt_data_rest. is__string__w_all_indirect_refs_are_strings(), ) expected = 72 + 5 all_symbols = [string_72_plus, string_5] value_syntax = StringConcatAbsStx([ string_72_plus.abstract_syntax, string_5.abstract_syntax, ]) CHECKER.check__abs_stx__layout_and_source_variants( self, InstructionArgumentsAbsStx.of_int(value_syntax), Arrangement.phase_agnostic( symbols=SymbolContext.symbol_table_of_contexts(all_symbols), ), MultiSourceExpectation.phase_agnostic( symbol_usages=SymbolContext.usages_assertion_of_contexts( all_symbols), instruction_settings=asrt_instr_settings.matches( timeout=asrt.equals(expected))), )
def test_success_when_executable_does_exist(self): for relativity_option_conf in RELATIVITY_OPTIONS: argument = '{relativity_option} {executable_file}'.format( relativity_option=relativity_option_conf.option_argument, executable_file=EXECUTABLE_FILE_THAT_EXITS_WITH_CODE_0. file_name, ) expectation = MultiSourceExpectation.phase_agnostic( symbol_usages=asrt.matches_sequence( relativity_option_conf.symbols. usage_expectation_assertions()), ) arrangement = Arrangement.phase_agnostic( tcds=TcdsArrangement( tcds_contents=relativity_option_conf. populator_for_relativity_option_root( fs.DirContents( [EXECUTABLE_FILE_THAT_EXITS_WITH_CODE_0])), ), symbols=relativity_option_conf.symbols.in_arrangement(), ) with self.subTest( option=relativity_option_conf.test_case_description): EXECUTION_CHECKER.check__w_source_variants( self, argument, arrangement, expectation)
def test_assignment_of_list_with_multiple_constant_elements(self): # ARRANGE # value_without_space = 'value_without_space' value_with_space = 'value with space' symbol_to_assign = ListSymbolContext.of_sdv( 'the_symbol_name', sdvs.from_str_constants([value_without_space, value_with_space])) syntax = _syntax( symbol_to_assign, NonEmptyListAbsStx([ ListElementStringAbsStx.of_str(value_without_space), ListElementStringAbsStx.of_str(value_with_space, QuoteType.SOFT), ])) expectation = MultiSourceExpectation.phase_agnostic( symbol_usages=asrt.matches_sequence( [symbol_to_assign.assert_matches_definition_of_sdv]), symbols_after_main=assert_symbol_table_is_singleton( symbol_to_assign.name, symbol_to_assign.value.assert_matches_container_of_sdv, ), ) # ACT & ASSERT # INSTRUCTION_CHECKER.check__abs_stx__layout_and_source_variants( self, syntax, Arrangement.phase_agnostic(), expectation, )
def test_main_method_arguments(self): # ARRANGE # the_environ = MappingProxyType({'the_env_var': 'the env var value'}) the_timeout = 69 the_os_services = os_services_access.new_for_current_os() def main_action_that_checks_arguments(environment: InstructionEnvironmentForPostSdsStep, instruction_settings: InstructionSettings, os_services: OsServices): self.assertIs(os_services, the_os_services, 'os_services') self.assertEqual(the_environ, environment.proc_exe_settings.environ, 'proc exe settings/environment') self.assertEqual(the_timeout, environment.proc_exe_settings.timeout_in_seconds, 'proc exe settings/timeout') self.assertEqual(the_environ, instruction_settings.environ(), 'instruction settings/environment') # ACT & ASSERT # self._check_source_and_exe_variants( ParserThatGives(instruction_embryo_that__phase_agnostic( main_initial_action=main_action_that_checks_arguments )), Arrangement.phase_agnostic( process_execution_settings=ProcessExecutionSettings(the_timeout, the_environ), os_services=the_os_services, ), MultiSourceExpectation.phase_agnostic(), )
def test_assignment_of_list_with_symbol_references(self): # ARRANGE # referred_symbol_name = 'referred_symbol' expected_symbol_reference = references.reference_to__w_str_rendering( referred_symbol_name) symbol_to_assign = ListSymbolContext.of_sdv( 'the_symbol_name', sdvs.from_elements( [sdvs.symbol_element(expected_symbol_reference)])) syntax = _syntax(symbol_to_assign, ListSymbolReferenceAbsStx(referred_symbol_name)) # ACT & ASSERT # INSTRUCTION_CHECKER.check__abs_stx__layout_and_source_variants( self, syntax, Arrangement.phase_agnostic(), MultiSourceExpectation.phase_agnostic( symbol_usages=asrt.matches_sequence( [symbol_to_assign.assert_matches_definition_of_sdv]), symbols_after_main=assert_symbol_table_is_singleton( symbol_to_assign.name, symbol_to_assign.value.assert_matches_container_of_sdv, ), ), )
def test_single_file_in_root_dir(self): # ARRANGE # expected_file = File.empty('file-name.txt') for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) for rel_opt_conf in ALLOWED_DST_FILE_RELATIVITIES: with self.subTest( relativity_option_string=rel_opt_conf.option_argument, phase_is_after_act=phase_is_after_act): instruction_syntax = abs_stx.without_contents( rel_opt_conf.path_abs_stx_of_name(expected_file.name)) # ACT & ASSERT # checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic(tcds=TcdsArrangement( pre_population_action= SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, ), ), MultiSourceExpectation.phase_agnostic( main_result=IS_SUCCESS, side_effects_on_hds=f_asrt.dir_is_empty(), symbol_usages=asrt.is_empty_sequence, main_side_effects_on_sds= non_hds_dir_contains_exactly( rel_opt_conf.root_dir__non_hds, fs.DirContents([expected_file])), ))
def test_contents_from_here_doc(self): # ARRANGE # string_value = rich_str_abs_stx.HereDocAbsStx( 'single line in here doc\n') expected_file = fs.File('a-file-name.txt', string_value.value) rel_opt_conf = ARBITRARY_ALLOWED_DST_FILE_RELATIVITY dst_path = rel_opt_conf.path_abs_stx_of_name(expected_file.name) instruction_syntax = instr_abs_stx.create_w_explicit_contents( dst_path, string_source_abs_stx.StringSourceOfStringAbsStx(string_value), ) for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) with self.subTest(phase_is_after_act=phase_is_after_act): # ACT & ASSERT # checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic(tcds=TcdsArrangement( pre_population_action= SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, ), ), MultiSourceExpectation.phase_agnostic( main_result=IS_SUCCESS, side_effects_on_hds=f_asrt.dir_is_empty(), symbol_usages=asrt.is_empty_sequence, main_side_effects_on_sds=non_hds_dir_contains_exactly( rel_opt_conf.root_dir__non_hds, fs.DirContents([expected_file])), ))
def test_WHEN_program_is_non_non_existing_system_command_THEN_result_SHOULD_be_error_message(self): failing_program_builder = program_abs_stx.TransformableProgramAbsStxBuilder( program_abs_stx.ProgramOfSystemCommandLineAbsStx.of_str(NON_EXISTING_SYSTEM_PROGRAM) ) transformer = TO_UPPER_TRANSFORMER_SYMBOL symbols = transformer.symbol_table cases = failing_program_builder.with_and_without_transformer_cases(transformer.abstract_syntax) for transformation_case in cases: instruction_syntax = instr_abs_stx.create_w_explicit_contents( path_abs_stx.DefaultRelPathAbsStx('dst-file'), string_source_abs_stx.StringSourceOfProgramAbsStx( ProcOutputFile.STDOUT, transformation_case.value, ignore_exit_code=False) ) for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) with self.subTest(phase_is_after_act=phase_is_after_act, transformation=transformation_case.name): checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic( symbols=symbols, tcds=TcdsArrangement(), ), MultiSourceExpectation.phase_agnostic( symbol_usages=asrt.anything_goes(), main_result=IS_FAILURE, ) )
def test_tcds__dummy(self): self._check_source_and_exe_variants( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, Arrangement.phase_agnostic(), MultiSourceExpectation.phase_agnostic( side_effects_on_tcds=asrt.IsInstance(TestCaseDs) ), )
def test_symbols_after_main(self): self._check_source_and_exe_variants( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, Arrangement.phase_agnostic(), MultiSourceExpectation.phase_agnostic( symbols_after_main=asrt.is_instance(SymbolTable) ), )
def test_check_non_zero_exit_code_with_output_to_stderr(self): python_program = 'import sys; sys.stderr.write("on stderr"); exit(2)' EXECUTION_CHECKER.check__w_source_variants( self, pgm_args.interpret_py_source_line(python_program).as_str, Arrangement.phase_agnostic(tcds=TcdsArrangement(), ), MultiSourceExpectation.phase_agnostic( main_result=result_assertions.equals(2, 'on stderr')))
def test_fail_due_to_fail_of_side_effects_on_instruction_settings(self): self._check_source_and_exe_variants__failing_assertions( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, Arrangement.phase_agnostic(), MultiSourceExpectation.phase_agnostic( instruction_settings=asrt.not_(asrt.is_instance(InstructionSettings)), ), )
def test_fail_due_to_assertion_on_instruction_environment(self): self._check_source_and_exe_variants__failing_assertions( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, Arrangement.phase_agnostic(), MultiSourceExpectation.phase_agnostic( instruction_environment=asrt.fail('unconditional failure') ), )
def test_fail_due_to_unexpected_result__from_main(self): self._check_source_and_exe_variants__failing_assertions( ParserThatGives(instruction_embryo_that__phase_agnostic(main=do_return('actual'))), Arrangement.phase_agnostic(), MultiSourceExpectation.phase_agnostic( main_result=asrt.equals('different-from-actual'), ), )
def test_fail_due_to_unexpected_result_from__validate_post_sds(self): self._check_source_and_exe_variants__failing_assertions( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, Arrangement.phase_agnostic(), MultiSourceExpectation.phase_agnostic( validation=ValidationAssertions.post_sds_fails() ), )
def runTest(self): CHECKER.check__abs_stx__layout_and_source_variants( self, InstructionArgumentsAbsStx.of_none(), Arrangement.phase_agnostic(), MultiSourceExpectation.phase_agnostic( instruction_settings=asrt_instr_settings.matches( timeout=asrt.is_none)), )
def test_hds(self): self._check_source_and_exe_variants( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, Arrangement.phase_agnostic( tcds=TcdsArrangement(), ), MultiSourceExpectation.phase_agnostic( side_effects_on_hds=asrt.IsInstance(pathlib.Path) ), )
def test_succeed_due_to_expected_hard_error_exception(self): self._check_source_and_exe_variants( ParserThatGives(instruction_embryo_that__phase_agnostic( main=do_raise(HardErrorException(new_single_string_text_for_test('hard error message')))) ), Arrangement.phase_agnostic(), MultiSourceExpectation.phase_agnostic( main_raises_hard_error=True ), )
def test_fail_due_to_unexpected_hard_error_exception(self): self._check_source_and_exe_variants__failing_assertions( ParserThatGives(instruction_embryo_that__phase_agnostic( main=do_raise(HardErrorException(new_single_string_text_for_test('hard error message')))) ), Arrangement.phase_agnostic(), MultiSourceExpectation.phase_agnostic( main_result=asrt.anything_goes() ), )
def test_side_effects_on_files(self): self._check_source_and_exe_variants( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, Arrangement.phase_agnostic( tcds=TcdsArrangement(), ), MultiSourceExpectation.phase_agnostic( main_side_effects_on_sds=asrt.IsInstance(SandboxDs) ), )
def test_environment_variables__is_copy_from_proc_exe_settings(self): self._check_source_and_exe_variants( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, Arrangement.phase_agnostic( process_execution_settings=ProcessExecutionSettings.with_environ({}) ), MultiSourceExpectation.phase_agnostic( main_side_effect_on_environment_variables=asrt.equals({}) ), )
def test_fail_due_to_fail_of_side_effects_on_files(self): self._check_source_and_exe_variants__failing_assertions( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, Arrangement.phase_agnostic( tcds=TcdsArrangement(), ), MultiSourceExpectation.phase_agnostic( main_side_effects_on_sds=act_dir_contains_exactly( DirContents([File.empty('non-existing-file.txt')])) ), )
def test_arrangement_and_expectation_of_hds_dir_contents(self): home_dir_contents = DirContents([File.empty('file-name.txt')]) self._check_source_and_exe_variants( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, Arrangement.phase_agnostic( tcds=TcdsArrangement( hds_contents=hds_case_dir_contents(home_dir_contents)), ), MultiSourceExpectation.phase_agnostic( side_effects_on_hds=f_asrt.dir_contains_exactly(home_dir_contents)), )
def test_fail_due_to_side_effects_on_hds(self): self._check_source_and_exe_variants__failing_assertions( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, Arrangement.phase_agnostic( tcds=TcdsArrangement(), ), MultiSourceExpectation.phase_agnostic( side_effects_on_hds=f_asrt.dir_contains_at_least( DirContents([File.empty('file-name.txt')])) ), )
def test_fail_due_to_side_effects_check(self): for tcds_case in TCDS_CASES: with self.subTest(tcds_case.name): self._check_source_and_exe_variants__failing_assertions( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, Arrangement.phase_agnostic( tcds=tcds_case.value ), MultiSourceExpectation.phase_agnostic( side_effects_on_tcds=asrt.not_(asrt.is_instance(TestCaseDs)) ), )