Ejemplo n.º 1
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()))))
Ejemplo n.º 2
0
    def test_empty_blocks_SHOULD_BE_separated_by_single_block_separator(self):
        # Have not implemented filtering of non-empty blocks.
        # Reason is that such blocks should not be constructed.
        # But implement it if it appears to be useful for making
        # construction easier.

        # ARRANGE #
        string_1 = 'the 1st string'

        empty_block = s.MajorBlock([
            s.MinorBlock(
                [],
                s.ELEMENT_PROPERTIES__NEUTRAL,
            ),
        ], s.ELEMENT_PROPERTIES__NEUTRAL)

        non_empty_block = s.MajorBlock(
            [
                single_line_minor_block_w_plain_properties(string_1),
            ],
            s.ELEMENT_PROPERTIES__NEUTRAL,
        )
        cases = [
            NEA(
                'two empty blocks',
                lines_content([
                    MAJOR_BLOCKS_SEPARATOR,
                ]),
                [
                    empty_block,
                    empty_block,
                ],
            ),
            NEA(
                'first non-empty, second empty',
                lines_content([
                    string_1,
                    MAJOR_BLOCKS_SEPARATOR,
                ]),
                [
                    non_empty_block,
                    empty_block,
                ],
            ),
            NEA(
                'first non-empty, second empty',
                lines_content([
                    string_1,
                    MAJOR_BLOCKS_SEPARATOR,
                ]),
                [
                    non_empty_block,
                    empty_block,
                ],
            ),
        ]

        for case in cases:
            check_block_sequence_and_document(self, case)
Ejemplo n.º 3
0
 def file_structure(self, root_path: pathlib.Path) -> DirContents:
     return DirContents([
         File('main.suite', lines_content(['[cases]', 'the.case'])),
         File(
             'the.case',
             lines_content([
                 '[act]', 'system-under-test', '[assert]',
                 'exit-code {eq} 0'.format(eq=comparators.EQ.name)
             ])),
         python_executable_file('system-under-test',
                                PYTHON_PROGRAM_THAT_EXISTS_WITH_STATUS_0)
     ])
Ejemplo n.º 4
0
class ReferencedInclusionDirectiveFileInIncludedFileDoesNotExist(
        check_exception.Setup):
    file_1_invalid_inclusion_line = ' '.join(
        [INCLUDING_DIRECTIVE_INFO.singular_name, 'does-not-exist.txt'])

    file_1 = File('1.xly', lines_content([file_1_invalid_inclusion_line]))

    root_suite_inclusion_line = ' '.join(
        [INCLUDING_DIRECTIVE_INFO.singular_name, file_1.name])
    inclusion_line_in_file_1 = single_line_sequence(
        1, file_1_invalid_inclusion_line)

    root_suite_file = File(
        '0.suite',
        lines_content([
            phase_names.CLEANUP.syntax,
            root_suite_inclusion_line,
        ]))
    inclusion_line_in_root_file = single_line_sequence(
        2, root_suite_inclusion_line)

    expected_source_location_path = SourceLocationPath(
        SourceLocation(
            inclusion_line_in_file_1,
            file_1.name_as_path,
        ), [
            SourceLocation(
                inclusion_line_in_root_file,
                root_suite_file.name_as_path,
            )
        ])

    def root_suite_based_at(self, root_path: pathlib.Path) -> pathlib.Path:
        return self.root_suite_file.name_as_path

    def file_structure_to_read(self) -> DirContents:
        return DirContents([self.root_suite_file, self.file_1])

    def check_exception(self, root_path: pathlib.Path, actual: Exception,
                        put: unittest.TestCase):
        put.assertIsInstance(actual, SuiteParseError)

        expectation = matches_suite_parse_error(
            suite_file=asrt.equals(self.root_suite_based_at(root_path)),
            maybe_section_name=asrt.equals(phase_names.CLEANUP.plain),
            source=equals_line_sequence(self.inclusion_line_in_file_1),
            source_location=equals_source_location_path(
                self.expected_source_location_path),
            document_parser_exception=asrt.is_instance(
                sec_doc_exceptions.FileAccessError),
        )

        expectation.apply(put, actual)
Ejemplo n.º 5
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),
                    ])),
            ))
 def file_structure(self, root_path: pathlib.Path) -> DirContents:
     exe_file = python_executable_file('executable-file',
                                       PYTHON_PROGRAM_THAT_EXISTS_WITH_STATUS_0)
     instruction_that_runs_program = '{run} {exe_file}'.format(
         run=instruction_names.RUN_INSTRUCTION_NAME,
         exe_file=exe_file.name,
     )
     return DirContents([
         File('main.suite', lines_content(['[cases]', 'the.case'])),
         File('the.case', lines_content(['[setup]',
                                         instruction_that_runs_program,
                                         ])),
         exe_file
     ])
Ejemplo n.º 7
0
 def file_structure(self, root_path: pathlib.Path) -> DirContents:
     return DirContents([
         File('main.suite', lines_content(['[cases]', 'the.case'])),
         File(
             'the.case',
             lines_content([
                 '[conf]',
                 '[setup]',
                 '[act]',
                 '[assert]',
                 '[before-assert]',
                 '[cleanup]',
             ])),
     ])
Ejemplo n.º 8
0
 def file_structure(self, root_path: pathlib.Path) -> DirContents:
     return DirContents([
         File(
             'main.suite',
             lines_content(
                 ['[suites]', 'sub.suite', '[cases]', 'main.case'])),
         File('main.case', ''),
         File(
             'sub.suite',
             lines_content(
                 ['[suites]', 'sub-sub.suite', '[cases]', 'sub.case'])),
         File('sub.case', ''),
         File('sub-sub.suite', ''),
     ])
Ejemplo n.º 9
0
 def file_structure_to_read(self, root_path: pathlib.Path) -> DirContents:
     return DirContents([
         Dir('main-sub-dir', [
             File(
                 'main.suite',
                 lines_content([
                     section_names.SUITES.syntax,
                     '../super.suite',
                 ])),
         ]),
         File('super.suite', lines_content([
             'super.case',
         ])),
         File.empty('super.case'),
     ])
Ejemplo n.º 10
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),
                    ])),
            ))
Ejemplo n.º 11
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),
                    ])),
            ))
Ejemplo n.º 12
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),
                    ])),
            ))
Ejemplo n.º 13
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),
                    ])),
            ))
Ejemplo n.º 14
0
    def test_indentation_element_properties_SHOULD_be_accumulated(self):
        # ARRANGE #

        line_object = s.StringLineObject('the string')
        block_properties = ElementProperties(
            Indentation(2, '<block indent suffix>'),
            TEXT_STYLE__NEUTRAL,
        )
        line_element_properties = ElementProperties(
            Indentation(3, '<line element indent suffix>'),
            TEXT_STYLE__NEUTRAL,
        )

        # ACT & ASSERT #

        check_minor_block(
            self,
            to_render=s.MinorBlock(
                [s.LineElement(line_object, line_element_properties)],
                block_properties,
            ),
            expectation=lines_content([
                ((LAYOUT_SETTINGS.minor_block.indent *
                  block_properties.indentation.level) +
                 block_properties.indentation.suffix +
                 (LAYOUT_SETTINGS.line_element_indent *
                  line_element_properties.indentation.level) +
                 line_element_properties.indentation.suffix +
                 line_object.string)
            ]),
        )
Ejemplo n.º 15
0
 def file_structure(self, root_path: pathlib.Path) -> DirContents:
     return DirContents([
         File('main.suite', lines_content(['[suites]', '?'])),
         File.empty('1'),
         Dir('2', []),
         File.empty('3'),
     ])
    def runTest(self):
        lines = ['1', '2', '3']
        actual_number_of_lines = len(lines)

        integer_matcher = IntegerMatcherSymbolContext.of_primitive(
            'INTEGER_MATCHER',
            matchers.matcher(
                comparators.EQ,
                actual_number_of_lines,
            ))
        integration_check.CHECKER__PARSE_SIMPLE.check(
            self,
            args.NumLines(
                integer_matcher.name__sym_ref_syntax).as_remaining_source,
            model_constructor.of_str(self, lines_content(lines)),
            arrangement_w_tcds(symbols=integer_matcher.symbol_table, ),
            Expectation(
                ParseExpectation(
                    source=asrt_source.is_at_end_of_line(1),
                    symbol_references=integer_matcher.references_assertion,
                ),
                ExecutionExpectation(
                    main_result=asrt_matching_result.matches_value(True)),
            ),
        )
Ejemplo n.º 17
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))
Ejemplo n.º 18
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.º 19
0
    def runTest(self):
        # ARRANGE #
        exit_code_from_program = 0
        exe_file_in_path = fs.python_executable_file(
            'the-program',
            lines_content(py_program.exit_with_code(exit_code_from_program)),
        )
        program_symbol = StringConstantSymbolContext(
            'PROGRAM_NAME_SYMBOL',
            exe_file_in_path.name,
        )
        program_line = args.system_program_command_line(
            program_symbol.name__sym_ref_syntax).as_str

        with tmp_dir_in_path_with_files(DirContents([exe_file_in_path
                                                     ])) as environ:
            for source_case in valid_source_variants(program_line):
                with self.subTest(source_case.name):
                    # ACT & ASSERT #
                    integration_check.check_execution(
                        self,
                        sut.actor(),
                        [instr([program_line])],
                        arrangement_w_tcds(
                            symbol_table=program_symbol.symbol_table,
                            act_exe_input=AtcExeInputArr(environ=environ),
                        ),
                        Expectation(
                            symbol_usages=asrt.matches_singleton_sequence(
                                program_symbol.
                                reference_assertion__string__w_all_indirect_refs_are_strings
                            ),
                            execute=asrt_eh.is_exit_code(
                                exit_code_from_program)),
                    )
Ejemplo n.º 20
0
def tmp_file_containing_lines(content_lines: Sequence[str],
                              suffix: str = '') -> pathlib.Path:
    """
    Short cut to tmp_file_containing combined with giving the contents as a string of lines.
    """
    return tmp_file_containing(lines_content(content_lines),
                               suffix=suffix)
Ejemplo n.º 21
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))))
    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.º 23
0
 def test_escaping_markup_token_inside_literal_block(self):
     check(self,
           [sut.LiteralLayout(lines_content(['```']))],
           sut.parse(['```',
                      '\\```',
                      '```',
                      ]))
Ejemplo n.º 24
0
    def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess):
        expected_content_line_template = 'expected content line, with {symbol} ref'

        def expected_content(symbol_content: str) -> str:
            return expected_content_line_template.format(symbol=symbol_content)

        symbol = StringConstantSymbolContext('symbol_name', 'the symbol value')
        self._check(
            test_configuration.source_for(
                args('{maybe_not} {equals} <<EOF',
                     maybe_not=maybe_not.nothing__if_positive__not_option__if_negative),
                [expected_content(symbol.name__sym_ref_syntax),
                 'EOF',
                 'following line']),
            model_constructor.of_str(self, lines_content([expected_content(symbol.str_value)])),
            arrangement_w_tcds(
                post_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY,
                symbols=symbol.symbol_table),
            Expectation(
                ParseExpectation(
                    source=asrt_source.is_at_end_of_line(3),
                    symbol_references=asrt.matches_sequence([
                        symbol.reference_assertion__w_str_rendering
                    ]),
                ),
                ExecutionExpectation(
                    main_result=maybe_not.pass__if_positive__fail__if_negative,
                ),
            ),
        )
Ejemplo n.º 25
0
 def test_single_literal_block_w_class(self):
     check(self,
           [sut.LiteralLayout(lines_content(['literal line']), 'the-class')],
           sut.parse(['```:the-class',
                      'literal line',
                      '```',
                      ]))
Ejemplo n.º 26
0
 def file_structure_to_read(self) -> DirContents:
     return DirContents([
         File('main.suite',
              lines_content([
                  '"starting but no closing double quote',
              ])),
     ])
Ejemplo n.º 27
0
    def test_symbol_value_with_space_SHOULD_be_given_as_single_argument_to_program(
            self):
        symbol = StringConstantSymbolContext('symbol_name',
                                             'symbol value with space')

        expected_output = lines_content([symbol.str_value])

        executable_file_name = 'the-executable_file_name'

        command_line = '{executable_file_name} {symbol}'.format(
            executable_file_name=executable_file_name,
            symbol=symbol.name__sym_ref_syntax,
        )

        arrangement = arrangement_w_tcds(
            hds_contents=relativity_configurations.ATC_FILE.
            populator_for_relativity_option_root__hds(
                fs.DirContents([
                    fs.python_executable_file(
                        executable_file_name,
                        PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES
                    )
                ])),
            symbol_table=symbol.symbol_table)

        expectation = Expectation(
            symbol_usages=asrt.matches_sequence(
                [symbol.reference_assertion__w_str_rendering]),
            execute=eh_assertions.is_exit_code(0),
            post_sds=PostSdsExpectation.
            constant(sub_process_result_from_execute=pr.stdout(
                asrt.Equals(expected_output, 'CLI arguments, one per line'))),
        )
        check_execution(self, sut.actor(), [instr([command_line])],
                        arrangement, expectation)
Ejemplo n.º 28
0
    def test_cwd__should_be__directory_containing_test_case_during_preprocessing_and_then_restored(
            self):
        test_case_source = 'CURRENT_WORKING_DIRECTORY'
        preprocessor_that_search_replace_current_working_directory = lines_content(
            [
                "import os",
                "print(os.getcwd())",
            ])
        cwd_before = os.getcwd()
        with test_case_and_preprocessor_source(test_case_source,
                                               preprocessor_that_search_replace_current_working_directory) \
                as (test_case_path,
                    preprocessor_file_path):
            pre_proc = PreprocessorViaExternalProgram(
                py_exe.args_for_interpreting(preprocessor_file_path))

            result = pre_proc.apply(test_case_path, test_case_source)

            cwd_after = os.getcwd()
            self.assertEqual(cwd_before, cwd_after,
                             'Current Working Directory should be restored')

            test_case_dir = test_case_path.parent
            expected_test_case_contents = str(test_case_dir) + os.linesep
            self.assertEqual(
                expected_test_case_contents, result,
                """Test case source is expected to be the name of the directory
                             that contains the test case.""")
Ejemplo n.º 29
0
def of_lines(on_separate_lines: Sequence[AbstractSyntax]) -> str:
    layout_spec = LayoutSpec.of_default()

    return misc_formatting.lines_content([
        syntax.tokenization().layout(layout_spec)
        for syntax in on_separate_lines
    ])