Exemplo n.º 1
0
 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],
                 ),
             )
Exemplo n.º 2
0
def dir_partition_cases_for_validation(dst_path_symbol_name: str,
                                       ) -> Sequence[NArrEx[RelativityOptionConfiguration, ValidationAssertions]]:
    return [
        NArrEx(
            DirectoryStructurePartition.HDS.name,
            _relativity_conf_for_symbol(dst_path_symbol_name, RelOptionType.REL_HDS_CASE),
            ValidationAssertions.pre_sds_fails__w_any_msg(),
        ),
        NArrEx(
            DirectoryStructurePartition.NON_HDS.name,
            _relativity_conf_for_symbol(dst_path_symbol_name, RelOptionType.REL_ACT),
            ValidationAssertions.post_sds_fails__w_any_msg(),
        ),
    ]
Exemplo n.º 3
0
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,
        )
Exemplo n.º 4
0
 def test_ERROR_when_file_does_not_exist__without_explicit_destination__non_hds(self):
     for execution_checker in _EXECUTION_CHECKERS:
         for relativity_option in source_relativity_options__non_hds():
             with self.subTest(parser=execution_checker.name,
                               relativity=relativity_option.test_case_description):
                 execution_checker.value.check(
                     self,
                     args.copy(
                         relativity_option.path_argument_of_rel_name('source-that-do-not-exist')
                     ).as_remaining_source,
                     Arrangement.phase_agnostic(
                         tcds=TcdsArrangement(),
                         symbols=relativity_option.symbols.in_arrangement(),
                     ),
                     Expectation.phase_agnostic_2(
                         symbol_usages=relativity_option.symbols.usages_expectation(),
                         validation=ValidationAssertions.post_sds_fails__w_any_msg(),
                     )
                 )
Exemplo n.º 5
0
def failing_regex_validation_cases(
    symbol_in_regex_name: str = 'symbol_in_regex'
) -> Sequence[RegexValidationCase]:
    post_sds_path = PathDdvSymbolContext.of_no_suffix(symbol_in_regex_name,
                                                      RelOptionType.REL_ACT)
    return [
        RegexValidationCase(
            'failing validation/pre sds',
            '*',
            [],
            [],
            ValidationAssertions.pre_sds_fails__w_any_msg(),
        ),
        RegexValidationCase(
            'failing validation/post sds',
            '*' + symbol_reference_syntax_for_name(post_sds_path.name),
            [post_sds_path],
            [is_reference_to__regex_string_part(post_sds_path.name)],
            ValidationAssertions.post_sds_fails__w_any_msg(),
        ),
    ]
Exemplo n.º 6
0
    def test_symbol_references_with_dir_dependencies(self):
        # ARRANGE #

        path_symbol_name = 'PATH_SYMBOL'

        regex_source_string = (symbol_reference_syntax_for_name(self.STAR_STRING_SYMBOL.name) +
                               symbol_reference_syntax_for_name(path_symbol_name))

        expectation = Expectation(
            references=asrt.matches_sequence([
                is_reference_to__regex_string_part(self.STAR_STRING_SYMBOL.name),
                is_reference_to__regex_string_part(path_symbol_name),
            ]),
            validation=ValidationAssertions.post_sds_fails__w_any_msg(),
            token_stream=assert_token_stream(is_null=asrt.is_true),
        )

        rel_opt_cases = [
            RelOptionType.REL_HDS_CASE,
            RelOptionType.REL_CWD,
            RelOptionType.REL_ACT,
        ]

        for rel_opt in rel_opt_cases:
            path_symbol = PathDdvSymbolContext.of_no_suffix(path_symbol_name, rel_opt)

            arrangement = Arrangement(
                symbols=SymbolContext.symbol_table_of_contexts([
                    self.STAR_STRING_SYMBOL,
                    path_symbol,
                ])
            )

            # ACT & ASSERT #

            self._check(regex_source_string,
                        arrangement,
                        expectation,
                        )
Exemplo n.º 7
0
 def runTest(self):
     # ARRANGE #
     cases = [
         NArrEx(
             'pre SDS validation failure SHOULD cause validation error',
             RelOptionType.REL_HDS_CASE,
             MultiSourceExpectation.phase_agnostic(
                 validation=ValidationAssertions.pre_sds_fails__w_any_msg()
             ),
         ),
         NArrEx(
             'post SDS validation failure SHOULD cause main error',
             RelOptionType.REL_ACT,
             MultiSourceExpectation.phase_agnostic(
                 validation=ValidationAssertions.post_sds_fails__w_any_msg()
             ),
         ),
     ]
     for case in cases:
         program_with_ref_to_non_existing_file = program_abs_stx.ProgramOfExecutableFileCommandLineAbsStx(
             path_abs_stx.RelOptPathAbsStx(case.arrangement, 'non-existing-file')
         )
         instruction_syntax = instr_abs_stx.create_w_explicit_contents(
             path_abs_stx.DefaultRelPathAbsStx('dst-file'),
             string_source_abs_stx.StringSourceOfProgramAbsStx(ProcOutputFile.STDOUT,
                                                               program_with_ref_to_non_existing_file,
                                                               ignore_exit_code=False)
         )
         # ACT & ASSERT #
         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,
                               step=case.name):
                 checker.check__abs_stx__std_layouts_and_source_variants(
                     self,
                     instruction_syntax,
                     Arrangement.phase_agnostic(),
                     case.expectation,
                 )
Exemplo n.º 8
0
    def _expect_failure_in(
            step_of_expected_failure: Step) -> MultiSourceExpectation:
        symbol_usages_expectation = asrt.is_sequence_of(
            asrt.is_instance(SymbolReference))

        if step_of_expected_failure is Step.VALIDATE_PRE_SDS:
            return MultiSourceExpectation.phase_agnostic(
                validation=ValidationAssertions.pre_sds_fails__w_any_msg(),
                symbol_usages=symbol_usages_expectation,
            )
        elif step_of_expected_failure is Step.VALIDATE_POST_SDS:
            return MultiSourceExpectation.phase_agnostic(
                validation=ValidationAssertions.post_sds_fails__w_any_msg(),
                symbol_usages=symbol_usages_expectation,
            )
        elif step_of_expected_failure is Step.MAIN:
            return MultiSourceExpectation.phase_agnostic(
                main_result=IS_FAILURE,
                symbol_usages=symbol_usages_expectation,
            )
        else:
            raise ValueError('Unknown {}: {}'.format(Step,
                                                     step_of_expected_failure))
Exemplo n.º 9
0
    def test_non_transformer_components(self):
        # ARRANGE #
        relativity_cases = [
            NArrEx(
                'pre SDS validation failure',
                RelOptionType.REL_HDS_CASE,
                ValidationAssertions.pre_sds_fails__w_any_msg(),
            ),
            NArrEx(
                'post SDS validation failure',
                RelOptionType.REL_ACT,
                ValidationAssertions.post_sds_fails__w_any_msg(),
            ),
        ]

        def make_pgm_w_ref_to_executable_file(
                relativity: RelOptionType) -> ProgramAbsStx:
            return program_abs_stx.ProgramOfExecutableFileCommandLineAbsStx(
                path_abs_stx.RelOptPathAbsStx(relativity, 'non-existing-file'))

        def make_pgm_w_ref_to_stdin_file(
                relativity: RelOptionType) -> ProgramAbsStx:
            return program_abs_stx.FullProgramAbsStx(
                program_abs_stx.ProgramOfSystemCommandLineAbsStx.of_str(
                    'a-system-command'),
                stdin=string_source_abs_stx.StringSourceOfFileAbsStx(
                    path_abs_stx.RelOptPathAbsStx(relativity,
                                                  'non-existing-file')))

        def make_pgm_w_ref_to_argument_file(
                relativity: RelOptionType) -> ProgramAbsStx:
            return program_abs_stx.ProgramOfSystemCommandLineAbsStx.of_str(
                'a-system-command', [
                    ArgumentOfExistingPathAbsStx(
                        path_abs_stx.RelOptPathAbsStx(relativity,
                                                      'non-existing-file'))
                ])

        program_cases = [
            NameAndValue(
                'missing executable file',
                make_pgm_w_ref_to_executable_file,
            ),
            NameAndValue(
                'missing argument file',
                make_pgm_w_ref_to_argument_file,
            ),
            NameAndValue(
                'missing stdin file',
                make_pgm_w_ref_to_stdin_file,
            ),
        ]
        for relativity_case in relativity_cases:
            for program_case in program_cases:
                string_source_syntax = string_source_abs_stx.StringSourceOfProgramAbsStx(
                    ProcOutputFile.STDOUT,
                    program_case.value(relativity_case.arrangement),
                    ignore_exit_code=False,
                )

                # ACT & ASSERT #
                checker = integration_check.checker__w_arbitrary_file_relativities(
                )
                with self.subTest(step=relativity_case.name,
                                  program=program_case.name):
                    checker.check__abs_stx__layouts__source_variants__wo_input(
                        self,
                        equivalent_source_variants__for_full_line_expr_parse__s__nsc,
                        OptionallyOnNewLine(string_source_syntax),
                        arrangement_w_tcds(),
                        MultiSourceExpectation(execution=ExecutionExpectation(
                            validation=relativity_case.expectation)))
Exemplo n.º 10
0
 def test_main_SHOULD_fail_WHEN_source_is_not_an_existing_file_rel_non_hds(self):
     self._check_of_invalid_src_file(RelOptionType.REL_ACT,
                                     ValidationAssertions.post_sds_fails__w_any_msg())