Ejemplo n.º 1
0
    def runTest(self):
        string_72_plus = StringSymbolContext.of_constant(
            'SYMBOL_72_PLUS',
            '72+',
            default_restrictions=asrt_data_rest.
            is__string__w_all_indirect_refs_are_strings(),
        )
        string_5 = StringSymbolContext.of_constant(
            'SYMBOL_5',
            '5',
            default_restrictions=asrt_data_rest.
            is__string__w_all_indirect_refs_are_strings(),
        )
        expected = 72 + 5

        all_symbols = [string_72_plus, string_5]

        value_syntax = StringConcatAbsStx([
            string_72_plus.abstract_syntax,
            string_5.abstract_syntax,
        ])
        CHECKER.check__abs_stx__layout_and_source_variants(
            self,
            InstructionArgumentsAbsStx.of_int(value_syntax),
            Arrangement.phase_agnostic(
                symbols=SymbolContext.symbol_table_of_contexts(all_symbols), ),
            MultiSourceExpectation.phase_agnostic(
                symbol_usages=SymbolContext.usages_assertion_of_contexts(
                    all_symbols),
                instruction_settings=asrt_instr_settings.matches(
                    timeout=asrt.equals(expected))),
        )
Ejemplo n.º 2
0
    def runTest(self):
        # ARRANGE #
        string_72_plus = StringSymbolContext.of_constant(
            'SYMBOL_72_PLUS',
            '72+',
            default_restrictions=asrt_data_rest.
            is__string__w_all_indirect_refs_are_strings(),
        )
        string_5 = StringSymbolContext.of_constant(
            'SYMBOL_5',
            '5',
            default_restrictions=asrt_data_rest.
            is__string__w_all_indirect_refs_are_strings(),
        )
        expected = 72 + 5

        all_symbols = [string_72_plus, string_5]

        value_syntax = StringConcatAbsStx([
            string_72_plus.abstract_syntax,
            string_5.abstract_syntax,
        ])
        # ACT & ASSERT #
        self.conf.instruction_checker.check_parsing__abs_stx__const(
            self, self.conf.parser(),
            InstructionArgumentsAbsStx.of_int(value_syntax),
            self.conf.arrangement(
                symbols=SymbolContext.symbol_table_of_contexts(all_symbols), ),
            self.conf.expect_success(
                symbol_usages=SymbolContext.usages_assertion_of_contexts(
                    all_symbols),
                instruction_settings=asrt_is.matches(
                    timeout=asrt.equals(expected))))
Ejemplo n.º 3
0
 def test_WHEN_defined_symbol_is_in_symbol_table_THEN_validation_error(self):
     # ARRANGE #
     name = 'already-defined'
     symbol_table = StringSymbolContext.of_constant(name, 'arbitrary value').symbol_table
     symbol_definition = StringSymbolContext.of_constant(name, 'other value').definition
     # ACT #
     actual = sut.validate_symbol_usage(symbol_definition, symbol_table)
     self.assertIsNotNone(actual, 'result should indicate error')
     self.assertIs(PartialControlledFailureEnum.VALIDATION_ERROR,
                   actual.status)
Ejemplo n.º 4
0
 def test_WHEN_defined_symbol_not_in_symbol_table_THEN_None_and_added_to_symbol_table(self):
     # ARRANGE #
     symbol_table = StringSymbolContext.of_constant('other', 'value').symbol_table
     symbol_definition = StringSymbolContext.of_constant('undefined', 'value').definition
     # ACT #
     actual = sut.validate_symbol_usage(symbol_definition, symbol_table)
     self.assertIsNone(actual, 'return value for indicating')
     self.assertTrue(symbol_table.contains('undefined'),
                     'definition should be added to symbol table')
     self.assertTrue(symbol_table.contains('other'),
                     'definition in symbol table before definition should remain there')
Ejemplo n.º 5
0
    def test_one_symbol_is_predefined(self):
        predefined_symbol = StringSymbolContext.of_constant(
            'predefined symbol name',
            'predefined string constant symbol value')

        expected_predefined_symbols = predefined_symbol.symbol_table
        all_predefined_symbols = frozenset((predefined_symbol.name, ))

        expected_phase_2_step_2_names_set = {
            PhaseEnum.SETUP:
            psr.same_value_for_all_steps(step.ALL_SETUP_WITH_ENV_ARG,
                                         all_predefined_symbols),
            PhaseEnum.ACT:
            psr.same_value_for_all_steps(step.ALL_ACT_WITH_ENV_ARG,
                                         all_predefined_symbols),
            PhaseEnum.BEFORE_ASSERT:
            psr.same_value_for_all_steps(step.ALL_BEFORE_ASSERT_WITH_ENV_ARG,
                                         all_predefined_symbols),
            PhaseEnum.ASSERT:
            psr.same_value_for_all_steps(step.ALL_ASSERT_WITH_ENV_ARG,
                                         all_predefined_symbols),
            PhaseEnum.CLEANUP:
            psr.same_value_for_all_steps(step.ALL_CLEANUP_WITH_ENV_ARG,
                                         all_predefined_symbols),
        }
        actual_phase_2_step_2_names_set = psr.new_phase_enum_2_empty_dict()

        def recorder_for(phase_step: SimplePhaseStep):
            return psr.StepRecordingAction(
                phase_step, actual_phase_2_step_2_names_set,
                get_symbols_name_set_from_instruction_environment)

        test_case = partial_test_case_with_instructions(
            [
                psr.setup_phase_instruction_that_records_a_value_per_step(
                    recorder_for)
            ],
            psr.act_phase_instructions_that_does_nothing(),
            [
                psr.
                before_assert_phase_instruction_that_records_a_value_per_step(
                    recorder_for)
            ],
            [
                psr.assert_phase_instruction_that_records_a_value_per_step(
                    recorder_for)
            ],
            [
                psr.cleanup_phase_instruction_that_records_a_value_per_step(
                    recorder_for)
            ],
        )
        test__va(
            self, test_case,
            Arrangement(psr.actor_that_records_a_value_per_step(
                recorder_for, recorder_for_parse_step=psr.no_recording),
                        predefined_symbols=expected_predefined_symbols),
            asrt.anything_goes())
        _check_result(self, expected_phase_2_step_2_names_set,
                      actual_phase_2_step_2_names_set)
Ejemplo n.º 6
0
    def test_builtin_symbol_with_reference_to_it(self):
        existing_builtin_symbol = StringSymbolContext.of_constant(
            'BUILTIN_STRING_SYMBOL', 'the builtin symbol value')

        case_with_single_def = File(
            'test.case',
            lines_content([
                phase_names.SETUP.syntax,
                sym_def.reference_to(existing_builtin_symbol.name,
                                     existing_builtin_symbol.value.value_type),
            ]))

        check_case_and_suite(
            self,
            symbol_command_arguments=symbol_args.individual__definition(
                case_with_single_def.name,
                existing_builtin_symbol.name,
            ),
            arrangement=Arrangement(
                cwd_contents=DirContents([
                    case_with_single_def,
                ]),
                main_program_config=sym_def.main_program_config(
                    builtin_symbols=[
                        sym_def.builtin_symbol(existing_builtin_symbol)
                    ], ),
            ),
            expectation=asrt_proc_result.sub_process_result(
                exitcode=asrt.equals(exit_codes.EXIT_OK),
                stdout=definition_of_builtin_symbol(
                    existing_builtin_symbol.name,
                    existing_builtin_symbol.value.value_type,
                    num_refs=1)))
Ejemplo n.º 7
0
 def test_string_symbol_reference(self):
     for other_valid_file_spec_case in OTHER_VALID_FILE_SPECS:
         for file_name_case in INVALID_FILE_NAMES:
             file_name_symbol = StringSymbolContext.of_constant(
                 'FILE_NAME_SYMBOL',
                 file_name_case.value,
                 default_restrictions=asrt_rest.is__string__w_all_indirect_refs_are_strings(),
             )
             file_name_abs_stx = file_name_symbol.abstract_syntax
             for file_spec_case in file_type_and_contents_variants(file_name_abs_stx):
                 integration_check.CHECKER.check__abs_stx__layout__std_source_variants(
                     self,
                     LiteralFilesSourceAbsStx(other_valid_file_spec_case.value + [file_spec_case.value]),
                     models.empty(),
                     arrangement_wo_tcds(
                         symbols=file_name_symbol.symbol_table
                     ),
                     MultiSourceExpectation(
                         symbol_references=file_name_symbol.references_assertion,
                         execution=ExecutionExpectation(
                             validation=ValidationAssertions.pre_sds_fails__w_any_msg()
                         )
                     ),
                     sub_test_identifiers={
                         'file-name': file_name_case.name,
                         'type-and-contents': file_spec_case.name,
                         'other-valid-file-spec': other_valid_file_spec_case.name,
                     }
                 )
Ejemplo n.º 8
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),
                    ])),
            ))
    def runTest(self):
        actual_contents = lines_content(['1', '2', '3', '4'])
        symbol_value = '3'
        constant_value = '1'
        operand_symbol = StringSymbolContext.of_constant(
            'operand_symbol', symbol_value)

        expression_that_evaluates_to_actual_number_of_lines = '{sym_ref}+{const}'.format(
            sym_ref=symbol_reference_syntax_for_name(operand_symbol.name),
            const=constant_value,
        )

        symbol_table_with_operand_symbol = operand_symbol.symbol_table

        expected_symbol_usages = asrt.matches_sequence(
            [is_reference_to_symbol_in_expression(operand_symbol.name)])

        self._check_variants_with_expectation_type(
            InstructionArgumentsVariantConstructor(
                operator=comparators.GTE.name,
                operand=expression_that_evaluates_to_actual_number_of_lines),
            expected_result_of_positive_test=PassOrFail.PASS,
            actual_file_contents=actual_contents,
            symbols=symbol_table_with_operand_symbol,
            expected_symbol_references=expected_symbol_usages,
        )
Ejemplo n.º 10
0
 def test_assignment_of_symbols_and_constant_text_within_soft_quotes(self):
     # ARRANGE #
     referred_symbol1 = SymbolWithReferenceSyntax('referred_symbol_1')
     referred_symbol2 = SymbolWithReferenceSyntax('referred_symbol_2')
     assigned_symbol = StringSymbolContext.of_sdv(
         'defined_symbol',
         string_sdv_from_fragments([
             symbol(referred_symbol1.name),
             constant(' between '),
             symbol(referred_symbol2.name),
         ]))
     source = single_line_source('{string_type} {name} = {soft_quote}{sym_ref1} between {sym_ref2}{soft_quote}',
                                 soft_quote=SOFT_QUOTE_CHAR,
                                 name=assigned_symbol.name,
                                 sym_ref1=referred_symbol1,
                                 sym_ref2=referred_symbol2)
     expectation = Expectation.phase_agnostic(
         symbol_usages=asrt.matches_sequence([
             assigned_symbol.assert_matches_definition_of_sdv,
         ]),
         symbols_after_main=assert_symbol_table_is_singleton(
             assigned_symbol.name,
             assigned_symbol.value.assert_matches_container_of_sdv,
         )
     )
     # ACT & ASSERT #
     INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
Ejemplo n.º 11
0
    def test_assignment_of_single_symbol_reference(self):
        # ARRANGE #
        referred_symbol = SymbolWithReferenceSyntax('referred_symbol')
        expected_sdv = string_sdv_from_fragments([symbol(referred_symbol.name),
                                                  constant('\n')])
        assigned_symbol = StringSymbolContext.of_sdv(
            'defined_symbol',
            expected_sdv,
        )
        sb = SB.new_with(referred_symbol=referred_symbol,
                         name_of_defined_symbol=assigned_symbol.name)

        source = sb.lines(
            here_doc_lines(first_line_start='{string_type} {name_of_defined_symbol} = ',
                           marker='EOF',
                           contents_lines=[str(referred_symbol)])
        )
        # EXPECTATION #
        expectation = Expectation.phase_agnostic(
            symbol_usages=asrt.matches_sequence([
                assigned_symbol.assert_matches_definition_of_sdv,
            ]),
            symbols_after_main=assert_symbol_table_is_singleton(
                assigned_symbol.name,
                assigned_symbol.value.assert_matches_container_of_sdv,
            )
        )
        # ACT & ASSERT #
        INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
Ejemplo n.º 12
0
    def test_resolving_object_with_different_symbol_values_SHOULD_give_different_values(self):
        # ARRANGE #

        STRING_SYMBOL_NAME = 'STRING_SYMBOL'

        single_sym_ref_source = remaining_source(symbol_reference_syntax_for_name(STRING_SYMBOL_NAME))

        parser = sut.ParserOfRegex()
        # ACT #
        actual_sdv = parser.parse_from_token_parser(single_sym_ref_source)

        non_matching_string = '0'

        for symbol_value in ['A', 'B']:
            with self.subTest(symbol_value=symbol_value):
                string_symbol = StringSymbolContext.of_constant(STRING_SYMBOL_NAME, symbol_value)
                symbols = string_symbol.symbol_table

                # ASSERT #

                self._assert_resolved_pattern_has_pattern_string(
                    actual_sdv,
                    expected_pattern_string=symbol_value,
                    matching_string=symbol_value,
                    non_matching_string=non_matching_string,
                    symbols=symbols,
                )
Ejemplo n.º 13
0
    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)
                    )
                ),
            )
        )
Ejemplo n.º 14
0
 def test_WHEN_referenced_symbol_is_in_symbol_table_and_satisfies_value_restriction_THEN_no_error(self):
     # ARRANGE #
     symbol_table = StringSymbolContext.of_constant('val_name', 'value string').symbol_table
     symbol_reference = SymbolReference('val_name',
                                        ReferenceRestrictionsOnDirectAndIndirect(
                                            RestrictionThatIsAlwaysSatisfied()))
     # ACT #
     actual = sut.validate_symbol_usage(symbol_reference, symbol_table)
     self.assertIsNone(actual, 'result should indicate success')
Ejemplo n.º 15
0
    def test_symbol_references(self):
        # ARRANGE #
        star_string_symbol = StringSymbolContext.of_constant('STAR_SYMBOL', '* ')

        regex_str = '.* regex'

        regex_arg_str = '.{star}regex'.format(
            star=symbol_reference_syntax_for_name(star_string_symbol.name),
        )

        matches_for_case_sensitive = [' regex', 'before regex after']

        option_cases = [
            option_case_for_no_option(
                _AssertPattern(regex_str,
                               matching_strings=matches_for_case_sensitive,
                               non_matching_string=' REGEX')
            ),

            option_case_for_ignore_case(
                _AssertPattern(regex_str,
                               matching_strings=matches_for_case_insensitive(matches_for_case_sensitive),
                               non_matching_string='regex')
            ),
        ]

        source_cases = [
            SourceCase('single invalid star',
                       Arguments(regex_arg_str),
                       assert_token_stream(is_null=asrt.is_true)
                       ),
            SourceCase('invalid stars at start of regex',
                       Arguments(surrounded_by_soft_quotes(regex_arg_str)),
                       assert_token_stream(is_null=asrt.is_true)
                       ),
        ]

        arrangement = Arrangement(
            symbols=star_string_symbol.symbol_table
        )

        expectation = ExpectationExceptPattern(
            references=asrt.matches_sequence([
                is_reference_to__regex_string_part(star_string_symbol.name),
            ]),
            validation=ValidationAssertions.all_passes(),
        )

        # ACT & ASSERT #

        check_many(self,
                   arrangement,
                   source_cases,
                   expectation,
                   option_cases,
                   )
Ejemplo n.º 16
0
def failing_integer_validation_cases(symbol_in_integer_name: str = 'symbol_in_integer'
                                     ) -> Sequence[IntegerValidationCase]:
    non_int_string_symbol = StringSymbolContext.of_constant(
        symbol_in_integer_name,
        'tre'
    )

    non_iterable_string_symbol = StringSymbolContext.of_constant(
        symbol_in_integer_name,
        '1'
    )

    constant_string_cases = [
        IntegerValidationCase('failing validation/pre sds: ' + expr_str,
                              expr_str,
                              [],
                              [],
                              validation.PRE_SDS_FAILURE_EXPECTATION,
                              validation.ValidationAssertions.pre_sds_fails__w_any_msg(),
                              )
        for expr_str in
        _PRE_SDS_VALIDATION_FAILURE__CONSTANT_STRINGS
    ]

    string_with_symbol_cases = [
        IntegerValidationCase('failing validation/pre sds: non-int string ref',
                              symbol_reference_syntax_for_name(non_int_string_symbol.name),
                              [non_int_string_symbol],
                              [is_reference_to_symbol_in_expression(non_int_string_symbol.name)],
                              validation.PRE_SDS_FAILURE_EXPECTATION,
                              ValidationAssertions.pre_sds_fails__w_any_msg(),
                              ),
        IntegerValidationCase('failing validation/pre sds: non-iterable string ref',
                              'len({})'.format(symbol_reference_syntax_for_name(non_iterable_string_symbol.name)),
                              [non_iterable_string_symbol],
                              [is_reference_to_symbol_in_expression(non_iterable_string_symbol.name)],
                              validation.PRE_SDS_FAILURE_EXPECTATION,
                              ValidationAssertions.pre_sds_fails__w_any_msg(),
                              ),
    ]

    return constant_string_cases + string_with_symbol_cases
Ejemplo n.º 17
0
 def test_WHEN_referenced_symbol_is_in_symbol_table_but_does_not_satisfy_value_restriction_THEN_validation_error(
         self):
     # ARRANGE #
     symbol_table = StringSymbolContext.of_constant('val_name', 'symbol string').symbol_table
     symbol_usage = SymbolReference('val_name',
                                    reference_restrictions__unconditionally_unsatisfied())
     # ACT #
     actual = sut.validate_symbol_usage(symbol_usage, symbol_table)
     self.assertIsNotNone(actual, 'result should indicate error')
     self.assertIs(PartialControlledFailureEnum.VALIDATION_ERROR,
                   actual.status)
Ejemplo n.º 18
0
 def test_WHEN_predefined_symbols_are_specified_THEN_the_set_of_symbols_SHOULD_be_exactly_these_symbols(
         self):
     # ARRANGE #
     predefined_symbols_table = StringSymbolContext.of_constant(
         'predefined symbol',
         'predefined string value (not used by this test)').symbol_table
     predefined_properties = PredefinedProperties(default_environ_getter=get_empty_environ,
                                                  environ=None,
                                                  predefined_symbols=predefined_symbols_table,
                                                  timeout_in_seconds=None)
     self._check(predefined_properties, assert_symbol_table_keys_equals(predefined_symbols_table.names_set))
Ejemplo n.º 19
0
 def test_WHEN_defined_symbol_not_in_symbol_table_but_referenced_symbols_not_in_table_THEN_validation_error(self):
     # ARRANGE #
     symbol_table = StringSymbolContext.of_constant('OTHER', 'value').symbol_table
     symbol = PathSymbolContext.of_sdv(
         'UNDEFINED',
         path_sdvs.rel_symbol(SymbolReference('REFERENCED',
                                              ReferenceRestrictionsOnDirectAndIndirect(
                                                  RestrictionThatIsAlwaysSatisfied())),
                              path_part_sdvs.from_constant_str('file-name')))
     # ACT #
     actual = sut.validate_symbol_usage(symbol.definition, symbol_table)
     self.assertIsNotNone(actual, 'return value for indicating error')
Ejemplo n.º 20
0
    def runTest(self):
        # ARRANGE #
        text_printed_by_program = StringSymbolContext.of_constant('STRING_TO_PRINT_SYMBOL', 'hello world')

        dst_file_symbol = ConstantSuffixPathDdvSymbolContext(
            'DST_FILE_SYMBOL',
            RelOptionType.REL_ACT,
            'dst-file-name.txt',
            sut.REL_OPT_ARG_CONF.options.accepted_relativity_variants,
        )

        to_upper_transformer = TO_UPPER_TRANSFORMER_SYMBOL

        transformed_program_output_contents_syntax = string_source_abs_stx.StringSourceOfProgramAbsStx(
            ProcOutputFile.STDOUT,
            program_abs_stx.FullProgramAbsStx(
                program_abs_stx.ProgramOfPythonInterpreterAbsStx.of_execute_python_src_string(
                    py_programs.single_line_pgm_that_prints_to(
                        ProcOutputFile.STDOUT,
                        text_printed_by_program.name__sym_ref_syntax
                    )
                ),
                transformation=to_upper_transformer.abstract_syntax,
            )
        )
        instruction_syntax = instr_abs_stx.create_w_explicit_contents(
            dst_file_symbol.abstract_syntax,
            transformed_program_output_contents_syntax
        )
        symbols = SymbolContext.symbol_table_of_contexts([
            dst_file_symbol,
            text_printed_by_program,
            to_upper_transformer,
        ])

        # ACT & ASSERT #
        checker = integration_check.checker(False)
        checker.check__abs_stx__std_layouts_and_source_variants(
            self,
            instruction_syntax,
            Arrangement.phase_agnostic(
                symbols=symbols,
                tcds=TcdsArrangement(),
            ),
            MultiSourceExpectation.phase_agnostic(
                main_result=IS_SUCCESS,
                symbol_usages=asrt.matches_sequence([
                    dst_file_symbol.reference_assertion__path_or_string,
                    text_printed_by_program.reference_assertion__w_str_rendering,
                    to_upper_transformer.reference_assertion,
                ]),
            )
        )
Ejemplo n.º 21
0
 def test_WHEN_defined_symbol_not_in_table_but_referenced_symbol_in_table_does_not_satisfy_restriction_THEN_error(
         self):
     # ARRANGE #
     symbol_table = StringSymbolContext.of_constant('REFERENCED', 'value').symbol_table
     symbol = PathSymbolContext.of_sdv(
         'UNDEFINED',
         path_sdvs.rel_symbol(SymbolReference('REFERENCED',
                                              reference_restrictions__unconditionally_unsatisfied()),
                              path_part_sdvs.from_constant_str('file-name')))
     # ACT #
     actual = sut.validate_symbol_usage(symbol.definition, symbol_table)
     # ASSERT #
     self.assertIsNotNone(actual, 'return value for indicating error')
Ejemplo n.º 22
0
 def test_WHEN_all_usages_are_valid_THEN_validation_ok(
         self):
     # ARRANGE #
     symbol_table = empty_symbol_table()
     valid_definition = StringSymbolContext.of_constant('symbol', 'value').definition
     valid__reference = SymbolReference('symbol', reference_restrictions__unconditionally_satisfied())
     symbol_usages = [
         valid_definition,
         valid__reference,
     ]
     # ACT #
     actual = sut.validate_symbol_usages(symbol_usages, symbol_table)
     self.assertIsNone(actual, 'result should indicate ok')
Ejemplo n.º 23
0
    def test_container_SHOULD_be_given_as_argument_to_assertion_on_container(self):
        # ARRANGE #
        builtin_symbol = StringSymbolContext.of_constant('the name', 's',
                                                         definition_source=None)
        actual_definition = builtin_symbol.definition
        actual_container = actual_definition.symbol_container

        assertion_that_is_expected_to_succeed = asrt.is_(actual_container)

        assertion_to_check = symbol_usage_assertions.matches_definition(
            name=asrt.anything_goes(),
            container=assertion_that_is_expected_to_succeed)
        # ACT & ASSERT #
        assertion_to_check.apply_without_message(self, actual_definition)
Ejemplo n.º 24
0
 def test_WHEN_2nd_element_fails_to_validate_THEN_validation_error(self):
     # ARRANGE #
     symbol_table = empty_symbol_table()
     valid_definition = StringSymbolContext.of_constant('name-of-definition', 'value').definition
     invalid__reference = SymbolReference('undefined', reference_restrictions__unconditionally_satisfied())
     symbol_usages = [
         valid_definition,
         invalid__reference,
     ]
     # ACT #
     actual = sut.validate_symbol_usages(symbol_usages, symbol_table)
     self.assertIsNotNone(actual, 'result should indicate error')
     self.assertIs(PartialControlledFailureEnum.VALIDATION_ERROR,
                   actual.status)
Ejemplo n.º 25
0
 def test_failing_validation(self):
     # ARRANGE #
     symbol_not_an_int = StringSymbolContext.of_constant('SYMBOL_NOT_AN_INT', 'notAnInt')
     cases = [
         ValidationCase(comparators.EQ.name + ' not a number',
                        remaining_source(comparators.EQ.name + ' notANumber'),
                        source_assertion=
                        assert_source(is_at_eol=asrt.is_true),
                        ),
         ValidationCase(comparators.EQ.name + ' not an int',
                        remaining_source(comparators.EQ.name + ' 0.5'),
                        source_assertion=
                        assert_source(is_at_eol=asrt.is_true),
                        ),
         ValidationCase(comparators.EQ.name + ' invalid expression syntax',
                        remaining_source(comparators.EQ.name + ' (1'),
                        source_assertion=
                        assert_source(is_at_eol=asrt.is_true),
                        ),
         ValidationCase(comparators.EQ.name + ' with symbol references',
                        remaining_source(
                            '== {}'.format(symbol_reference_syntax_for_name(symbol_not_an_int.name))
                        ),
                        source_assertion=
                        assert_source(is_at_eol=asrt.is_true),
                        references=asrt.matches_singleton_sequence(
                            symbol_not_an_int.reference_assertion__string__w_all_indirect_refs_are_strings),
                        symbols=symbol_not_an_int.symbol_table
                        ),
     ]
     for case in cases:
         with self.subTest(case.name):
             integration_check.CHECKER__PARSE_SIMPLE.check(
                 self,
                 case.source,
                 input_=integration_check.ARBITRARY_MODEL,
                 arrangement=arrangement_wo_tcds(
                     symbols=case.symbols,
                 ),
                 expectation=Expectation(
                     ParseExpectation(
                         source=case.source_assertion,
                         symbol_references=case.references,
                     ),
                     ExecutionExpectation(
                         validation=validation.ValidationAssertions.pre_sds_fails__w_any_msg(),
                     ),
                 )
             )
Ejemplo n.º 26
0
    def test_arbitrary_failure(self):
        # ARRANGE #
        builtin_symbol = StringSymbolContext.of_constant('the name',
                                                         's',
                                                         definition_source=None)
        actual_definition = builtin_symbol.definition
        actual_container = actual_definition.symbol_container

        assertion_that_is_expected_to_succeed = asrt.not_(asrt.is_(actual_container))

        assertion_to_check = symbol_usage_assertions.matches_definition(
            name=asrt.anything_goes(),
            container=assertion_that_is_expected_to_succeed)
        # ACT & ASSERT #
        assert_that_assertion_fails(assertion_to_check, actual_definition)
Ejemplo n.º 27
0
    def runTest(self):
        # ARRANGE #
        input_lines = ['1\n', '2\n', '3\n']
        expected_output_lines = input_lines[0:2]

        range_lim_l = StringSymbolContext.of_constant(
            'LIMIT__LOWER',
            '1',
            default_restrictions=IS_RANGE_EXPR_STR_REFERENCE_RESTRICTIONS,
        )
        range_lim_u = StringSymbolContext.of_constant(
            'LIMIT__UPPER',
            '2',
            default_restrictions=IS_RANGE_EXPR_STR_REFERENCE_RESTRICTIONS,
        )
        symbols = [range_lim_l, range_lim_u]

        integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants_for_full_line_parser_2(
            self,
            single_line_arguments(
                range_lim_l.name__sym_ref_syntax,
                range_lim_u.name__sym_ref_syntax,
            ).as_arguments,
            model_constructor.of_lines(self,
                                       input_lines,
                                       may_depend_on_external_resources=False),
            arrangement_w_tcds(
                symbols=SymbolContext.symbol_table_of_contexts(symbols), ),
            integration_check.expectation_of_successful_execution_2(
                symbol_references=SymbolContext.
                references_assertion_of_contexts(symbols),
                output_lines=expected_output_lines,
                may_depend_on_external_resources=False,
                is_identity_transformer=False,
            ),
        )
Ejemplo n.º 28
0
    def test_SHOULD_not_match_WHEN_resolved_primitive_value_is_none(self):
        # ARRANGE #
        cases = [
            NameAndValue('without symbol table', None),
            NameAndValue(
                'with symbol table',
                StringSymbolContext.of_sdv('the symbol name',
                                           CONSTANT_STRING_SDV).symbol_table),
        ]
        sdv_of_actual = RegexSdvConstantTestImpl(None)

        for case in cases:
            with self.subTest(name=case.name):
                assertion_to_check = sut.matches_regex_sdv(symbols=case.value)
                # ACT & ASSERT #
                assert_that_assertion_fails(assertion_to_check, sdv_of_actual)
 def test_symbol_is_builtin(self):
     for how_to_fix in ['', 'how_to_fix']:
         with self.subTest(how_to_fix=how_to_fix):
             error = _new_em('error message',
                             how_to_fix=how_to_fix)
             failure = FailureOfIndirectReference(failing_symbol='name_of_failing_symbol',
                                                  path_to_failing_symbol=[],
                                                  error=error)
             # ACT #
             checked_symbol = StringSymbolContext.of_constant('checked_symbol',
                                                              'checked symbol value',
                                                              definition_source=None)
             symbol_table = checked_symbol.symbol_table
             actual = sut.ErrorMessage(checked_symbol.name, symbol_table, failure)
             # ASSERT #
             asrt_text_doc.assert_is_valid_text_renderer(self, actual)
Ejemplo n.º 30
0
 def test_WHEN_defined_symbol_not_in_symbol_table_and_referenced_symbol_is_in_table_and_satisfies_restriction_THEN_ok(
         self):
     # ARRANGE #
     referenced_symbol = StringSymbolContext.of_constant('REFERENCED', 'value')
     symbol_table = referenced_symbol.symbol_table
     symbol = PathSymbolContext.of_sdv('UNDEFINED',
                                       path_sdvs.rel_symbol(
                                           SymbolReference('REFERENCED',
                                                           ReferenceRestrictionsOnDirectAndIndirect(
                                                               RestrictionThatIsAlwaysSatisfied())),
                                           path_part_sdvs.from_constant_str('file-name')))
     # ACT #
     actual = sut.validate_symbol_usage(symbol.definition, symbol_table)
     # ASSERT #
     self.assertIsNone(actual, 'return value for indicating success')
     self.assertTrue(symbol_table.contains('UNDEFINED'),
                     'definition should have been added')