Exemple #1
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 #2
0
    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.SymbolSummary(symbol_in_suite,
                                             ValueType.STRING,
                                             num_refs=0),
                        output.SymbolSummary(symbol_in_case__after_preproc,
                                             ValueType.STRING,
                                             num_refs=0),
                    ])),
            ))
Exemple #3
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),
                    ])),
            ))
Exemple #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),
                    ])),
            ))
Exemple #5
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 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),
                    ])),
            ))
    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))))
Exemple #8
0
def definition_of_builtin_symbol(name: str,
                                 value_type: ValueType,
                                 num_refs: int) -> Assertion[str]:
    summary_line = output.summary_of_single(output.SymbolSummary(name,
                                                                 value_type,
                                                                 num_refs))
    return asrt_str.begins_with(''.join([summary_line,
                                         '\n',
                                         MAJOR_BLOCKS_SEPARATOR,
                                         individual.BUILTIN_SYMBOL_DEFINITION_SOURCE_LINE]))
Exemple #9
0
    def test_definition_in_suite_and_case(self):
        symbol_in_suite_name = 'SUITE_SYMBOL'
        symbol_in_case_name = 'CASE_SYMBOL'

        suite_with_single_def = lines_content([
            section_names.CASE__SETUP.syntax,
            sym_def.define_string(symbol_in_suite_name, 'value'),
        ])

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

        for suite_case in suite_cases('single-definition.suite'):
            with self.subTest(suite_case.name):
                test_with_files_in_tmp_dir.check(
                    self,
                    command_line_arguments=symbol_args.arguments(
                        suite_case.value.suite_arguments +
                        [case_with_single_def.name]),
                    arrangement=Arrangement(
                        cwd_contents=DirContents([
                            suite_case.value.suite_file(suite_with_single_def),
                            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(symbol_in_suite_name,
                                                     ValueType.STRING,
                                                     num_refs=0),
                                output.SymbolSummary(symbol_in_case_name,
                                                     ValueType.STRING,
                                                     num_refs=0),
                            ])),
                    ))
Exemple #10
0
    def test_single_definition(self):
        symbol_name__before_preproc = 'STRING_SYMBOL__BEFORE_PRE_PROC'
        symbol_name__after_preproc = 'STRING_SYMBOL'

        py_pgm_that_replaces_symbol_name = File(
            'replace.py',
            preprocessor_utils.SEARCH_REPLACE_PREPROCESSOR__PY_SRC)

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

        test_with_files_in_tmp_dir.check(
            self,
            command_line_arguments=symbol_args.
            py_search_replace_preprocessing_and_case(
                py_pgm_that_replaces_symbol_name.name,
                symbol_name__before_preproc, symbol_name__after_preproc,
                case_with_single_def.name),
            arrangement=Arrangement(
                cwd_contents=DirContents([
                    py_pgm_that_replaces_symbol_name,
                    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(symbol_name__after_preproc,
                                             ValueType.STRING,
                                             num_refs=0),
                    ])),
            ))
    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))))