def test_that_symbols_from_arrangement_exist_in_environment(self): symbol = StringConstantSymbolContext('symbol_name', 'the symbol value') symbol_table_of_arrangement = symbol.symbol_table expected_symbol_table = symbol.symbol_table expectation = asrt_sym.equals_symbol_table(expected_symbol_table) sdv_that_checks_symbols = MatcherSdvThatAssertsThatSymbolsAreAsExpected(self, expectation) cases = [ NameAndValue('arrangement without tcds', arrangement_wo_tcds( symbol_table_of_arrangement) ), NameAndValue('arrangement with tcds', arrangement_w_tcds( symbols=symbol_table_of_arrangement) ), ] for arrangement in cases: with self.subTest(arrangement.name): self._check___single_and_multi( utils.single_line_arguments(), ARBITRARY_MODEL, _constant_line_matcher_type_parser_of_matcher_sdv(sdv_that_checks_symbols), arrangement.value, Expectation(), )
def _check_raises_test_error__single_and_multi(self, parser: Parser[MatcherSdv[int]], expectation: Expectation, ): for check_application_result_with_tcds in [False, True]: checker = sut.IntegrationChecker(parser, CONFIGURATION, check_application_result_with_tcds) for arrangement in _EMPTY_ARRANGEMENT_W_WO_TCDS: with self.subTest(arrangement.name, check_application_result_with_tcds=check_application_result_with_tcds, execution_variant='single execution'): with self.assertRaises(utils.TestError): self._check( utils.single_line_source(), ARBITRARY_MODEL, checker, arrangement.value, expectation, ) with self.subTest(arrangement.name, check_application_result_with_tcds=check_application_result_with_tcds, execution_variant='multiple execution'): with self.assertRaises(utils.TestError): self._check___multi( utils.single_line_arguments(), ARBITRARY_MODEL, checker, arrangement.value, expectation, )
def test_successful_flow(self): for arrangement in _EMPTY_ARRANGEMENT_W_WO_TCDS: with self.subTest(arrangement.name): self._check___single_and_multi( utils.single_line_arguments(), ARBITRARY_MODEL, PARSER_THAT_GIVES_MATCHER_THAT_MATCHES_WO_SYMBOL_REFS_AND_SUCCESSFUL_VALIDATION, arrangement.value, is_expectation_of_execution_result_of(True), )
def test_that_cwd_for_main_and_post_validation_is_test_root(self): def make_primitive(tcds: TestCaseDs) -> MatcherWTrace[int]: return MatcherThatAssertsThatCwdIsIsActDir(self, tcds) self._check___single_and_multi( utils.single_line_arguments(), ARBITRARY_MODEL, _constant_line_matcher_type_parser_of_matcher_ddv( sdv_ddv.MatcherDdvFromPartsTestImpl( make_primitive, ValidatorThatAssertsThatCwdIsIsActDirAtPostSdsValidation(self), ) ), arrangement_w_tcds(), Expectation())
def test_tcds_directories_are_empty(self): all_tcds_dirs_are_empty = asrt.and_([ dir_is_empty(tcds_dir) for tcds_dir in RelOptionType ]) self._check___single_and_multi( utils.single_line_arguments(), ARBITRARY_MODEL, parser_of_matcher_that_is_an_assertion_on_tcds( self, all_tcds_dirs_are_empty, ), arrangement_w_tcds(), is_expectation_of_execution_result_of(True))
def test_tcds_SHOULD_not_exist_WHEN_flag_for_not_creating_tcds_is_given(self): def make_primitive(tcds: TestCaseDs) -> MatcherWTrace[int]: return constant.MatcherWithConstantResult(True) self._check___single_and_multi( utils.single_line_arguments(), ARBITRARY_MODEL, _constant_line_matcher_type_parser_of_matcher_ddv( sdv_ddv.MatcherDdvFromPartsTestImpl( make_primitive, ValidatorThatAssertsThatTcdsDirsDoesNotDenoteExistingDirectories(self), ) ), arrangement_wo_tcds(), Expectation(), )
def test_populate_non_hds(self): populated_dir_contents = DirContents([File.empty('non-home-file.txt')]) self._check___single_and_multi( utils.single_line_arguments(), ARBITRARY_MODEL, parser_of_matcher_that_is_an_assertion_on_tcds( self, sds_2_tcds_assertion( tmp_user_dir_contains_exactly(populated_dir_contents) ) ), arrangement_w_tcds( non_hds_contents=non_hds_populator.rel_option( non_hds_populator.RelNonHdsOptionType.REL_TMP, populated_dir_contents)), Expectation(), )
def test_expected_hard_error_is_detected(self): parser_that_gives_value_that_causes_hard_error = _constant_line_matcher_type_parser_of_matcher( matchers.MatcherThatReportsHardError() ) for arrangement in _EMPTY_ARRANGEMENT_W_WO_TCDS: with self.subTest(arrangement.name): self._check___single_and_multi( utils.single_line_arguments(), ARBITRARY_MODEL, parser_that_gives_value_that_causes_hard_error, arrangement.value, Expectation( execution=ExecutionExpectation( is_hard_error=matcher_assertions.is_hard_error(), ), ), )
def test_populate_hds(self): populated_dir_contents = DirContents([File.empty('hds-file.txt')]) the_hds_dir = RelHdsOptionType.REL_HDS_CASE self._check___single_and_multi( utils.single_line_arguments(), ARBITRARY_MODEL, parser_of_matcher_that_is_an_assertion_on_tcds( self, hds_contents_check.hds_2_tcds_assertion( hds_contents_check.dir_contains_exactly(the_hds_dir, populated_dir_contents) ) ), arrangement_w_tcds( hds_contents=hds_populators.contents_in( the_hds_dir, populated_dir_contents)), Expectation(), )
def test_populate_result_dir_with_act_result(self): act_result = SubProcessResult( exitcode=72, stdout='the stdout', stderr='the stderr', ) result_dir_contains_files_corresponding_to_act_result = asrt_tcds_contents.dir_contains_exactly( RelOptionType.REL_RESULT, DirContents([ File(sds.RESULT_FILE__EXITCODE, str(act_result.exitcode)), File(sds.RESULT_FILE__STDOUT, str(act_result.stdout)), File(sds.RESULT_FILE__STDERR, str(act_result.stderr)), ]) ) all_tcds_dirs_but_result_dir_are_empty = asrt.and_([ dir_is_empty(tcds_dir) for tcds_dir in RelOptionType if tcds_dir is not RelOptionType.REL_RESULT ]) self._check___single_and_multi( utils.single_line_arguments(), ARBITRARY_MODEL, parser_of_matcher_that_is_an_assertion_on_tcds( self, asrt.and_([ result_dir_contains_files_corresponding_to_act_result, all_tcds_dirs_but_result_dir_are_empty, ] ) ), arrangement_w_tcds( act_result=ActResultProducerFromActResult(act_result) ), Expectation(), )
def test_fail_due_to_unsatisfied_assertion_on_output_from_application(self): matcher_result_value = True for check_application_result_with_tcds in [False, True]: parser = _constant_line_matcher_type_parser_of_matcher_sdv( sdv_ddv.sdv_from_primitive_value(constant.MatcherWithConstantResult(matcher_result_value)) ) checker = sut.IntegrationChecker( parser, _CustomMatcherPropertiesConfiguration(asrt_matching_result.matches_value(not matcher_result_value)), check_application_result_with_tcds, ) expectation = is_expectation_of_execution_result_of(matcher_result_value) for arrangement in _EMPTY_ARRANGEMENT_W_WO_TCDS: with self.subTest(arrangement.name, check_application_result_with_tcds=check_application_result_with_tcds, execution_variant='single execution'): with self.assertRaises(utils.TestError): self._check( utils.single_line_source(), ARBITRARY_MODEL, checker, arrangement.value, expectation, ) with self.subTest(arrangement.name, check_application_result_with_tcds=check_application_result_with_tcds, execution_variant='multiple execution'): with self.assertRaises(utils.TestError): self._check___multi( utils.single_line_arguments(), ARBITRARY_MODEL, checker, arrangement.value, expectation, )