コード例 #1
0
    def test_1_file_in_fc_wo_matcher(self):
        # ARRANGE #
        name_of_file_in_fc = 'file-in-files-condition'
        name_of_file_not_in_fc_1 = 'file-not-in-files-condition-1'
        name_of_file_not_in_fc_2 = 'file-not-in-files-condition-2'

        arguments = args.matches_full(
            fc_args.FilesCondition([fc_args.FileCondition(name_of_file_in_fc)])
        )

        checked_dir = DirArgumentHelper(RelOptionType.REL_TMP, 'dir-w-more-than-one-file')

        execution_cases = [
            NExArr(
                '2 files: one file name matches',
                PRIM_AND_EXE_EXPECTATION__NON_MATCH,
                Arrangement(
                    tcds=checked_dir.tcds_arrangement_dir_with_contents([
                        File.empty(name_of_file_in_fc),
                        File.empty(name_of_file_not_in_fc_1),
                    ])
                )
            ),
            NExArr(
                '2 files: no file name matches',
                PRIM_AND_EXE_EXPECTATION__NON_MATCH,
                Arrangement(
                    tcds=checked_dir.tcds_arrangement_dir_with_contents([
                        File.empty(name_of_file_not_in_fc_1),
                        File.empty(name_of_file_not_in_fc_2),
                    ])
                )
            ),
            NExArr(
                '3 files: one file name matches',
                PRIM_AND_EXE_EXPECTATION__NON_MATCH,
                Arrangement(
                    tcds=checked_dir.tcds_arrangement_dir_with_contents([
                        File.empty(name_of_file_in_fc),
                        File.empty(name_of_file_not_in_fc_1),
                        File.empty(name_of_file_not_in_fc_2),
                    ])
                )
            )
        ]
        # ACT & ASSERT #
        integration_check.CHECKER__PARSE_FULL.check_multi__w_source_variants(
            self,
            arguments.as_arguments,
            symbol_references=asrt.is_empty_sequence,
            input_=model_constructor__non_recursive(checked_dir.path_sdv),
            execution=execution_cases
        )
コード例 #2
0
    def test_one_file_wo_matcher_and_one_w_matcher(self):
        # ARRANGE #
        file_name_w_matcher = 'file-name-with-matcher'
        file_name_wo_matcher = 'file-name-without-matcher'

        fm_symbol = 'file_matcher'

        arguments = args.FilesCondition([
            args.FileCondition(file_name_wo_matcher),
            args.FileCondition(
                file_name_w_matcher,
                fm_args.SymbolReferenceWReferenceSyntax(fm_symbol)),
        ])
        # ACT & ASSERT #
        CHECKER.check_multi__w_source_variants(
            self, arguments.as_arguments,
            asrt.matches_sequence([is_reference_to_file_matcher(fm_symbol)]),
            None, [
                NExArr(
                    'FileMatcher should give {}'.format(expected_result),
                    PrimAndExeExpectation.of_prim__const(
                        asrt_primitive.files_matches({
                            PurePosixPath(file_name_wo_matcher):
                            asrt.is_none,
                            PurePosixPath(file_name_w_matcher):
                            asrt_primitive.is_matcher_that_gives(
                                expected_result)
                        })),
                    arrangement_wo_tcds(
                        FileMatcherSymbolContext.of_primitive_constant(
                            fm_symbol, expected_result).symbol_table),
                ) for expected_result in [False, True]
            ])
コード例 #3
0
 def _check___single_and_multi(self,
                               arguments: Arguments,
                               model: int,
                               parser: Parser[MatcherSdv[int]],
                               arrangement: Arrangement,
                               expectation: Expectation):
     for case in _application_result_check_cases(parser):
         with self.subTest(case.name):
             with self.subTest('single execution'):
                 case.value.check(
                     self.tc,
                     arguments.as_remaining_source,
                     constant_model(model),
                     arrangement, expectation,
                 )
             with self.subTest('multiple executions'):
                 case.value.check_single_multi_execution_setup__for_test_of_test_resources(
                     self.tc,
                     arguments,
                     expectation.parse,
                     constant_model(model),
                     NExArr('the one and only execution',
                            expectation.prim_and_exe,
                            arrangement),
                 )
コード例 #4
0
def environment_exe_case(
    environment: Dict[str, str],
    program_symbol_name: str,
) -> NExArr[PrimAndExeExpectation[MatcherWTrace, MatchingResult], Arrangement]:
    py_file = File(
        'environment-vars-check.py',
        py_programs.
        pgm_that_exists_with_zero_exit_code_iff_environment_vars_not_included(
            environment))

    py_file_rel_opt_conf = rel_opt.conf_rel_any(RelOptionType.REL_TMP)
    py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name)

    program_symbol = ProgramSymbolContext.of_sdv(
        program_symbol_name,
        program_sdvs.interpret_py_source_file_that_must_exist(
            py_file_conf.path_sdv))

    return NExArr(
        'Environment: {}'.format(repr(environment)),
        PrimAndExeExpectation.of_exe(
            main_result=asrt_run.is_result_for_py_interpreter(
                py_run_programs.EXIT_CODE_FOR_SUCCESS)),
        arrangement_w_tcds(
            tcds_contents=py_file_rel_opt_conf.
            populator_for_relativity_option_root(DirContents([py_file])),
            symbols=program_symbol.symbol_table,
            process_execution=ProcessExecutionArrangement(
                process_execution_settings=ProcessExecutionSettings.
                with_environ(environment))))
コード例 #5
0
    def runTest(self):
        # ARRANGE #

        files_matcher_name = 'the_files_matcher'
        checked_dir_location = RelSdsOptionType.REL_TMP
        checked_dir = Dir.empty('checked-dir')

        # ACT & ASSERT #

        integration_check.CHECKER__PARSE_FULL.check_multi__w_source_variants(
            self,
            arguments=args.DirContents(
                fsm_args.SymbolReference(files_matcher_name)).as_arguments,
            input_=integration_check.file_in_sds(checked_dir_location,
                                                 checked_dir.name),
            symbol_references=asrt.matches_singleton_sequence(
                is_reference_to_files_matcher(files_matcher_name)),
            execution=[
                NExArr(
                    'checked dir is empty',
                    PrimAndExeExpectation.of_exe(
                        main_result=asrt_matching_result.matches_value(
                            matcher_result)),
                    arrangement_w_tcds(
                        non_hds_contents=sds_populator.contents_in(
                            checked_dir_location, DirContents([checked_dir])),
                        symbols=FilesMatcherSymbolContext.
                        of_primitive_constant(files_matcher_name,
                                              matcher_result).symbol_table,
                    ),
                ) for matcher_result in [False, True]
            ],
        )
コード例 #6
0
    def runTest(self):
        unconditionally_constant_true = FilesMatcherSymbolContext.of_primitive_constant(
            'unconditionally_constant_true', True)
        symbols = unconditionally_constant_true.symbol_table

        location = RelSdsOptionType.REL_TMP
        model_file_name = 'the-checked-file'

        integration_check.CHECKER__PARSE_FULL.check_multi__w_source_variants(
            self,
            arguments=args.DirContents(
                args.SymbolReference(
                    unconditionally_constant_true.name)).as_arguments,
            symbol_references=asrt.matches_singleton_sequence(
                unconditionally_constant_true.reference_assertion),
            input_=integration_check.file_in_sds(location, model_file_name),
            execution=[
                NExArr(
                    invalid_file_case.name,
                    PrimAndExeExpectation.of_exe(
                        is_hard_error=asrt_renderer.
                        is_renderer_of_major_blocks()),
                    arrangement_w_tcds(
                        symbols=symbols,
                        non_hds_contents=sds_populator.contents_in(
                            location, invalid_file_case.value)))
                for invalid_file_case in invalid_model.cases(model_file_name)
            ])
コード例 #7
0
ファイル: recursive.py プロジェクト: emilkarlen/exactly
    def runTest(self):
        # ARRANGE #

        files_matcher_name = 'the_files_matcher'
        checked_dir_location = RelOptionType.REL_ACT
        checked_dir = Dir.empty('checked-dir')

        matcher_argument = SymbolReferenceArgument(files_matcher_name).as_str

        tcds = TcdsArrangementPostAct(
            TcdsPopulatorForRelOptionType(checked_dir_location,
                                          DirContents([checked_dir])))

        source_cases = [
            NameAndValue(
                'All arguments on separate lines',
                Arguments(checked_dir.name, [
                    reserved_words.COLON, args.RECURSION_OPTION_STR,
                    matcher_argument
                ]),
            ),
            NameAndValue(
                'Empty lines between arguments',
                Arguments(checked_dir.name, [
                    '',
                    reserved_words.COLON,
                    '',
                    args.RECURSION_OPTION_STR,
                    '',
                    matcher_argument,
                ]),
            ),
        ]

        execution_cases = [
            NExArr(
                'matcher gives ' + str(matcher_result),
                ExecutionExpectation(
                    main_result=asrt_pfh.is_non_hard_error(matcher_result)),
                ArrangementPostAct2(
                    tcds,
                    symbols=FilesMatcherSymbolContext.of_primitive_constant(
                        files_matcher_name, matcher_result).symbol_table))
            for matcher_result in [False, True]
        ]
        # ACT & ASSERT #

        for source_case in source_cases:
            with self.subTest(source_case=source_case.name):
                INSTRUCTION_CHECKER.check_multi__with_source_variants(
                    self,
                    SourceArrangement.new_w_arbitrary_fs_location(
                        source_case.value),
                    symbol_usages=asrt.matches_singleton_sequence(
                        is_reference_to_files_matcher__usage(
                            files_matcher_name)),
                    execution=execution_cases,
                )
コード例 #8
0
 def execution_cases(
         self) -> Sequence[NExArr[ExecutionResult, Arrangement]]:
     return [
         NExArr(
             num_files_setup.name,
             FullExecutionResult(num_files_setup.expected),
             Arrangement(tcds=self._helper.
                         tcds_arrangement_for_contents_of_checked_dir(
                             num_files_setup.actual)))
         for num_files_setup in self.num_files_setup.cases
     ]
コード例 #9
0
 def test_single_file_name_with_matcher(self):
     # ARRANGE #
     file_name = 'file-name'
     fm_symbol = 'file_matcher'
     cases = [
         NameAndValue(
             'single name entry',
             args.FilesCondition([
                 args.FileCondition(
                     file_name,
                     fm_args.SymbolReferenceWReferenceSyntax(fm_symbol))
             ]),
         ),
         NameAndValue(
             'two entries with same file name, 1st without and 2nd with FileMatcher',
             args.FilesCondition([
                 args.FileCondition(file_name),
                 args.FileCondition(
                     file_name,
                     fm_args.SymbolReferenceWReferenceSyntax(fm_symbol)),
             ]),
         ),
         NameAndValue(
             'two entries with same file name, 1st with and 2nd without FileMatcher',
             args.FilesCondition([
                 args.FileCondition(
                     file_name,
                     fm_args.SymbolReferenceWReferenceSyntax(fm_symbol)),
                 args.FileCondition(file_name),
             ]),
         ),
     ]
     # ACT & ASSERT #
     for case in cases:
         with self.subTest(case.name):
             CHECKER.check_multi__w_source_variants(
                 self, case.value.as_arguments,
                 asrt.matches_sequence(
                     [is_reference_to_file_matcher(fm_symbol)]), None,
                 [
                     NExArr(
                         'FileMatcher should give {}'.format(
                             expected_result),
                         PrimAndExeExpectation.of_prim__const(
                             asrt_primitive.files_matches({
                                 PurePosixPath(file_name):
                                 asrt_primitive.is_matcher_that_gives(
                                     expected_result)
                             })),
                         arrangement_wo_tcds(
                             FileMatcherSymbolContext.of_primitive_constant(
                                 fm_symbol, expected_result).symbol_table),
                     ) for expected_result in [False, True]
                 ])
コード例 #10
0
ファイル: _utils.py プロジェクト: emilkarlen/exactly
 def execution_case_for(result: bool) -> NExArr:
     referenced_matcher = matchers.ConstantMatcherWithCustomTrace(mk_trace, result)
     return NExArr(
         'matcher that gives ' + str(result),
         PrimAndExeExpectation.of_exe(
             main_result=asrt_matching_result.matches(
                 value=asrt.equals(result),
                 trace=trace_equals(mk_trace(result))
             )
         ),
         Arrangement(
             symbols=helper.logic_type_symbol_context_from_primitive(symbol_name,
                                                                     referenced_matcher).symbol_table
         )
     )
コード例 #11
0
 def execution_cases(
         self
 ) -> Sequence[NExArr[ExecutionExpectation, ArrangementPostAct2]]:
     return [
         NExArr(
             'pre sds validation',
             ExecutionExpectation(
                 validation_pre_sds=asrt_svh.is_validation_error(
                     asrt_text_doc.is_string_for_test_that_equals(
                         self.err_msg_from_validator)), ),
             self._arrangement(
                 DdvValidatorThat(pre_sds_return_value=asrt_text_doc.
                                  new_single_string_text_for_test(
                                      self.err_msg_from_validator)))),
         NExArr(
             'post sds validation',
             ExecutionExpectation(main_result=asrt_pfh.is_hard_error(
                 asrt_text_doc.is_string_for_test_that_equals(
                     self.err_msg_from_validator)), ),
             self._arrangement(
                 DdvValidatorThat(post_setup_return_value=asrt_text_doc.
                                  new_single_string_text_for_test(
                                      self.err_msg_from_validator)))),
     ]
コード例 #12
0
 def _check___multi(self,
                    arguments: Arguments,
                    model: int,
                    checker: IntegrationCheckerForTest,
                    arrangement: Arrangement,
                    expectation: Expectation):
     checker.check_single_multi_execution_setup__for_test_of_test_resources(
         self.tc,
         arguments,
         expectation.parse,
         constant_model(model),
         NExArr('only execution',
                expectation.prim_and_exe,
                arrangement),
     )
コード例 #13
0
 def execution_case_for(
     operand_result: bool
 ) -> NExArr[PrimAndExeExpectation[MatcherWTrace[MODEL],
                                   MatchingResult], Arrangement]:
     operand_matcher = helper.logic_type_symbol_context_from_primitive(
         symbol_name,
         matchers.ConstantMatcherWithCustomTrace(
             mk_operand_trace, operand_result))
     trace = tree.Node(logic.NOT_OPERATOR_NAME, not operand_result, (),
                       [mk_operand_trace(operand_result)])
     return NExArr(
         'operand that gives ' + str(operand_result),
         PrimAndExeExpectation.of_exe(
             main_result=asrt_matching_result.matches(
                 value=asrt.equals(not operand_result),
                 trace=trace_equals(trace))),
         Arrangement(symbols=operand_matcher.symbol_table))
コード例 #14
0
    def test_two_different_files_w_matcher(self):
        # ARRANGE #
        file_name__constant = 'file-name-with-constant-matcher'
        file_name__w_variations = 'file-name-with-matcher-with-variations'

        fm__constant = FileMatcherSymbolContextOfPrimitiveConstant(
            'fm_constant', True)
        fm__w_variations = 'fm_w_variations'

        arguments = args.FilesCondition([
            args.FileCondition(
                file_name__constant,
                fm_args.SymbolReferenceWReferenceSyntax(fm__constant.name)),
            args.FileCondition(
                file_name__w_variations,
                fm_args.SymbolReferenceWReferenceSyntax(fm__w_variations)),
        ])
        # ACT & ASSERT #
        CHECKER.check_multi__w_source_variants(
            self, arguments.as_arguments,
            asrt.matches_sequence([
                fm__constant.reference_assertion,
                is_reference_to_file_matcher(fm__w_variations),
            ]), None, [
                NExArr(
                    'FileMatcher with variations should give {}'.format(
                        expected_result_of_matcher_w_variations),
                    PrimAndExeExpectation.of_prim__const(
                        asrt_primitive.files_matches({
                            PurePosixPath(file_name__constant):
                            asrt_primitive.is_matcher_that_gives(
                                fm__constant.result_value),
                            PurePosixPath(file_name__w_variations):
                            asrt_primitive.is_matcher_that_gives(
                                expected_result_of_matcher_w_variations)
                        })),
                    arrangement_wo_tcds(
                        SymbolContext.symbol_table_of_contexts([
                            fm__constant,
                            FileMatcherSymbolContext.of_primitive_constant(
                                fm__w_variations,
                                expected_result_of_matcher_w_variations),
                        ])),
                ) for expected_result_of_matcher_w_variations in [False, True]
            ])
コード例 #15
0
ファイル: _utils.py プロジェクト: emilkarlen/exactly
 def failing_validation_cases(self, symbol_name: str
                              ) -> Sequence[NExArr[PrimAndExeExpectation[MatcherWTrace[MODEL],
                                                                         MatchingResult],
                                                   Arrangement]]:
     return [
         NExArr(
             validation_case.name,
             expected=PrimAndExeExpectation.of_exe(
                 validation=validation_case.expected,
             ),
             arrangement=Arrangement(
                 symbols=self.conf.mk_logic_type_context_of_sdv(
                     symbol_name,
                     self.sdv_with_validation(validation_case.actual)).symbol_table
             )
         )
         for validation_case in failing_validation_cases()
     ]
コード例 #16
0
    def case(
        exit_code_from_program: int
    ) -> NExArr[PrimAndExeExpectation[MatcherWTrace, MatchingResult],
                Arrangement]:
        exit_code_symbol = StringIntConstantSymbolContext(
            exit_code_symbol_name, exit_code_from_program)

        return NExArr(
            'Exit code {}'.format(exit_code_from_program),
            PrimAndExeExpectation.of_exe(
                main_result=asrt_run.is_result_for_py_interpreter(
                    exit_code_from_program)),
            arrangement_w_tcds(
                tcds_contents=py_file_rel_opt_conf.
                populator_for_relativity_option_root(DirContents([py_file])),
                symbols=SymbolContext.symbol_table_of_contexts([
                    program_symbol,
                    exit_code_symbol,
                ]),
            ))
コード例 #17
0
def result_is_single_file_name_w_lazy_conjunction_w_1st_is_applied_before_2nd(
    file_name: str,
    fm1: NameAndValue[bool],
    fm2: NameAndValue[bool],
    additional_symbols: Sequence[SymbolContext] = (),
    additional_entries: Optional[Mapping[
        PurePosixPath, Assertion[Optional[FileMatcher]]]] = None
) -> NExArr[PrimAndExeExpectation[FilesCondition, Optional[MatchingResult]],
            Arrangement]:
    expected_result_of_complex = fm1.value and fm2.value

    sequence_builder = ApplicationSequenceFrom1Builder()

    fst_matcher = sequence_builder.add_applied(fm1, 1)
    snd_matcher__w_respect_to_laziness = (sequence_builder.add_applied(
        fm2, 2) if fm1.value else sequence_builder.add_un_applied(fm2))

    symbols = []
    symbols += additional_symbols
    symbols += [
        FileMatcherSymbolContext.of_sdv(fm1.name, fst_matcher),
        FileMatcherSymbolContext.of_sdv(fm2.name,
                                        snd_matcher__w_respect_to_laziness),
    ]

    entries = ({} if additional_entries is None else dict(additional_entries))
    entries.update({
        PurePosixPath(file_name):
        asrt_primitive.is_matcher_that_gives(expected_result_of_complex)
    })

    return NExArr(
        'combination of {} && {}'.format(fm1.value, fm2.value),
        PrimAndExeExpectation.of_prim__const(
            matches_w_application_order(
                entries, sequence_builder.expected_application_sequence())),
        arrangement_wo_tcds(SymbolContext.symbol_table_of_contexts(symbols)),
    )
コード例 #18
0
ファイル: _utils.py プロジェクト: emilkarlen/exactly
 def cases_for(validation_case: NEA[ValidationAssertions, ValidationActual]
               ) -> List[NExArr[PrimAndExeExpectation[MatcherWTrace[MODEL],
                                                      MatchingResult],
                                Arrangement]]:
     validations = [validation_case.actual] + ([ValidationActual.passes()] * (len(self.operands) - 1))
     return [
         NExArr(
             'validation={}, failing_symbol={}'.format(validation_case.name,
                                                       operand_name_validations[0]),
             PrimAndExeExpectation.of_exe(
                 validation=validation_case.expected
             ),
             Arrangement(
                 symbols=SymbolContext.symbol_table_of_contexts([
                     self.helper.conf.mk_logic_type_context_of_sdv(
                         sym_and_validation[0],
                         self.helper.sdv_with_validation(sym_and_validation[1]))
                     for sym_and_validation in zip(operand_name_validations, validations)
                 ])
             ),
         )
         for operand_name_validations in itertools.permutations(self.operands)
     ]
コード例 #19
0
ファイル: arguments.py プロジェクト: emilkarlen/exactly
        def arguments_case(
            command_line_arguments: List[str],
        ) -> NExArr[PrimAndExeExpectation[StringTransformer, StringSource],
                    Arrangement]:
            arg_list_symbol = ListSymbolContext.of_constants(
                command_line_arg_list_symbol_name, command_line_arguments)

            symbols = [
                program_symbol,
                arg_list_symbol,
            ]

            expected_lines_on_stdout = asrt.matches_sequence(
                [asrt.equals(arg + '\n') for arg in command_line_arguments])

            return NExArr(
                'Arguments: ' + repr(command_line_arguments),
                PrimAndExeExpectation(
                    ExecutionExpectation(
                        main_result=asrt_string_source.
                        pre_post_freeze__matches_lines(
                            expected_lines_on_stdout,
                            may_depend_on_external_resources=asrt.equals(True),
                            frozen_may_depend_on_external_resources=asrt.
                            anything_goes(),
                        )),
                    prim_asrt__constant(
                        asrt_string_transformer.is_identity_transformer(
                            False)),
                ),
                arrangement_w_tcds(
                    symbols=SymbolContext.symbol_table_of_contexts(symbols),
                    tcds_contents=py_file_rel_opt_conf.
                    populator_for_relativity_option_root(DirContents([py_file
                                                                      ])),
                ),
            )
コード例 #20
0
def argument_list_exe_case(
    command_line_arguments: List[str],
    expected_program_arguments: List[str],
    program_symbol_name: str,
    list_arg_symbol_name: str,
) -> NExArr[PrimAndExeExpectation[MatcherWTrace, MatchingResult], Arrangement]:
    py_file = File(
        'arguments-check.py',
        py_run_programs.
        pgm_that_exists_with_zero_exit_code_iff_arguments_are_expected(
            expected_program_arguments))

    py_file_rel_opt_conf = rel_opt.conf_rel_any(RelOptionType.REL_TMP)
    py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name)

    program_symbol = ProgramSymbolContext.of_sdv(
        program_symbol_name,
        program_sdvs.interpret_py_source_file_that_must_exist(
            py_file_conf.path_sdv))

    arg_list_symbol = ListSymbolContext.of_constants(list_arg_symbol_name,
                                                     command_line_arguments)

    return NExArr(
        'Command line arguments: {}'.format(repr(command_line_arguments), ),
        PrimAndExeExpectation.of_exe(
            main_result=asrt_run.is_result_for_py_interpreter(
                py_run_programs.EXIT_CODE_FOR_SUCCESS)),
        arrangement_w_tcds(
            tcds_contents=py_file_rel_opt_conf.
            populator_for_relativity_option_root(DirContents([py_file])),
            symbols=SymbolContext.symbol_table_of_contexts([
                program_symbol,
                arg_list_symbol,
            ]),
        ))
コード例 #21
0
def validation_exe_cases(source_dir_name: str,
                         dst_path_symbol_name: str,
                         ) -> Sequence[NExArr[PrimAndExeExpectation[FilesSource, pathlib.Path],
                                              Arrangement]]:
    return [
        NExArr(
            'dir_partition={}, invalid_contents={}'.format(
                dir_partition_case.name,
                invalid_contents_case.name),
            PrimAndExeExpectation.of_exe(
                validation=dir_partition_case.expectation
            ),
            Arrangement(
                symbols=dir_partition_case.arrangement.symbols.in_arrangement(),
                tcds=TcdsArrangement(
                    tcds_contents=dir_partition_case.arrangement.populator_for_relativity_option_root__s(
                        invalid_contents_case.value
                    )
                )
            )
        )
        for dir_partition_case in dir_partition_cases_for_validation(dst_path_symbol_name)
        for invalid_contents_case in invalid_contents_cases(source_dir_name)
    ]
コード例 #22
0
    def test_1_file_in_fc_w_matcher(self):
        # ARRANGE #
        name_of_file_in_fc = 'file-in-files-condition'
        name_of_file_not_in_fc_1 = 'file-not-in-files-condition-1'
        name_of_file_not_in_fc_2 = 'file-not-in-files-condition-2'

        arguments = args.matches_non_full(
            fc_args.FilesCondition([
                fc_args.FileCondition(name_of_file_in_fc,
                                      fm_args.SymbolReferenceWReferenceSyntax(IS_REGULAR_FILE_FILE_MATCHER.name)),
            ])
        )

        checked_dir = DirArgumentHelper(RelOptionType.REL_TMP, 'dir-w-more-than-one-file')

        execution_cases = [
            NExArr(
                '2 files: one file name matches, and matcher matches',
                PRIM_AND_EXE_EXPECTATION__MATCH,
                Arrangement(
                    symbols=IS_REGULAR_FILE_FILE_MATCHER.symbol_table,
                    tcds=checked_dir.tcds_arrangement_dir_with_contents([
                        File.empty(name_of_file_in_fc),
                        File.empty(name_of_file_not_in_fc_1),
                    ])
                )
            ),
            NExArr(
                '2 files: one file name matches, but matcher does not match',
                PRIM_AND_EXE_EXPECTATION__NON_MATCH,
                Arrangement(
                    symbols=is_dir_file_matcher(IS_REGULAR_FILE_FILE_MATCHER.name).symbol_table,
                    tcds=checked_dir.tcds_arrangement_dir_with_contents([
                        File.empty(name_of_file_in_fc),
                        File.empty(name_of_file_not_in_fc_1),
                    ])
                )
            ),
            NExArr(
                '3 files: one file name matches, and matcher matches',
                PRIM_AND_EXE_EXPECTATION__MATCH,
                Arrangement(
                    symbols=is_dir_file_matcher(IS_REGULAR_FILE_FILE_MATCHER.name).symbol_table,
                    tcds=checked_dir.tcds_arrangement_dir_with_contents([
                        Dir.empty(name_of_file_in_fc),
                        File.empty(name_of_file_not_in_fc_1),
                        File.empty(name_of_file_not_in_fc_2),
                    ])
                )
            )
        ]
        # ACT & ASSERT #
        integration_check.CHECKER__PARSE_FULL.check_multi__w_source_variants(
            self,
            arguments.as_arguments,
            symbol_references=asrt.matches_sequence([
                IS_REGULAR_FILE_FILE_MATCHER.reference_assertion,
            ]),
            input_=model_constructor__non_recursive(checked_dir.path_sdv),
            execution=execution_cases
        )
コード例 #23
0
ファイル: environment.py プロジェクト: emilkarlen/exactly
    def runTest(self):
        # ARRANGE #

        py_file = File('output-env-vars.py',
                       _PGM_THAT_OUTPUTS_ENVIRONMENT_VARS)

        py_file_rel_opt_conf = rel_opt.conf_rel_any(RelOptionType.REL_TMP)
        py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name)

        program_symbol = ProgramSymbolContext.of_sdv(
            'PROGRAM_THAT_EXECUTES_PY_FILE',
            program_sdvs.interpret_py_source_file_that_must_exist(
                py_file_conf.path_sdv))
        environment_cases = [
            {
                '1': 'one',
            },
            {
                '1': 'one',
                '2': 'two',
            },
        ]

        for with_ignored_exit_code in [False, True]:
            with self.subTest(with_ignored_exit_code=with_ignored_exit_code):
                # ACT && ASSERT #

                integration_check.CHECKER__PARSE_FULL.check_multi(
                    self,
                    args.syntax_for_run(
                        program_args.symbol_ref_command_elements(
                            program_symbol.name),
                        ignore_exit_code=with_ignored_exit_code,
                    ),
                    ParseExpectation(
                        source=asrt_source.is_at_end_of_line(1),
                        symbol_references=program_symbol.references_assertion,
                    ),
                    model_constructor.arbitrary(self),
                    [
                        NExArr(
                            'Environment: {}'.format(repr(environment)),
                            PrimAndExeExpectation(
                                ExecutionExpectation(
                                    main_result=asrt_string_source.
                                    pre_post_freeze__matches_lines(
                                        _AssertLinesRepresentSubSetOfDict(
                                            environment),
                                        may_depend_on_external_resources=asrt.
                                        equals(True),
                                        frozen_may_depend_on_external_resources
                                        =asrt.anything_goes(),
                                    )),
                                prim_asrt__constant(
                                    asrt_string_transformer.
                                    is_identity_transformer(False)),
                            ),
                            arrangement_w_tcds(
                                tcds_contents=py_file_rel_opt_conf.
                                populator_for_relativity_option_root(
                                    DirContents([py_file])),
                                symbols=program_symbol.symbol_table,
                                process_execution=ProcessExecutionArrangement(
                                    process_execution_settings=
                                    ProcessExecutionSettings.with_environ(
                                        environment))))
                        for environment in environment_cases
                    ],
                )
コード例 #24
0
                fsm_args.SymbolReference(
                    model_checker_symbol_name)).as_arguments,
            parse_expectation=ParseExpectation(
                symbol_references=asrt.matches_singleton_sequence(
                    is_reference_to_files_matcher(
                        model_checker_symbol_name)), ),
            input_=integration_check.file_in_tcds(model_location, model_name),
            execution=[
                NExArr(
                    contents_case.name,
                    PrimAndExeExpectation.of_exe(),
                    arrangement_w_tcds(
                        tcds_contents=tcds_populators.
                        TcdsPopulatorForRelOptionType(
                            model_location,
                            DirContents(
                                [Dir(model_name, contents_case.actual)])),
                        symbols=SymbolTable({
                            model_checker_symbol_name:
                            model_checker.matcher__sym_tbl_container(
                                self, model_path, contents_case.expected)
                        })),
                ) for contents_case in contents_cases
            ],
        )


class TestConcreteMatcher(unittest.TestCase):
    def test_wo_selection(self):
        # ARRANGE #
        helper = files_matcher_integration.NumFilesWoSelectionTestCaseHelper(
コード例 #25
0
    def test_2_files_in_fc(self):
        # ARRANGE #
        name_of_file_in_fc__1 = 'file-in-files-condition-1'
        name_of_file_in_fc__2 = 'file-in-files-condition-2'
        name_of_file_not_in_fc__1 = 'file-not-in-files-condition-1'
        name_of_file_not_in_fc__2 = 'file-not-in-files-condition-2'

        file_matcher_name = 'the_file_matcher'
        arguments = args.matches_full(
            fc_args.FilesCondition([
                fc_args.FileCondition(name_of_file_in_fc__1,
                                      fm_args.SymbolReferenceWReferenceSyntax(file_matcher_name)),
                fc_args.FileCondition(name_of_file_in_fc__2),
            ])
        )

        checked_dir = DirArgumentHelper(RelOptionType.REL_TMP, 'dir-w-more-than-two-files')

        execution_cases = [
            NExArr(
                '3 files: one file name matches, and matcher matches',
                PRIM_AND_EXE_EXPECTATION__NON_MATCH,
                Arrangement(
                    symbols=is_regular_file_matcher(file_matcher_name).symbol_table,
                    tcds=checked_dir.tcds_arrangement_dir_with_contents([
                        File.empty(name_of_file_in_fc__1),
                        File.empty(name_of_file_not_in_fc__1),
                        File.empty(name_of_file_not_in_fc__2),
                    ])
                )
            ),
            NExArr(
                '3 files: both file names matches, and matcher matches',
                PRIM_AND_EXE_EXPECTATION__NON_MATCH,
                Arrangement(
                    symbols=is_regular_file_matcher(file_matcher_name).symbol_table,
                    tcds=checked_dir.tcds_arrangement_dir_with_contents([
                        File.empty(name_of_file_in_fc__1),
                        File.empty(name_of_file_in_fc__2),
                        File.empty(name_of_file_not_in_fc__1),
                    ])
                )
            ),
            NExArr(
                '3 files: both file name matches, but matcher does not match',
                PRIM_AND_EXE_EXPECTATION__NON_MATCH,
                Arrangement(
                    symbols=is_dir_file_matcher(file_matcher_name).symbol_table,
                    tcds=checked_dir.tcds_arrangement_dir_with_contents([
                        File.empty(name_of_file_in_fc__1),
                        File.empty(name_of_file_in_fc__2),
                        File.empty(name_of_file_not_in_fc__1),
                    ])
                )
            ),
            NExArr(
                '4 files: both file name matches, and matcher matches',
                PRIM_AND_EXE_EXPECTATION__NON_MATCH,
                Arrangement(
                    symbols=is_regular_file_matcher(file_matcher_name).symbol_table,
                    tcds=checked_dir.tcds_arrangement_dir_with_contents([
                        File.empty(name_of_file_in_fc__1),
                        File.empty(name_of_file_in_fc__2),
                        File.empty(name_of_file_not_in_fc__1),
                        File.empty(name_of_file_not_in_fc__2),
                    ])
                )
            ),
        ]
        # ACT & ASSERT #
        integration_check.CHECKER__PARSE_FULL.check_multi__w_source_variants(
            self,
            arguments.as_arguments,
            symbol_references=asrt.matches_sequence([
                is_reference_to_file_matcher(file_matcher_name),
            ]),
            input_=model_constructor__non_recursive(checked_dir.path_sdv),
            execution=execution_cases
        )
コード例 #26
0
    def runTest(self):
        # ARRANGE #
        checked_dir = DirArgumentHelper(RelOptionType.REL_ACT, 'a-dir')

        fc_file_1 = 'file-1'
        fc_file_2 = 'file-2'
        file_name_not_in_fc = 'not-in-fc'

        unconditionally_matching_file_matcher = FileMatcherSymbolContext.of_primitive_constant(
            'unconditionally_matching_file_matcher', True)

        unconditionally_matching_file_matcher_sym_ref_arg = fm_args.SymbolReferenceWReferenceSyntax(
            unconditionally_matching_file_matcher.name)
        unconditionally_matching_file_matcher_sym_ref_assertion = unconditionally_matching_file_matcher.reference_assertion
        symbol_table_with_unconditionally_matching_file_matcher = unconditionally_matching_file_matcher.symbol_table

        files_condition_w_2_files_cases = [
            NIE(
                'no file matcher',
                asrt.is_empty_sequence,
                fc_args.FilesCondition([
                    fc_args.FileCondition(fc_file_1),
                    fc_args.FileCondition(fc_file_2),
                ]),
            ),
            NIE(
                'file matcher on one file',
                asrt.matches_sequence([
                    unconditionally_matching_file_matcher_sym_ref_assertion,
                ]),
                fc_args.FilesCondition([
                    fc_args.FileCondition(
                        fc_file_1,
                        unconditionally_matching_file_matcher_sym_ref_arg),
                    fc_args.FileCondition(fc_file_2),
                ]),
            ),
            NIE(
                'file matcher on all files',
                asrt.matches_sequence([
                    unconditionally_matching_file_matcher_sym_ref_assertion,
                    unconditionally_matching_file_matcher_sym_ref_assertion,
                ]),
                fc_args.FilesCondition([
                    fc_args.FileCondition(
                        fc_file_1,
                        unconditionally_matching_file_matcher_sym_ref_arg),
                    fc_args.FileCondition(
                        fc_file_2,
                        unconditionally_matching_file_matcher_sym_ref_arg),
                ]),
            ),
        ]

        expectation_of_matching_giving_false = PrimAndExeExpectation.of_exe(
            main_result=asrt.equals(False))

        model_contents_cases = [
            NExArr(
                'model is empty',
                expectation_of_matching_giving_false,
                Arrangement(
                    symbols=
                    symbol_table_with_unconditionally_matching_file_matcher,
                    tcds=checked_dir.tcds_arrangement_dir_with_contents([])),
            ),
            NExArr(
                'model contains single file with name in FILES-CONDITION',
                expectation_of_matching_giving_false,
                Arrangement(
                    symbols=
                    symbol_table_with_unconditionally_matching_file_matcher,
                    tcds=checked_dir.tcds_arrangement_dir_with_contents(
                        [File.empty(fc_file_1)])),
            ),
            NExArr(
                'model contains single file with name not in FILES-CONDITION',
                expectation_of_matching_giving_false,
                Arrangement(
                    symbols=
                    symbol_table_with_unconditionally_matching_file_matcher,
                    tcds=checked_dir.tcds_arrangement_dir_with_contents(
                        [File.empty(file_name_not_in_fc)])),
            ),
        ]
        for files_condition_w_2_files_case in files_condition_w_2_files_cases:
            with self.subTest(files_condition_w_2_files_case.name):
                # ACT & ASSERT #
                check_non_full_and_full__multi(
                    self,
                    files_condition_w_2_files_case.input_value,
                    symbol_references=files_condition_w_2_files_case.
                    expected_value,
                    model=model_constructor__non_recursive(
                        checked_dir.path_sdv),
                    execution=model_contents_cases,
                )
コード例 #27
0
ファイル: recursive.py プロジェクト: emilkarlen/exactly
            self,
            SourceArrangement.new_w_arbitrary_fs_location(
                arguments.as_arguments),
            ParseExpectation(symbol_usages=asrt.matches_singleton_sequence(
                is_reference_to_files_matcher__usage(
                    model_checker_symbol_name))),
            execution=[
                NExArr(
                    contents_case.name,
                    ExecutionExpectation(),
                    ArrangementPostAct2(
                        tcds=TcdsArrangementPostAct(
                            tcds_contents=tcds_populators.
                            TcdsPopulatorForRelOptionType(
                                checked_dir_location,
                                DirContents([
                                    Dir(checked_dir_name, contents_case.actual)
                                ]))),
                        symbols=SymbolTable({
                            model_checker_symbol_name:
                            model_checker.matcher__sym_tbl_container(
                                self, checked_dir_path, contents_case.expected)
                        })),
                ) for contents_case in contents_cases
            ],
        )


class TestMultiLineSyntax(unittest.TestCase):
    def runTest(self):
        # ARRANGE #
コード例 #28
0
        # ACT & ASSERT #

        integration_check.CHECKER__PARSE_FULL.check_multi(
            self,
            arguments=fm_args.DirContentsRecursive(
                helper.files_matcher_sym_ref_arg()).as_arguments,
            parse_expectation=helper.parse_expectation_of_symbol_references(),
            input_=helper.model_constructor_for_checked_dir(),
            execution=[
                NExArr(
                    contents_case.name,
                    PrimAndExeExpectation.of_exe(),
                    helper.arrangement_for_contents_of_model(
                        checked_dir_contents=contents_case.actual,
                        files_matcher_symbol_value=model_checker.matcher(
                            self,
                            helper.dir_arg.path_sdv,
                            contents_case.expected,
                        ),
                    ),
                ) for contents_case in contents_cases
            ],
        )


class TestConcreteMatcher(unittest.TestCase):
    def test_wo_selection(self):
        # ARRANGE #
        helper = files_matcher_integration.NumFilesWoSelectionTestCaseHelper(
            files_matcher_integration.MODEL_CONTENTS__RECURSIVE,
            RelSdsOptionType.REL_ACT,