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)))
Example #2
0
    def test(self):
        name_of_existing_symbol = 'STRING_SYMBOL'
        not_the_name_of_an_existing_symbol = 'NON_EXISTING_SYMBOL'

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

        check_case_and_suite(
            self,
            symbol_command_arguments=symbol_args.individual__references(
                case_with_single_def.name,
                not_the_name_of_an_existing_symbol,
            ),
            arrangement=Arrangement(
                cwd_contents=DirContents([
                    case_with_single_def,
                ]),
                main_program_config=sym_def.main_program_config(),
            ),
            expectation=asrt_proc_result.is_result_for_empty_stdout(
                exit_values.EXECUTION__HARD_ERROR.exit_code))
    def test_symbol_without_references(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.summary_of_single(
            output.SymbolSummary(name_of_existing_symbol,
                                 ValueType.STRING,
                                 num_refs=0))
        check_case_and_suite(
            self,
            symbol_command_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))))
Example #4
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),
                    ])),
            ))
Example #5
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),
                    ])),
            ))
Example #6
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),
                    ])),
            ))
Example #7
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()))))
Example #8
0
    def test_empty_file(self):
        emtpy_test_case_file = File.empty('empty.xly')

        check_case_and_suite(
            self,
            symbol_command_arguments=[emtpy_test_case_file.name],
            arrangement=Arrangement(cwd_contents=DirContents([
                emtpy_test_case_file,
            ])),
            expectation=asrt_proc_result.is_result_for_empty_stdout(
                exit_codes.EXIT_OK))
Example #9
0
    def test_superfluous_arguments(self):
        case_file = File.empty('test.xly')

        check_case_and_suite(
            self,
            symbol_command_arguments=symbol_args.individual__references(
                case_file.name,
                'symbol_name',
            ) + ['superfluous'],
            arrangement=Arrangement(cwd_contents=DirContents([case_file])),
            expectation=asrt_proc_result.is_result_for_empty_stdout(
                exit_codes.EXIT_INVALID_USAGE))
Example #10
0
    def test_invalid_symbol_name(self):
        case_file = File.empty('test.xly')

        check_case_and_suite(
            self,
            symbol_command_arguments=symbol_args.individual__references(
                case_file.name,
                NOT_A_VALID_SYMBOL_NAME,
            ),
            arrangement=Arrangement(cwd_contents=DirContents([case_file])),
            expectation=asrt_proc_result.is_result_for_empty_stdout(
                exit_codes.EXIT_INVALID_USAGE))
Example #11
0
    def test_invalid_option(self):
        case_file = File.empty('test.xly')

        check_case_and_suite(
            self,
            symbol_command_arguments=[
                case_file.name,
                'symbol_name',
                short_and_long_option_syntax.long_syntax('invalid'),
            ],
            arrangement=Arrangement(cwd_contents=DirContents([case_file])),
            expectation=asrt_proc_result.is_result_for_empty_stdout(
                exit_codes.EXIT_INVALID_USAGE))
    def test_superfluous_symbol_name(self):
        case_file = File.empty('test.case')

        check_case_and_suite(
            self,
            symbol_command_arguments=[
                case_file.name,
                'symbol_name',
                'superfluous',
            ],
            arrangement=Arrangement(cwd_contents=DirContents([case_file])),
            expectation=asrt_proc_result.is_result_for_empty_stdout(
                exit_codes.EXIT_INVALID_USAGE))
Example #13
0
    def test_invalid_syntax(self):
        file_with_invalid_syntax = File(
            'invalid-syntax.xly',
            lines_content([
                SectionName('nonExistingSection').syntax,
            ]))

        check_case_and_suite(
            self, [file_with_invalid_syntax.name],
            Arrangement(cwd_contents=DirContents([
                file_with_invalid_syntax,
            ])),
            asrt_proc_result.is_result_for_empty_stdout(
                exit_values.NO_EXECUTION__SYNTAX_ERROR.exit_code))
Example #14
0
    def test_multiple_definition(self):
        setup_symbol_name = 'SETUP_SYMBOL'
        before_assert_symbol_name = 'BEFORE_ASSERT_SYMBOL'
        assert_symbol_name = 'ASSERT_SYMBOL'
        cleanup_symbol_name = 'CLEANUP_SYMBOL'
        case_with_one_def_per_phase = File(
            'test.xly',
            lines_content([
                phase_names.SETUP.syntax,
                sym_def.define_string(setup_symbol_name,
                                      setup_symbol_name + 'value'),
                phase_names.BEFORE_ASSERT.syntax,
                sym_def.define_string(before_assert_symbol_name,
                                      before_assert_symbol_name + 'value'),
                phase_names.ASSERT.syntax,
                sym_def.define_string(assert_symbol_name,
                                      assert_symbol_name + 'value'),
                phase_names.CLEANUP.syntax,
                sym_def.define_string(cleanup_symbol_name,
                                      cleanup_symbol_name + 'value'),
            ]))

        check_case_and_suite(
            self,
            symbol_command_arguments=[case_with_one_def_per_phase.name],
            arrangement=Arrangement(
                cwd_contents=DirContents([
                    case_with_one_def_per_phase,
                ]),
                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(setup_symbol_name,
                                             ValueType.STRING,
                                             num_refs=0),
                        output.SymbolSummary(before_assert_symbol_name,
                                             ValueType.STRING,
                                             num_refs=0),
                        output.SymbolSummary(assert_symbol_name,
                                             ValueType.STRING,
                                             num_refs=0),
                        output.SymbolSummary(cleanup_symbol_name,
                                             ValueType.STRING,
                                             num_refs=0),
                    ])),
            ))
Example #15
0
    def test_invalid_arguments(self):
        # ARRANGE #
        file_name = 'file.xly'

        cases = [
            NameAndValue('file-arg is missing', []),
            NameAndValue('file-arg is not existing', [file_name]),
        ]
        for case in cases:
            with self.subTest(case.name):
                cli_arguments = case.value
                # ACT & ASSERT #
                check_case_and_suite(
                    self,
                    cli_arguments,
                    arrangement=Arrangement(),
                    expectation=asrt_proc_result.is_result_for_empty_stdout(
                        exit_codes.EXIT_INVALID_USAGE))
Example #16
0
    def test_invalid_symbol_reference(self):
        file_with_invalid_case = File(
            'invalid-symbol-reference.xly',
            lines_content([
                phase_names.SETUP.syntax,
                sym_def.reference_to('UNDEFINED_SYMBOL', ValueType.STRING),
            ]))

        check_case_and_suite(
            self,
            symbol_command_arguments=[file_with_invalid_case.name],
            arrangement=Arrangement(
                main_program_config=sym_def.main_program_config(),
                cwd_contents=DirContents([
                    file_with_invalid_case,
                ])),
            expectation=asrt_proc_result.is_result_for_empty_stdout(
                exit_values.EXECUTION__VALIDATION_ERROR.exit_code))
Example #17
0
    def test_invalid_syntax_of_act_phase(self):
        file_with_invalid_syntax = File(
            'invalid-syntax.xly',
            lines_content([
                phase_names.ACT.syntax,
                'invalid contents',
            ]))

        check_case_and_suite(
            self,
            symbol_command_arguments=[file_with_invalid_syntax.name],
            arrangement=Arrangement(
                main_program_config=sym_def.main_program_config(
                    ActorThatRaisesParseException()),
                cwd_contents=DirContents([
                    file_with_invalid_syntax,
                ])),
            expectation=asrt_proc_result.is_result_for_empty_stdout(
                exit_values.EXECUTION__SYNTAX_ERROR.exit_code))
Example #18
0
    def test_hard_error_from_instruction_in_conf_phase(self):
        file_with_failing_conf_phase_instruction = File(
            'hard-error.xly',
            lines_content([
                phase_names.CONFIGURATION.syntax,
                sym_def.UNCONDITIONALLY_HARD_ERROR_CONF_PHASE_INSTRUCTION_NAME,
            ]))

        check_case_and_suite(
            self,
            symbol_command_arguments=[
                file_with_failing_conf_phase_instruction.name
            ],
            arrangement=Arrangement(
                main_program_config=sym_def.main_program_config(),
                cwd_contents=DirContents([
                    file_with_failing_conf_phase_instruction,
                ])),
            expectation=asrt_proc_result.is_result_for_empty_stdout(
                exit_values.EXECUTION__HARD_ERROR.exit_code))
Example #19
0
    def test_single_reference_to_builtin_symbol(self):
        name_of_user_defined_symbol = 'USER_DEFINED_SYMBOL'
        builtin_symbol = StringSymbolContext.of_constant(
            'BUILTIN_SYMBOL', 'builtin string symbol value')

        definition_source = sym_def.define_string(
            name_of_user_defined_symbol,
            symbol_reference_syntax_for_name(builtin_symbol.name))
        case_with_single_def = File(
            'test.xly',
            lines_content([
                phase_names.SETUP.syntax,
                definition_source,
            ]))

        expected_reference_output = output.Reference(
            phase_identifier.SETUP,
            output.LineInFilePosition(case_with_single_def.name, 2), [
                definition_source,
            ])

        check_case_and_suite(
            self,
            symbol_command_arguments=symbol_args.individual__references(
                case_with_single_def.name,
                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(builtin_symbol),
                    ]),
            ),
            expectation=asrt_proc_result.sub_process_result(
                exitcode=asrt.equals(exit_codes.EXIT_OK),
                stdout=asrt.equals(
                    lines_content(expected_reference_output.output_lines()))))
    def test_symbol_with_reference_to_builtin_symbol(self):
        existing_builtin_symbol = StringSymbolContext.of_constant(
            'BUILTIN_STRING_SYMBOL', 'the builtin symbol value')
        name_of_existing_user_defined_symbol = 'USER_DEFINED_STRING_SYMBOL'

        case_with_single_def = File(
            'test.case',
            lines_content([
                phase_names.SETUP.syntax,
                sym_def.define_string(
                    name_of_existing_user_defined_symbol,
                    symbol_reference_syntax_for_name(
                        existing_builtin_symbol.name)),
            ]))

        expected_first_line = output.summary_of_single(
            output.SymbolSummary(name_of_existing_user_defined_symbol,
                                 ValueType.STRING,
                                 num_refs=0))
        check_case_and_suite(
            self,
            symbol_command_arguments=symbol_args.individual__definition(
                case_with_single_def.name,
                name_of_existing_user_defined_symbol,
            ),
            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=asrt_str.first_line(asrt.equals(expected_first_line))))
Example #21
0
    def test_references_SHOULD_be_listed_phase_order(self):
        name_of_existing_symbol = 'STRING_SYMBOL'

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

        expected_reference_outputs = [
            output.Reference(
                phase_identifier.SETUP,
                output.LineInFilePosition(case_with_references.name, 12),
                [reference_source]),
            output.Reference(phase_identifier.ACT, None, [reference_source]),
            output.Reference(
                phase_identifier.BEFORE_ASSERT,
                output.LineInFilePosition(case_with_references.name, 8),
                [reference_source]),
            output.Reference(
                phase_identifier.ASSERT,
                output.LineInFilePosition(case_with_references.name, 6),
                [reference_source]),
            output.Reference(
                phase_identifier.CLEANUP,
                output.LineInFilePosition(case_with_references.name, 4),
                [reference_source]),
        ]

        expected_output_lines = list(
            itertools.chain.from_iterable(
                intersperse_list(['', ''],
                                 list(
                                     map(output.Reference.output_lines,
                                         expected_reference_outputs)))))
        check_case_and_suite(
            self,
            symbol_command_arguments=symbol_args.individual__references(
                case_with_references.name,
                name_of_existing_symbol,
            ),
            arrangement=Arrangement(
                cwd_contents=DirContents([
                    case_with_references,
                ]),
                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_output_lines))))