def test_definition_and_reference_in_definition(self):
        leaf_name = 'LEAF_SYMBOL_SYMBOL'
        referrer_name = 'REFERRER_SYMBOL'
        case_with_single_def = File(
            'test.case',
            lines_content([
                phase_names.SETUP.syntax,
                sym_def.define_string(leaf_name, 'value'),
                sym_def.define_string(referrer_name,
                                      symbol_reference_syntax_for_name(leaf_name)),
            ]))

        test_with_files_in_tmp_dir.check(
            self,
            command_line_arguments=
            symbol_args.arguments([case_with_single_def.name]),
            arrangement=
            Arrangement(
                cwd_contents=DirContents([
                    case_with_single_def,
                ]),
                main_program_config=sym_def.main_program_config(),
            ),
            expectation=
            asrt_proc_result.sub_process_result(
                exitcode=asrt.equals(exit_codes.EXIT_OK),
                stdout=asrt.equals(output.list_of([
                    output.SymbolReport(leaf_name, ValueType.STRING, num_refs=1),
                    output.SymbolReport(referrer_name, ValueType.STRING, num_refs=0),
                ])),
            )
        )
 def test_not_matches(self):
     cases = [
         NEA('different keys',
             expected={'expected key': sut.equals('value')},
             actual={'actual key': 'value'},
             ),
         NEA('different values',
             expected={'key': sut.equals('expected value')},
             actual={'key': 'actual value'},
             ),
         NEA('more elements in actual than in expected',
             expected={1: sut.equals('value')},
             actual={1: 'value',
                     2: 'value'},
             ),
         NEA('more elements in expected than in actual',
             expected={1: sut.equals('value'),
                       2: sut.equals('value')},
             actual={1: 'value'},
             ),
     ]
     for nea in cases:
         with self.subTest(nea.name):
             assertion = sut.matches_dict(nea.expected)
             # ACT & ASSERT #
             assert_that_assertion_fails(assertion, nea.actual)
Exemple #3
0
    def test_single_definition_with_single_reference_in_act_phase__with_actor_set_in_conf(
            self):
        symbol_name = 'STRING_SYMBOL'
        case_with_single_def = File(
            'test.xly',
            lines_content([
                phase_names.CONFIGURATION.syntax,
                sym_def.SET_ACTOR_THAT_PARSES_REFERENCES_INSTRUCTION_NAME,
                phase_names.SETUP.syntax,
                sym_def.define_string(symbol_name, 'value'),
                phase_names.ACT.syntax,
                sym_def.reference_to(symbol_name, ValueType.STRING),
            ]))

        check_case_and_suite(
            self,
            symbol_command_arguments=[case_with_single_def.name],
            arrangement=Arrangement(
                main_program_config=sym_def.main_program_config(
                    ActorThatRaisesParseException()),
                cwd_contents=DirContents([
                    case_with_single_def,
                ]),
            ),
            expectation=asrt_proc_result.sub_process_result(
                exitcode=asrt.equals(exit_codes.EXIT_OK),
                stdout=asrt.equals(
                    output.list_of([
                        output.SymbolSummary(symbol_name,
                                             ValueType.STRING,
                                             num_refs=1),
                    ])),
            ))
Exemple #4
0
    def runTest(self):
        # ARRANGE #
        may_depend_on_external_resources = False
        expected = 'the expected\ncontents'
        expected__invalid_line_sequence = ('the expected', '\ncontents')

        expectation = sut.ExpectationOnUnFrozenAndFrozen.equals(
            expected,
            may_depend_on_external_resources=asrt.equals(may_depend_on_external_resources),
            frozen_may_depend_on_external_resources=asrt.equals(may_depend_on_external_resources),
        )

        data__valid = StringSourceData(expected, may_depend_on_external_resources)

        data__invalid_line_sequence = StringSourceData(expected, may_depend_on_external_resources)
        data__invalid_line_sequence.data__as_lines = expected__invalid_line_sequence

        source_constructor = self._source_constructor(data__valid, data__invalid_line_sequence)
        for check_variant in check_variants(expectation):
            with self.subTest(check_method=check_variant.name):
                # ACT & ASSERT #
                test_utils.assert_that_assertion_fails(
                    check_variant.value,
                    sut.SourceConstructors.of_common(source_constructor),
                )
Exemple #5
0
 def assertion(self) -> Assertion[ParseSource]:
     return (asrt_source.is_at_end_of_line(self.current_line_number)
             if self.remaining_part_of_current_line is None else
             asrt_source.source_is_not_at_end(
                 current_line_number=asrt.equals(self.current_line_number),
                 remaining_part_of_current_line=asrt.equals(
                     self.remaining_part_of_current_line)))
Exemple #6
0
    def test(self):
        name_of_existing_symbol = 'STRING_SYMBOL'

        case_with_single_def = File('test.case',
                                    lines_content([
                                        phase_names.SETUP.syntax,
                                        sym_def.define_string(name_of_existing_symbol, 'value'),
                                    ]))

        expected_first_line = output.list_of([output.SymbolReport(name_of_existing_symbol,
                                                                  ValueType.STRING,
                                                                  num_refs=0)]).rstrip()
        test_with_files_in_tmp_dir.check(
            self,
            command_line_arguments=
            symbol_args.individual__definition(
                case_with_single_def.name,
                name_of_existing_symbol,
            ),
            arrangement=
            Arrangement(
                cwd_contents=DirContents([
                    case_with_single_def,
                ]),
                main_program_config=sym_def.main_program_config(),
            ),
            expectation=
            asrt_proc_result.sub_process_result(
                exitcode=asrt.equals(exit_codes.EXIT_OK),
                stdout=asrt_str.first_line(asrt.equals(expected_first_line)))
        )
def equals_node(expected: Node) -> Assertion[Node]:
    return matches_node(
        header=asrt.equals(expected.header),
        data=asrt.equals(expected.data),
        details=equals_details(expected.details),
        children=equals_nodes(expected.children),
    )
def is_skipped() -> ValueAssertion[FullExeResult]:
    return matches(status=asrt.is_(FullExeResultStatus.SKIPPED),
                   failure_info=asrt.is_none,
                   has_sds=asrt.equals(False),
                   sds=asrt.is_none,
                   has_action_to_check_outcome=asrt.equals(False),
                   action_to_check_outcome=asrt.is_none)
    def test_single_definition_in_default_suite_file(self):
        symbol_name = 'STRING_SYMBOL'
        suite_with_single_def = File(
            DEFAULT_SUITE_FILE,
            lines_content([
                phase_names.SETUP.syntax,
                sym_def.define_string(symbol_name, 'value'),
            ]))
        dir_arg = Dir('a-dir', [suite_with_single_def])

        test_with_files_in_tmp_dir.check(
            self,
            command_line_arguments=symbol_args.arguments__suite([dir_arg.name
                                                                 ]),
            arrangement=Arrangement(
                cwd_contents=DirContents([
                    dir_arg,
                ]),
                main_program_config=sym_def.main_program_config(),
            ),
            expectation=asrt_proc_result.sub_process_result(
                exitcode=asrt.equals(exit_codes.EXIT_OK),
                stdout=asrt.equals(
                    output.list_of([
                        output.SymbolSummary(symbol_name,
                                             ValueType.STRING,
                                             num_refs=0),
                    ])),
            ))
Exemple #10
0
 def test(self):
     cases = [
         Case('empty line with no following lines',
              source=
              remaining_source(''),
              expectation=
              Expectation(elements=[],
                          source=asrt_source.is_at_end_of_line(1)),
              ),
         Case('only white space on current line, with no following lines',
              source=
              remaining_source('   '),
              expectation=
              Expectation(elements=[],
                          source=asrt_source.source_is_not_at_end(
                              current_line_number=asrt.equals(1),
                              remaining_part_of_current_line=asrt.equals('   '))),
              ),
         Case('empty line, with following lines',
              source=
              remaining_source('', ['contents of following line']),
              expectation=
              Expectation(elements=[],
                          source=asrt_source.is_at_end_of_line(1),
                          )
              ),
     ]
     # ACT & ASSERT #
     _test_cases(self, cases)
Exemple #11
0
    def test_contents_is_larger_than_mem_buff(self):
        # ARRANGE #
        mem_buff_size = 4
        cases = [
            NameAndValue(
                'single line',
                'abc' * mem_buff_size,
            ),
            NameAndValue(
                'multi line',
                '1st\n2nd\n' * mem_buff_size,
            ),
        ]
        for case in cases:
            with self.subTest(case.name):
                source_constructor = _SourceConstructorOfUnfrozenAsConstStr(
                    case.value, mem_buff_size)
                expectation = multi_obj_assertions.ExpectationOnUnFrozenAndFrozen.equals(
                    ''.join(source_constructor.contents),
                    may_depend_on_external_resources=asrt.equals(False),
                    frozen_may_depend_on_external_resources=asrt.equals(True),
                )

                assertion = multi_obj_assertions.assertion_of_sequence_permutations(
                    expectation)
                # ACT & ASSERT #
                assertion.apply_without_message(
                    self,
                    multi_obj_assertions.SourceConstructors.of_common(
                        source_constructor),
                )
    def test_implementation_error_in_act_execute(self):
        test_case = _single_successful_instruction_in_each_phase(single_line_sequence(72, 'ignored'))
        self._check(
            Arrangement(test_case,
                        ActorThatRunsConstantActions(
                            execute_action=execute_action_that_raises(
                                test.ImplementationErrorTestException()))),
            Expectation(
                asrt_result.matches2(PartialExeResultStatus.IMPLEMENTATION_ERROR,
                                     asrt_result.has_sds(),
                                     asrt_result.has_no_action_to_check_outcome(),
                                     ExpectedFailureForPhaseFailure.new_with_exception(
                                         phase_step.ACT__EXECUTE,
                                         test.ImplementationErrorTestException)
                                     ),
                atc_stdout_output=asrt.equals(''),
                atc_stderr_output=asrt.equals(''),
                step_recordings=
                [phase_step.ACT__PARSE] +
                SYMBOL_VALIDATION_STEPS__ONCE +
                PRE_SDS_VALIDATION_STEPS__ONCE +
                [phase_step.SETUP__MAIN,

                 phase_step.SETUP__VALIDATE_POST_SETUP,
                 phase_step.ACT__VALIDATE_POST_SETUP,
                 phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP,
                 phase_step.ASSERT__VALIDATE_POST_SETUP,

                 phase_step.ACT__PREPARE,
                 phase_step.ACT__EXECUTE,

                 (phase_step.CLEANUP__MAIN, PreviousPhase.ACT),
                 ],
            ))
Exemple #13
0
    def test_not_matches(self):
        # ARRANGE #
        expected_instruction = Instruction()
        expected_description = 'the description'
        instruction_info = InstructionInfo(expected_instruction, expected_description)
        expected_source = LineSequence(1, ('expected',))
        actual_element = ParsedInstruction(expected_source, instruction_info)

        cases = [
            NameAndValue('mismatch on source',
                         sut.matches_instruction(asrt.not_(equals_line_sequence(expected_source)),
                                                 matches_instruction_info(asrt.equals(expected_description),
                                                                          asrt.is_(expected_instruction)))
                         ),
            NameAndValue('mismatch on description',
                         sut.matches_instruction(equals_line_sequence(expected_source),
                                                 matches_instruction_info(asrt.not_(asrt.equals(expected_description)),
                                                                          asrt.is_(expected_instruction)))
                         ),
            NameAndValue('mismatch on instruction',
                         sut.matches_instruction(equals_line_sequence(expected_source),
                                                 matches_instruction_info(asrt.not_(asrt.equals(expected_description)),
                                                                          asrt.not_(asrt.is_(expected_instruction))))
                         ),
        ]
        for nav in cases:
            with self.subTest(nav.name):
                # ACT & ASSERT #
                assert_that_assertion_fails(nav.value, actual_element)
Exemple #14
0
    def runTest(self):
        # ARRANGE #
        arguments = names.IDENTITY_TRANSFORMER_NAME

        model_content_lines = ['the model contents line 1']

        # ACT & ASSERT #

        integration_check.CHECKER__PARSE_FULL.check__w_source_variants(
            self,
            Arguments(arguments),
            model_constructor.of_lines(self, model_content_lines),
            arrangement_w_tcds(),
            Expectation(
                ParseExpectation(
                    symbol_references=asrt.is_empty_sequence,
                ),
                ExecutionExpectation(
                    main_result=asrt_string_source.pre_post_freeze__matches_lines__identical(
                        asrt.equals(model_content_lines),
                        may_depend_on_external_resources=asrt.equals(False),
                    )
                ),
                prim_asrt__constant(is_identity_transformer(True)),
                adv=freeze_check.first_invoked_method_of_source_model__is_freeze,
            )
        )
    def runTest(self):
        # ARRANGE #

        source_file = fs.File.empty('source-file.src')

        python_interpreter_symbol = PathSymbolContext.of_sdv(
            'PYTHON_INTERPRETER_SYMBOL',
            path_sdvs.constant(
                path_ddvs.absolute_path(pathlib.Path(sys.executable))))

        interpreter_with_symbol_reference = command_sdvs.for_executable_file(
            python_interpreter_symbol.reference_sdv__path_or_string(
                relativity_configurations.INTERPRETER_FILE.relativity))

        arrangement = arrangement_w_tcds(
            symbol_table=python_interpreter_symbol.symbol_table,
            hds_contents=relativity_configurations.ATC_FILE.
            populator_for_relativity_option_root__hds(
                fs.DirContents([source_file])))
        expectation = Expectation(
            symbol_usages=asrt.matches_singleton_sequence(
                python_interpreter_symbol.reference_assertion__path_or_string),
            post_sds=PostSdsExpectation.constant(
                sub_process_result_from_execute=asrt_pr.sub_process_result(
                    exitcode=asrt.equals(0),
                    stdout=asrt.equals(''),
                    stderr=asrt.equals(''),
                )),
        )
        # ACT & ASSERT #
        check_execution(self, sut.actor(interpreter_with_symbol_reference),
                        [instr([])], arrangement, expectation)
 def test_parse(self):
     pattern = 'include*'
     space = '   '
     cases = [
         SourceCase('single name argument',
                    remaining_source(name_glob_pattern_matcher_of(pattern)),
                    assert_source(is_at_eof=asrt.is_true),
                    ),
         SourceCase('single name argument followed by space, and following lines',
                    remaining_source(name_glob_pattern_matcher_of(pattern) + space,
                                     ['following line']),
                    assert_source(current_line_number=asrt.equals(1),
                                  remaining_part_of_current_line=asrt.equals(space[1:])),
                    ),
         SourceCase('single name argument followed by arguments',
                    remaining_source(name_glob_pattern_matcher_of(pattern) + space + 'following argument',
                                     ['following line']),
                    assert_source(current_line_number=asrt.equals(1),
                                  remaining_part_of_current_line=asrt.equals(space[1:] + 'following argument')),
                    ),
     ]
     for case in cases:
         with self.subTest(case=case.name):
             self._check_parse(
                 case.source,
                 Expectation(
                     resolved_value_equals_file_matcher(file_matchers.FileMatcherNameGlobPattern(pattern)),
                     source=case.source_assertion,
                 )
             )
Exemple #17
0
 def visit_string(self, expected: StringText):
     self._assert_is_type(StringText)
     actual = self.actual
     assert isinstance(actual, StringText)
     asrt.equals(expected.value).apply(
         self.put, actual.value,
         self.message_builder.for_sub_component('value'))
Exemple #18
0
def type_is_file_on_disk(
    path_of_file_on_disk: Assertion[pathlib.Path],
    fileno: Assertion[int] = asrt.anything_goes(),
) -> Assertion[sut.SpooledTextFile]:
    return asrt.and_([
        asrt.sub_component(
            'is_mem_buff',
            sut.SpooledTextFile.is_mem_buff.fget,
            asrt.equals(False),
        ),
        asrt.sub_component(
            'is_file_on_disk',
            sut.SpooledTextFile.is_file_on_disk.fget,
            asrt.equals(True),
        ),
        asrt.sub_component(
            'fileno',
            sut.SpooledTextFile.fileno,
            asrt.is_instance_with(int, fileno),
        ),
        asrt.sub_component(
            'path_of_file_on_disk',
            sut.SpooledTextFile.path_of_file_on_disk.fget,
            path_of_file_on_disk,
        ),
    ])
Exemple #19
0
 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 test_hard_error_in_setup_main_step(self):
     py_pgm_setup = PyProgramSetup('some output to stdout',
                                   'some output to stderr',
                                   72)
     test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr(
         act_phase_source=py_pgm_setup.as_line_sequence()) \
         .add(PartialPhase.SETUP,
              test.setup_phase_instruction_that(
                  main=do_return(sh.new_sh_hard_error('hard error msg from setup'))))
     self._check(
         arr_for_py3_source(test_case),
         Expectation(
             asrt_result.matches2(
                 PartialExeResultStatus.HARD_ERROR,
                 asrt_result.has_sds(),
                 asrt_result.has_no_action_to_check_outcome(),
                 ExpectedFailureForInstructionFailure.new_with_message(
                     phase_step.SETUP__MAIN,
                     test_case.the_extra(PartialPhase.SETUP)[0].source,
                     'hard error msg from setup'),
             ),
             atc_stdout_output=asrt.equals(''),
             atc_stderr_output=asrt.equals(''),
             step_recordings=
             [phase_step.ACT__PARSE] +
             SYMBOL_VALIDATION_STEPS__TWICE +
             PRE_SDS_VALIDATION_STEPS__TWICE +
             [phase_step.SETUP__MAIN,
              (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
              (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP),
              ],
         ))
Exemple #21
0
 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 test_relative_path_to_root_file_in_sub_dir_of_cwd(self):
        # ARRANGE #

        root_file_sub_dir_path = Path('sub-dir')

        root_file_in_sub_dir = file_with_lines('root-file-base-name.src', [
            phase_names.CONFIGURATION.syntax,
            INSTR_THAT_ASSERTS_SOURCE_INFO_MATCHES_LOCATION,
        ])

        cwd_dir_contents = DirContents([
            Dir(str(root_file_sub_dir_path), [
                root_file_in_sub_dir,
            ])
        ])

        file_arg_to_parser_rel_cwd = root_file_sub_dir_path / root_file_in_sub_dir.name

        with tmp_dir_as_cwd(cwd_dir_contents) as abs_cwd_dir_path:
            instruction_parser_file_loc_assertion = matches_file_location_info(
                abs_path_of_dir_containing_first_file_path=asrt.equals(abs_cwd_dir_path),
                file_path_rel_referrer=asrt.equals(file_arg_to_parser_rel_cwd),
                file_inclusion_chain=asrt.is_empty_sequence,
            )

            # ACT & ASSERT #

            fail_if_test_case_does_not_pass(
                self,
                file_arg_to_parser_rel_cwd,
                test_case_definition_with_config_phase_assertion_instruction(self,
                                                                             instruction_parser_file_loc_assertion))
    def test_relative_path_to_root_file_in_sub_dir_of_cwd(self):
        # ARRANGE #

        root_file_sub_dir_path = Path('sub-dir')

        root_file_in_sub_dir = file_with_lines('root-file-base-name.src', [
            phase_names.CONFIGURATION.syntax,
            INSTR_THAT_ASSERTS_SOURCE_INFO_MATCHES_LOCATION,
        ])

        cwd_dir_contents = DirContents([
            Dir(str(root_file_sub_dir_path), [
                root_file_in_sub_dir,
            ])
        ])

        file_arg_to_parser_rel_cwd = root_file_sub_dir_path / root_file_in_sub_dir.name

        with tmp_dir_as_cwd(cwd_dir_contents) as abs_cwd_dir_path:
            instruction_parser_file_loc_assertion = matches_file_location_info(
                abs_path_of_dir_containing_first_file_path=asrt.equals(abs_cwd_dir_path),
                file_path_rel_referrer=asrt.equals(file_arg_to_parser_rel_cwd),
                file_inclusion_chain=asrt.is_empty_sequence,
            )

            # ACT & ASSERT #

            fail_if_test_case_does_not_pass(
                self,
                file_arg_to_parser_rel_cwd,
                test_case_definition_with_config_phase_assertion_instruction(self,
                                                                             instruction_parser_file_loc_assertion))
Exemple #24
0
def equals(expected: Element) -> Assertion[Element]:
    return asrt.and_([
        asrt.sub_component(
            'tag',
            _get_element_tag,
            asrt.equals(expected.tag),
        ),
        asrt.sub_component(
            'attributes',
            _get_element_attrib,
            asrt.equals(expected.attrib),
        ),
        asrt.sub_component(
            'text',
            _get_element_text,
            _text_assertion__none_eq_empty_str(expected.text),
        ),
        asrt.sub_component(
            'tail',
            _get_element_tail,
            _text_assertion__none_eq_empty_str(expected.tail),
        ),
        asrt.sub_component(
            'children',
            _get_element_children,
            asrt.matches_sequence__named([
                NameAndValue(repr(child.tag), equals(child))
                for child in list(expected)
            ]),
        ),
    ])
Exemple #25
0
    def test_single_reference_in_act_phase(self):
        name_of_existing_symbol = 'STRING_SYMBOL'

        reference_source = sym_def.reference_to(name_of_existing_symbol,
                                                ValueType.STRING)
        case_with_single_def = File(
            'test.xly',
            lines_content([
                phase_names.SETUP.syntax,
                sym_def.define_string(name_of_existing_symbol, 'value'),
                phase_names.ACT.syntax,
                reference_source,
            ]))

        expected_reference_output = output.Reference(phase_identifier.ACT,
                                                     None, [
                                                         reference_source,
                                                     ])
        check_case_and_suite(
            self,
            symbol_command_arguments=symbol_args.individual__references(
                case_with_single_def.name,
                name_of_existing_symbol,
            ),
            arrangement=Arrangement(
                cwd_contents=DirContents([
                    case_with_single_def,
                ]),
                main_program_config=sym_def.main_program_config(),
            ),
            expectation=asrt_proc_result.sub_process_result(
                exitcode=asrt.equals(exit_codes.EXIT_OK),
                stdout=asrt.equals(
                    lines_content(expected_reference_output.output_lines()))))
Exemple #26
0
def is_skipped() -> Assertion[FullExeResult]:
    return matches(status=asrt.is_(FullExeResultStatus.SKIPPED),
                   failure_info=asrt.is_none,
                   has_sds=asrt.equals(False),
                   sds=asrt.is_none,
                   has_action_to_check_outcome=asrt.equals(False),
                   action_to_check_outcome=asrt.is_none)
Exemple #27
0
def _equals_empty_node(expected: Node) -> Assertion[Node]:
    return asrt_d_tree.matches_node(
        header=asrt.equals(expected.header),
        data=asrt.equals(expected.data),
        details=asrt.is_empty_sequence,
        children=asrt.is_empty_sequence,
    )
Exemple #28
0
    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)
        )
Exemple #29
0
 def test_not_matches(self):
     cases = [
         NEA(
             'color - different values',
             expected=sut.matches_text_style(color=asrt.equals(
                 ForegroundColor.GREEN), ),
             actual=TextStyle(ForegroundColor.RED, None),
         ),
         NEA(
             'color - actual is None',
             expected=sut.matches_text_style(color=asrt.equals(
                 ForegroundColor.GREEN), ),
             actual=TextStyle(None, None),
         ),
         NEA(
             'font_style - different values',
             expected=sut.matches_text_style(font_style=asrt.equals(
                 FontStyle.UNDERLINE), ),
             actual=TextStyle(None, FontStyle.BOLD),
         ),
         NEA(
             'font_style - actual is None',
             expected=sut.matches_text_style(font_style=asrt.equals(
                 FontStyle.UNDERLINE), ),
             actual=TextStyle(None, None),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             assert_that_assertion_fails(case.expected, case.actual)
Exemple #30
0
    def test_hard_error(self):
        the_instruction_environment = instruction_environment.fake_post_sds_environment()
        the_os_services = os_services.new_default()

        cases = [
            (
                'hard error exception in left operand',
                asrt_pfh.is_hard_error(asrt.equals('error error in left op')),

                operand_resolver_that(
                    resolve_return_value_action=actions.do_raise(PfhHardErrorException('error error in left op'))),
                operand_resolver_that(),
            ),
            (
                'hard error exception in right operand',
                asrt_pfh.is_hard_error(asrt.equals('error error in right op')),

                operand_resolver_that(),
                operand_resolver_that(
                    resolve_return_value_action=actions.do_raise(PfhHardErrorException('error error in right op'))),
            ),
        ]

        for name, result_assertion, l_op, r_op in cases:
            instruction_to_check = sut.Instruction(cmp_setup(l_op, r_op))
            with self.subTest(name=name):
                # ACT #

                actual = instruction_to_check.main(the_instruction_environment,
                                                   the_os_services)

                # ASSERT #

                result_assertion.apply_without_message(self, actual)
Exemple #31
0
 def test_matches(self):
     cases = [
         NEA(
             'default',
             expected=sut.matches_element_properties(),
             actual=ElementProperties(Indentation(1, ''),
                                      TEXT_STYLE__NEUTRAL),
         ),
         NEA(
             'indentation',
             expected=sut.matches_element_properties(
                 indentation=sut.matches_indentation(
                     level=asrt.equals(69)), ),
             actual=ElementProperties(Indentation(69, ''),
                                      TEXT_STYLE__NEUTRAL),
         ),
         NEA(
             'text_style',
             expected=sut.matches_element_properties(
                 text_style=sut.matches_text_style(
                     color=asrt.equals(ForegroundColor.GREEN)), ),
             actual=ElementProperties(
                 INDENTATION__NEUTRAL, TextStyle(ForegroundColor.GREEN,
                                                 None)),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             case.expected.apply_without_message(self, case.actual)
Exemple #32
0
    def runTest(self):
        # ARRANGE #
        for transformation_may_depend_on_external_resources in [False, True]:
            with self.subTest(transformation_may_depend_on_external_resources=
                              transformation_may_depend_on_external_resources):
                source_constructor = _SourceConstructorOfTransFun(
                    _transformer_function,
                    [
                        '1st\n',
                        '2nd\n',
                    ],
                    transformation_may_depend_on_external_resources,
                )
                expectation = multi_obj_assertions.ExpectationOnUnFrozenAndFrozen.equals(
                    ''.join(_transformer_function(source_constructor.lines)),
                    may_depend_on_external_resources=asrt.equals(
                        transformation_may_depend_on_external_resources),
                    frozen_may_depend_on_external_resources=asrt.equals(
                        transformation_may_depend_on_external_resources),
                )

                assertion = multi_obj_assertions.assertion_of_sequence_permutations(
                    expectation)
                # ACT & ASSERT #
                assertion.apply_without_message(
                    self,
                    multi_obj_assertions.SourceConstructors.of_common(
                        source_constructor),
                )
    def test_glob_pattern(self):
        match_anything_glob_pattern_string_symbol = StringSymbolContext.of_constant(
            'glob_pattern_symbol',
            '*',
            default_restrictions=glob_pattern.is_reference_restrictions__glob_pattern_string()
        )
        arguments = self.conf.arguments(
            NameGlobPatternVariant(match_anything_glob_pattern_string_symbol.name__sym_ref_syntax)
        )

        integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants(
            self,
            arguments=
            arguments.as_arguments,
            input_=
            ARBITRARY_MODEL,
            arrangement=arrangement_wo_tcds(
                symbols=match_anything_glob_pattern_string_symbol.symbol_table
            ),
            expectation=Expectation(
                ParseExpectation(
                    symbol_references=asrt.matches_sequence([
                        match_anything_glob_pattern_string_symbol.reference_assertion,
                    ]),
                ),
                ExecutionExpectation(
                    main_result=asrt_matching_result.matches_value__w_header(
                        asrt.equals(True),
                        asrt.equals(self.conf.node_name)
                    )
                ),
            )
        )
    def test_path_argument_SHOULD_use_posix_syntax(self):
        # ARRANGE #
        inclusion_directive_name = 'incl-directive'
        parser = sut.FileInclusionDirectiveParser(inclusion_directive_name)

        path_arg = pathlib.PurePosixPath('first') / 'second'
        inclusion_directive_line = inclusion_directive_name + ' ' + str(path_arg)
        source = source_of_lines([
            inclusion_directive_line,
            'second line',
        ])
        # ACT #
        actual = parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
        # ASSERT #
        expected_directive = is_file_inclusion_directive(
            matches_file_inclusion_directive(
                files_to_include=asrt.matches_sequence([
                    asrt.equals(pathlib.Path(path_arg)),
                ]),
                source=matches_line_sequence(
                    first_line_number=asrt.equals(1),
                    lines=asrt.matches_sequence([
                        asrt.equals(inclusion_directive_line)
                    ]))
            ))
        expected_directive.apply_with_message(self,
                                              actual,
                                              'parsed directive')

        expected_source = is_at_beginning_of_line(2)
        expected_source.apply_with_message(self, source, 'source')
Exemple #35
0
 def test_matches(self):
     cases = [
         NEA(
             'default 1',
             expected=sut.matches_text_style(),
             actual=TextStyle(None, None),
         ),
         NEA(
             'default/w color',
             expected=sut.matches_text_style(),
             actual=TextStyle(ForegroundColor.GREEN, None),
         ),
         NEA(
             'default/w style',
             expected=sut.matches_text_style(),
             actual=TextStyle(None, FontStyle.BOLD),
         ),
         NEA(
             'color',
             expected=sut.matches_text_style(color=asrt.equals(
                 ForegroundColor.GREEN), ),
             actual=TextStyle(ForegroundColor.GREEN, None),
         ),
         NEA(
             'font_style',
             expected=sut.matches_text_style(font_style=asrt.equals(
                 FontStyle.BOLD), ),
             actual=TextStyle(None, FontStyle.BOLD),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             case.expected.apply_without_message(self, case.actual)
    def check_exception(self,
                        root_path: pathlib.Path,
                        actual: Exception,
                        put: unittest.TestCase):
        put.assertIsInstance(actual, SuiteParseError)

        expected_source = single_line_sequence(2, self.file_inclusion_line)

        expectation = matches_suite_parse_error(
            suite_file=asrt.equals(self.root_suite_based_at(root_path)),
            maybe_section_name=asrt.equals(phase_names.SETUP.plain),
            source=equals_line_sequence(expected_source),
            source_location=equals_source_location_path(
                SourceLocationPath(
                    SourceLocation(
                        expected_source,
                        self.root_suite_file,
                    ),
                    []
                )
            ),
            document_parser_exception=asrt.is_instance(sec_doc_exceptions.FileAccessError),
        )

        expectation.apply(put, actual)
    def test_WHEN_source_does_start_with_directive_name_but_invalid_number_of_arguments_follows_THEN_exception_SHOULD_be_raised(
            self):
        # ARRANGE #
        inclusion_directive_name = 'include'
        parser = sut.FileInclusionDirectiveParser(inclusion_directive_name)
        cases = [
            NameAndValue('missing argument',
                         inclusion_directive_name,
                         ),
            NameAndValue('superfluous arguments',
                         inclusion_directive_name + '   arg1 superfluous',
                         ),
        ]
        for case in cases:
            with self.subTest(case.name):
                source = source_of_lines([
                    case.value,
                    'second line',
                ])
                # ACT #
                with self.assertRaises(RecognizedSectionElementSourceError) as cm:
                    # ACT & ASSERT #
                    parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
                actual_exception = cm.exception
                assert isinstance(actual_exception, SectionElementError)

                expected_invalid_source = matches_line_sequence(
                    first_line_number=asrt.equals(1),
                    lines=asrt.matches_sequence([
                        asrt.equals(case.value)
                    ]))

                expected_invalid_source.apply_with_message(self, actual_exception.source, 'source')
Exemple #38
0
    def test_definition_and_reference_in_definition(self):
        leaf_name = 'LEAF_SYMBOL_SYMBOL'
        referrer_name = 'REFERRER_SYMBOL'
        case_with_single_def = File(
            'test.xly',
            lines_content([
                phase_names.SETUP.syntax,
                sym_def.define_string(leaf_name, 'value'),
                sym_def.define_string(
                    referrer_name,
                    symbol_reference_syntax_for_name(leaf_name)),
            ]))

        check_case_and_suite(
            self,
            symbol_command_arguments=[case_with_single_def.name],
            arrangement=Arrangement(
                cwd_contents=DirContents([
                    case_with_single_def,
                ]),
                main_program_config=sym_def.main_program_config(),
            ),
            expectation=asrt_proc_result.sub_process_result(
                exitcode=asrt.equals(exit_codes.EXIT_OK),
                stdout=asrt.equals(
                    output.list_of([
                        output.SymbolSummary(leaf_name,
                                             ValueType.STRING,
                                             num_refs=1),
                        output.SymbolSummary(referrer_name,
                                             ValueType.STRING,
                                             num_refs=0),
                    ])),
            ))
Exemple #39
0
 def test_matches(self):
     value1 = 'a value'
     value2 = 'a value'
     cases = [
         NEA('empty',
             expected=[],
             actual=[],
             ),
         NEA('single element / list',
             expected=[sut.equals(value1)],
             actual=[value1],
             ),
         NEA('single element / tuple',
             expected=(sut.equals(value1),),
             actual=(value1,),
             ),
         NEA('many values',
             expected=[sut.equals(value1),
                       sut.equals(value2)],
             actual=[value1,
                     value2],
             ),
     ]
     for nea in cases:
         with self.subTest(nea.name):
             assertion = sut.matches_sequence(nea.expected)
             # ACT & ASSERT #
             assertion.apply_without_message(self, nea.actual)
Exemple #40
0
    def test_single_definition_with_reference_to_builtin_symbol(self):
        builtin_symbol = StringSymbolContext.of_constant(
            'BUILTIN_STRING_SYMBOL', 'builtin string symbol value')
        user_defined_symbol_name = 'STRING_SYMBOL'
        case_with_single_def = File(
            'test.xly',
            lines_content([
                phase_names.SETUP.syntax,
                sym_def.define_string(
                    user_defined_symbol_name,
                    symbol_reference_syntax_for_name(builtin_symbol.name)),
            ]))

        check_case_and_suite(
            self,
            symbol_command_arguments=[case_with_single_def.name],
            arrangement=Arrangement(
                cwd_contents=DirContents([
                    case_with_single_def,
                ]),
                main_program_config=sym_def.main_program_config(
                    builtin_symbols=[
                        sym_def.builtin_symbol(builtin_symbol),
                    ]),
            ),
            expectation=asrt_proc_result.sub_process_result(
                exitcode=asrt.equals(exit_codes.EXIT_OK),
                stdout=asrt.equals(
                    output.list_of([
                        output.SymbolSummary(user_defined_symbol_name,
                                             ValueType.STRING,
                                             num_refs=0),
                    ])),
            ))
Exemple #41
0
 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)
Exemple #42
0
 def test_matches(self):
     expected_string = 'expected string'
     cases = [
         NEA(
             'default/False',
             expected=sut.is_string(),
             actual=StringLineObject('anything', False),
         ),
         NEA(
             'default/True',
             expected=sut.is_string(),
             actual=StringLineObject('anything', True),
         ),
         NEA('string',
             expected=sut.is_string(string=asrt.equals(expected_string)),
             actual=StringLineObject(expected_string, True)),
         NEA(
             'string is line ended',
             expected=sut.is_string(string_is_line_ended=asrt.equals(True)),
             actual=StringLineObject('anything', True),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             case.expected.apply_without_message(self, case.actual)
Exemple #43
0
    def runTest(self):
        # ARRANGE #
        cases = [
            NameAndValue(
                'empty',
                '',
            ),
            NameAndValue(
                'single line',
                'abc',
            ),
            NameAndValue(
                'multi line',
                '1st\n2nd\n',
            ),
        ]
        for case in cases:
            with self.subTest(case.name):
                source_constructor = _SourceConstructor(case.value)
                expectation = multi_obj_assertions.ExpectationOnUnFrozenAndFrozen.equals(
                    ''.join(source_constructor.contents),
                    may_depend_on_external_resources=asrt.equals(False),
                    frozen_may_depend_on_external_resources=asrt.equals(False),
                )

                assertion = multi_obj_assertions.assertion_of_sequence_permutations(
                    expectation)
                # ACT & ASSERT #
                assertion.apply_without_message(
                    self,
                    multi_obj_assertions.SourceConstructors.of_common(
                        source_constructor),
                )
Exemple #44
0
 def runTest(self):
     # ARRANGE #
     may_depend_on_external_resources = False
     contents = 'the contents'
     expectation = sut.ExpectationOnUnFrozenAndFrozen.equals(
         contents,
         may_depend_on_external_resources=asrt.equals(
             may_depend_on_external_resources),
         frozen_may_depend_on_external_resources=asrt.equals(
             may_depend_on_external_resources),
     )
     data__before_and_after_freeze = StringSourceData(
         contents, may_depend_on_external_resources)
     source_constructor = ConstructorOfStringSourceData(
         data__before_and_after_freeze,
         data__before_and_after_freeze,
     )
     for checker_variant in check_variants(expectation):
         with self.subTest(checker_variant.name):
             # ACT & ASSERT #
             checker_variant.value.apply(
                 self,
                 sut.SourceConstructors.of_common(source_constructor),
                 asrt.MessageBuilder(),
             )
def equals_single_line_source_location_path(expected: Line) -> ValueAssertion[SourceLocationPath]:
    return matches_source_location_path(
        source_location=matches_source_location(
            source=matches_line_sequence(
                first_line_number=asrt.equals(expected.line_number),
                lines=asrt.matches_sequence([asrt.equals(expected.text)])),
            file_path_rel_referrer=asrt.is_none),
        file_inclusion_chain=equals_source_location_sequence([]))
    def test_long_path_to_symbol_that_fails(self):
        # ARRANGE #
        restrictions_that_should_not_be_used = sut.ReferenceRestrictionsOnDirectAndIndirect(
            direct=ValueRestrictionThatRaisesErrorIfApplied(),
            indirect=ValueRestrictionThatRaisesErrorIfApplied())
        satisfied_value_type = DataValueType.STRING
        dissatisfied_value_type = DataValueType.PATH

        level_3_symbol = symbol_table_entry('level_3_symbol',
                                            references=[],
                                            value_type=dissatisfied_value_type)
        level_2_symbol = symbol_table_entry('level_2_symbol',
                                            references=[reference_to(level_3_symbol,
                                                                     restrictions_that_should_not_be_used)],
                                            value_type=satisfied_value_type)
        level_1a_symbol = symbol_table_entry('level_1a_symbol',
                                             references=[],
                                             value_type=satisfied_value_type)
        level_1b_symbol = symbol_table_entry('level_1b_symbol',
                                             references=[reference_to(level_2_symbol,
                                                                      restrictions_that_should_not_be_used)],
                                             value_type=satisfied_value_type)
        level_0_symbol = symbol_table_entry('level_0_symbol',
                                            references=[reference_to(level_1a_symbol,
                                                                     restrictions_that_should_not_be_used),
                                                        reference_to(level_1b_symbol,
                                                                     restrictions_that_should_not_be_used)],
                                            value_type=satisfied_value_type)
        symbol_table_entries = [level_0_symbol, level_1a_symbol, level_1b_symbol, level_2_symbol, level_3_symbol]

        symbol_table = symbol_tables.symbol_table_from_entries(symbol_table_entries)

        restriction_on_every_indirect = RestrictionThatRegistersProcessedSymbols(
            resolver_container_2_result__fun=dissatisfaction_if_value_type_is(
                DATA_TYPE_2_VALUE_TYPE[dissatisfied_value_type]))
        restrictions_to_test = sut.ReferenceRestrictionsOnDirectAndIndirect(
            indirect=restriction_on_every_indirect,
            direct=unconditionally_satisfied_value_restriction(),
            meaning_of_failure_of_indirect_reference='meaning of failure')
        # ACT #
        actual_result = restrictions_to_test.is_satisfied_by(symbol_table, level_0_symbol.key, level_0_symbol.value)
        # ASSERT #
        expected_result = is_failure_of_indirect_reference(failing_symbol=asrt.equals(level_3_symbol.key),
                                                           path_to_failing_symbol=asrt.equals([level_1b_symbol.key,
                                                                                               level_2_symbol.key]),
                                                           meaning_of_failure=asrt.equals('meaning of failure'))
        expected_result.apply_with_message(self, actual_result, 'result of processing')
        actual_processed_symbols = dict(restriction_on_every_indirect.visited.items())
        expected_processed_symbol = {
            level_1a_symbol.key: 1,
            level_1b_symbol.key: 1,
            level_2_symbol.key: 1,
            level_3_symbol.key: 1,
        }
        self.assertEqual(expected_processed_symbol,
                         actual_processed_symbols)
Exemple #47
0
def path_relativity_variants_equals(expected: PathRelativityVariants) -> ValueAssertion:
    return asrt.is_instance_with(PathRelativityVariants,
                                 asrt.And([
                                     asrt.sub_component('rel_option_types',
                                                        PathRelativityVariants.rel_option_types.fget,
                                                        asrt.equals(expected.rel_option_types)),
                                     asrt.sub_component('absolute',
                                                        PathRelativityVariants.absolute.fget,
                                                        asrt.equals(expected.absolute)),
                                 ]))
def equals_line(expected: Line) -> ValueAssertion[Any]:
    return asrt.is_instance_with(Line,
                                 asrt.And([
                                     asrt.sub_component('line_number',
                                                        Line.line_number.fget,
                                                        asrt.equals(expected.line_number)),
                                     asrt.sub_component('text',
                                                        Line.text.fget,
                                                        asrt.equals(expected.text))
                                 ]))
Exemple #49
0
def equals_name(name: Name) -> ValueAssertion:
    return asrt.is_instance_with(Name,
                                 asrt.and_([
                                     asrt.sub_component('singular',
                                                        Name.singular.fget,
                                                        asrt.equals(name.singular)),
                                     asrt.sub_component('plural',
                                                        Name.plural.fget,
                                                        asrt.equals(name.plural)),
                                 ]))
    def test_symbol_references(self):
        file_to_interpret = fs.File('python-program.py',
                                    python_program_that_exits_with_code_given_as_first_cl_arg)
        file_to_interpret_symbol = NameAndValue('file_to_interpret_symbol',
                                                file_to_interpret.file_name)
        python_interpreter_symbol = NameAndValue('python_interpreter_symbol', sys.executable)
        exit_code_symbol = NameAndValue('exit_code_symbol', 72)

        argument = ' {python_interpreter} {interpret_option} {file_to_interpret}  "{exit_code}"'.format(
            python_interpreter=symbol_reference_syntax_for_name(python_interpreter_symbol.name),
            interpret_option=args.option(syntax_elements.EXISTING_FILE_OPTION_NAME).as_str,
            file_to_interpret=symbol_reference_syntax_for_name(file_to_interpret_symbol.name),
            exit_code=symbol_reference_syntax_for_name(str(exit_code_symbol.name)),
        )

        following_line = 'following line'
        source = remaining_source(argument, [following_line])

        arrangement = ArrangementWithSds(
            home_or_sds_contents=HomeOrSdsPopulatorForRelOptionType(
                parse_file_ref.ALL_REL_OPTIONS_CONFIG.options.default_option,
                fs.DirContents([file_to_interpret])),
            symbols=SymbolTable({
                python_interpreter_symbol.name: su.string_constant_container(python_interpreter_symbol.value),
                file_to_interpret_symbol.name: su.string_constant_container(file_to_interpret_symbol.value),
                exit_code_symbol.name: su.string_constant_container(str(exit_code_symbol.value)),
            }),
        )

        expectation = embryo_check.Expectation(
            source=assert_source(current_line_number=asrt.equals(2),
                                 column_index=asrt.equals(0)),
            symbol_usages=asrt.matches_sequence([
                matches_reference_2(
                    python_interpreter_symbol.name,
                    equals_data_type_reference_restrictions(
                        parse_file_ref.path_or_string_reference_restrictions(
                            syntax_elements.REL_OPTION_ARG_CONF.options.accepted_relativity_variants
                        ))),
                matches_reference_2(
                    file_to_interpret_symbol.name,
                    equals_data_type_reference_restrictions(
                        parse_file_ref.path_or_string_reference_restrictions(
                            parse_file_ref.ALL_REL_OPTIONS_CONFIG.options.accepted_relativity_variants
                        ))),
                matches_reference_2(
                    exit_code_symbol.name,
                    equals_data_type_reference_restrictions(is_any_data_type()
                                                            )),
            ]),
            main_result=spr_check.is_success_result(exit_code_symbol.value, ''),
        )

        parser = sut.embryo_parser('instruction-name')
        embryo_check.check(self, parser, source, arrangement, expectation)
Exemple #51
0
    def test_validation_pre_sds(self):
        the_instruction_environment = instruction_environment.fake_pre_sds_environment()

        cases = [
            (
                'validation should succeed when both operands succeed',
                asrt_svh.is_success(),

                operand_resolver_that(),
                operand_resolver_that(),
            ),
            (
                'validation exception in left operand',
                asrt_svh.is_validation_error(asrt.equals('error in left op')),

                operand_resolver_that(
                    validate_pre_sds=actions.do_raise(SvhValidationException('error in left op'))),
                operand_resolver_that(),
            ),
            (
                'validation exception in right operand',
                asrt_svh.is_validation_error(asrt.equals('error in right op')),

                operand_resolver_that(),
                operand_resolver_that(
                    validate_pre_sds=actions.do_raise(SvhValidationException('error in right op'))),
            ),
            (
                'hard error exception in left operand',
                asrt_svh.is_hard_error(asrt.equals('error in left op')),

                operand_resolver_that(
                    validate_pre_sds=actions.do_raise(SvhHardErrorException('error in left op'))),
                operand_resolver_that(),
            ),
            (
                'hard error exception in right operand',
                asrt_svh.is_hard_error(asrt.equals('error in right op')),

                operand_resolver_that(),
                operand_resolver_that(
                    validate_pre_sds=actions.do_raise(SvhHardErrorException('error in right op'))),
            ),
        ]

        for name, result_assertion, l_op, r_op in cases:
            instruction_to_check = sut.Instruction(cmp_setup(l_op, r_op))
            with self.subTest(name=name):
                # ACT #

                actual = instruction_to_check.validate_pre_sds(the_instruction_environment)

                # ASSERT #

                result_assertion.apply_without_message(self, actual)
 def _matches_recording_of(cwd_dir_abs_path: Path,
                           string: str,
                           file_path_rel_referrer: Path) -> ValueAssertion[Recording]:
     return matches_recording(
         string=asrt.equals(string),
         file_location_info=matches_file_location_info(
             abs_path_of_dir_containing_first_file_path=asrt.equals(cwd_dir_abs_path),
             file_path_rel_referrer=asrt.equals(file_path_rel_referrer),
             file_inclusion_chain=asrt.is_empty_sequence,
         ),
     )
def is_xpass(sds: ValueAssertion[Optional[SandboxDirectoryStructure]] =
             asrt.is_instance(SandboxDirectoryStructure),
             action_to_check_outcome: ValueAssertion[Optional[ActionToCheckOutcome]] =
             asrt.is_instance(ActionToCheckOutcome)
             ) -> ValueAssertion[FullExeResult]:
    return matches(status=asrt.is_(FullExeResultStatus.XPASS),
                   failure_info=asrt.is_none,
                   has_sds=asrt.equals(True),
                   sds=sds,
                   has_action_to_check_outcome=asrt.equals(True),
                   action_to_check_outcome=action_to_check_outcome)
def equals_test_case_reference(expected: TestCaseFileReference) -> ValueAssertion[TestCaseFileReference]:
    return asrt.and_([
        asrt.sub_component('file_path',
                           TestCaseFileReference.file_path.fget,
                           asrt.equals(expected.file_path)
                           ),
        asrt.sub_component('file_reference_relativity_root_dir',
                           TestCaseFileReference.file_reference_relativity_root_dir.fget,
                           asrt.equals(expected.file_reference_relativity_root_dir)
                           ),
    ])
def equals_shell_command_driver(expected: CommandDriverForShell) -> ValueAssertion[CommandDriver]:
    return asrt.is_instance_with_many(CommandDriverForShell,
                                      [
                                          asrt.sub_component('shell_command_line',
                                                             CommandDriverForShell.shell_command_line.fget,
                                                             asrt.equals(expected.shell_command_line)
                                                             ),
                                          asrt.sub_component('shell',
                                                             _get_is_shell,
                                                             asrt.equals(True)
                                                             ),
                                      ])
    def runTest(self):
        err_msg_from_validator = 'error from validator pre sds'
        name_of_referenced_symbol = 'FILES_MATCHER_SYMBOL'

        expected_symbol_usages = asrt.matches_sequence(
            [is_reference_to_files_matcher(name_of_referenced_symbol)])

        arguments_constructor = args.CompleteArgumentsConstructor(
            args.PathArgumentsConstructor('unused-path-arg'),
            fm_args.argument_constructor_for_symbol_reference(name_of_referenced_symbol)
        )
        arguments = arguments_constructor.apply(
            pfh_expectation_type_config(ExpectationType.POSITIVE),
            default_conf_rel_non_home(RelNonHomeOptionType.REL_CWD),
        )

        cases = [
            NEA('pre sds validation',
                expected=
                Expectation(
                    validation_pre_sds=asrt_svh.is_validation_error(asrt.equals(err_msg_from_validator)),
                    symbol_usages=expected_symbol_usages,
                ),
                actual=
                ValidatorThat(pre_sds_return_value=err_msg_from_validator)
                ),
            NEA('post sds validation',
                expected=
                Expectation(
                    validation_post_sds=asrt_svh.is_validation_error(asrt.equals(err_msg_from_validator)),
                    symbol_usages=expected_symbol_usages,
                ),
                actual=
                ValidatorThat(post_setup_return_value=err_msg_from_validator)
                ),
        ]
        for case in cases:
            with self.subTest(case.name):
                instruction_source = remaining_source(arguments)
                instruction_check.check(
                    self,
                    sut.Parser(),
                    instruction_source,
                    ArrangementPostAct(
                        symbols=SymbolTable({
                            name_of_referenced_symbol:
                                container(FilesMatcherResolverConstantTestImpl(
                                    resolved_value=True,
                                    validator=case.actual,
                                ))
                        }),
                    ),
                    expectation=case.expected)
    def test_definition_in_suite_and_case(self):
        # ARRANGE #

        symbol_in_suite = 'SUITE_STRING_SYMBOL'
        symbol_in_case__before_preproc = 'CASE_STRING_SYMBOL__BEFORE_PRE_PROC'
        symbol_in_case__after_preproc = 'CASE_STRING_SYMBOL'

        suite_with_preprocessor = File(
            'with-preprocessor.suite',
            lines_content([
                section_names.CONFIGURATION.syntax,
                suite_instructions.set_search_replace_preprocessor(
                    symbol_in_case__before_preproc,
                    symbol_in_case__after_preproc
                ),

                phase_names.SETUP.syntax,
                sym_def.define_string(symbol_in_suite, 'suite-value'),
            ])
        )

        case_with_single_def = File(
            'test.case',
            lines_content([
                phase_names.SETUP.syntax,
                sym_def.define_string(symbol_in_case__before_preproc, 'case-value'),
            ]))

        # ACT & ASSERT #

        test_with_files_in_tmp_dir.check(
            self,
            command_line_arguments=
            symbol_args.explicit_suite_and_case(suite_with_preprocessor.name,
                                                case_with_single_def.name),
            arrangement=
            Arrangement(
                cwd_contents=DirContents([
                    suite_with_preprocessor,
                    case_with_single_def,
                ]),
                main_program_config=sym_def.main_program_config(),
            ),
            expectation=
            asrt_proc_result.sub_process_result(
                exitcode=asrt.equals(exit_codes.EXIT_OK),
                stdout=asrt.equals(output.list_of([
                    output.SymbolReport(symbol_in_suite, ValueType.STRING, num_refs=0),
                    output.SymbolReport(symbol_in_case__after_preproc, ValueType.STRING, num_refs=0),
                ])),
            )
        )
Exemple #58
0
    def test_set_value_SHOULD_be_able_to_have_symbol_references_in_the_right_hand_side(self):
        variable_name = 'variable_to_assign'

        my_symbol = NameAndValue('my_symbol', 'my symbol value')
        your_symbol = NameAndValue('your_symbol', 'your symbol value')

        value_template = 'pre {MY_SYMBOL} {YOUR_SYMBOL} post'

        expected_evaluated_value_string = value_template.format(
            MY_SYMBOL=my_symbol.value,
            YOUR_SYMBOL=your_symbol.value,
        )
        expected_environ_after_main = {
            variable_name: expected_evaluated_value_string,
        }
        value_source_string = value_template.format(
            MY_SYMBOL=symbol_reference_syntax_for_name(my_symbol.name),
            YOUR_SYMBOL=symbol_reference_syntax_for_name(your_symbol.name),
        )

        source_line = ' {variable_name} = {soft_quote}{source_value_string}{soft_quote}'.format(
            variable_name=variable_name,
            source_value_string=value_source_string,
            soft_quote=SOFT_QUOTE_CHAR,
        )

        following_line = 'following line'
        source = remaining_source(source_line, [following_line])

        arrangement = ArrangementWithSds(
            symbols=SymbolTable({
                my_symbol.name: su.string_constant_container(my_symbol.value),
                your_symbol.name: su.string_constant_container(your_symbol.value),
            }),
        )

        expectation = embryo_check.Expectation(
            main_side_effect_on_environment_variables=asrt.equals(expected_environ_after_main),
            symbol_usages=asrt.matches_sequence([
                matches_reference_2(
                    my_symbol.name,
                    is_any_data_type_reference_restrictions()),
                matches_reference_2(
                    your_symbol.name,
                    is_any_data_type_reference_restrictions()),
            ]),
            source=assert_source(current_line_number=asrt.equals(2),
                                 column_index=asrt.equals(0)),
        )

        parser = sut.EmbryoParser()
        embryo_check.check(self, parser, source, arrangement, expectation)
def equals_executable_file_command_driver(expected: CommandDriverForExecutableFile
                                          ) -> ValueAssertion[CommandDriver]:
    return asrt.is_instance_with_many(CommandDriverForExecutableFile,
                                      [
                                          asrt.sub_component('executable_file',
                                                             CommandDriverForExecutableFile.executable_file.fget,
                                                             asrt.equals(expected.executable_file)
                                                             ),
                                          asrt.sub_component('shell',
                                                             _get_is_shell,
                                                             asrt.equals(False)
                                                             ),
                                      ])
def equals_system_program_command_driver(expected: CommandDriverForSystemProgram
                                         ) -> ValueAssertion[CommandDriver]:
    return asrt.is_instance_with_many(CommandDriverForSystemProgram,
                                      [
                                          asrt.sub_component('executable_file',
                                                             CommandDriverForSystemProgram.program.fget,
                                                             asrt.equals(expected.program)
                                                             ),
                                          asrt.sub_component('shell',
                                                             _get_is_shell,
                                                             asrt.equals(False)
                                                             ),
                                      ])