Ejemplo n.º 1
0
    def test_stdin_is_devnull_WHEN_program_do_not_define_stdin(self):
        # ARRANGE #
        test_setup = NoStdinTestSetup(self, exit_code=0)

        for output_file in ProcOutputFile:
            for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference(
            ):
                for ignore_exit_code in [False, True]:
                    with self.subTest(output_file=output_file,
                                      program=pgm_and_args_case.name,
                                      ignore_exit_code=ignore_exit_code):
                        # ACT & ASSERT #
                        CHECKER.check__abs_stx__wo_input(
                            self,
                            StringSourceOfProgramAbsStx(
                                output_file,
                                pgm_and_args_case.pgm_and_args,
                                ignore_exit_code,
                            ),
                            arrangement_w_tcds(
                                symbols=pgm_and_args_case.symbol_table,
                                process_execution=test_setup.
                                proc_exe_env__w_stdin_check,
                                tcds_contents=pgm_and_args_case.tcds,
                            ),
                            Expectation.of_prim__const(
                                parse=ParseExpectation(
                                    symbol_references=pgm_and_args_case.
                                    references_assertion, ),
                                primitive=IS_EMPTY_STRING_SOURCE,
                            ))
Ejemplo n.º 2
0
 def runTest(self):
     # ARRANGE #
     model_contents = 'the contents of stdin of program'
     stdin_string_source_syntax = string_source_abs_stx.StringSourceOfStringAbsStx.of_str_hard(
         model_contents, )
     for output_file in ProcOutputFile:
         for ignore_exit_code in [False, True]:
             with self.subTest(output_file=output_file,
                               ignore_exit_code=ignore_exit_code):
                 test_setup = StdinCheckViaCopyToOutputFileTestSetup(
                     output_file)
                 # ACT & ASSERT #
                 CHECKER.check__abs_stx__wo_input(
                     self,
                     StringSourceOfProgramAbsStx(
                         output_file,
                         FullProgramAbsStx(
                             test_setup.program_that_copies_stdin_syntax(),
                             stdin=stdin_string_source_syntax),
                         ignore_exit_code,
                     ),
                     arrangement_w_tcds(
                         symbols=SymbolContext.symbol_table_of_contexts(
                             test_setup.symbols), ),
                     Expectation.of_prim__const(
                         parse=ParseExpectation(
                             symbol_references=SymbolContext.
                             references_assertion_of_contexts(
                                 test_setup.symbols)),
                         primitive=asrt_string_source.
                         pre_post_freeze__identical(
                             asrt_contents.matches__str(
                                 asrt.equals(model_contents))),
                     ),
                 )
Ejemplo n.º 3
0
    def _test_symbol_reference_in_contents(
            self, symbol_ref_syntax_2_contents_arguments: Callable[
                [str], StringSourceAbsStx],
            symbol_value_2_expected_contents: Callable[[str], str]):
        contents_symbol = StringConstantSymbolContext(
            'contents_symbol_name',
            'contents symbol value',
            default_restrictions=asrt_rest.is__w_str_rendering(),
        )

        expected_contents = symbol_value_2_expected_contents(
            contents_symbol.str_value)

        symbols = [contents_symbol]
        expected_symbol_references = SymbolContext.references_assertion_of_contexts(
            symbols)
        symbol_table = SymbolContext.symbol_table_of_contexts(symbols)

        string_source_syntax = symbol_ref_syntax_2_contents_arguments(
            symbol_reference_syntax_for_name(contents_symbol.name))

        CHECKER.check__abs_stx(
            self, string_source_syntax, None,
            arrangement_w_tcds(symbols=symbol_table, ),
            Expectation.of_prim__const(
                primitive=asrt_string_source.
                pre_post_freeze__matches_str__const(
                    expected_contents, may_depend_on_external_resources=False),
                parse=ParseExpectation(
                    symbol_references=expected_symbol_references, ),
            ))
Ejemplo n.º 4
0
 def test_string_symbol(self):
     contents_symbol = StringSourceSymbolContextOfPrimitiveConstant(
         'contents_symbol_name',
         'symbol value contents',
     )
     CHECKER.check__abs_stx(
         self,
         OptionallyOnNewLine(
             WithinParensAbsStx(contents_symbol.abstract_syntax)), None,
         arrangement_w_tcds(symbols=contents_symbol.symbol_table, ),
         Expectation.of_prim__const(
             primitive=asrt_string_source.
             pre_post_freeze__matches_str__const(
                 contents_symbol.contents_str,
                 may_depend_on_external_resources=False),
             parse=ParseExpectation(
                 symbol_references=contents_symbol.references_assertion, ),
         ))
Ejemplo n.º 5
0
    def test_just_symbol_reference(self):
        contents_symbol = StringConstantSymbolContext(
            'contents_symbol_name',
            'symbol value contents',
            default_restrictions=asrt_rest.is__w_str_rendering(),
        )

        string_source_syntax = StringSourceOfStringAbsStx.of_plain(
            str_abs_stx.StringSymbolAbsStx(contents_symbol.name))

        CHECKER.check__abs_stx(
            self, string_source_syntax, None,
            arrangement_w_tcds(symbols=contents_symbol.symbol_table, ),
            Expectation.of_prim__const(
                primitive=asrt_string_source.
                pre_post_freeze__matches_str__const(
                    contents_symbol.str_value,
                    may_depend_on_external_resources=False),
                parse=ParseExpectation(
                    symbol_references=asrt.matches_singleton_sequence(
                        references.is_reference_to__string_source_or_string(
                            contents_symbol.name)), ),
            ))
Ejemplo n.º 6
0
    def test_string_transformer_should_be_parsed_as_simple_expression(self):
        # ARRANGE #
        the_layout = LayoutSpec.of_default()

        src_rel_opt_conf = conf_rel_any(RelOptionType.REL_TMP)

        src_file = fs.File('source-file.txt', 'contents of source file')
        expected_contents = src_file.contents.upper()

        to_upper_transformer = StringTransformerSymbolContext.of_primitive(
            'TRANSFORMER_SYMBOL',
            string_transformers.to_uppercase(),
        )

        str_trans__unused = StringTransformerSymbolReferenceAbsStx('UNUSED_TRANSFORMER')
        transformation_w_infix_op = str_trans_abs_stx.StringTransformerCompositionAbsStx(
            [
                to_upper_transformer.abstract_syntax,
                str_trans__unused,
            ],
            within_parens=False,
            allow_elements_on_separate_lines=False,
        )
        expected_remaining_tokens = TokenSequence.concat([
            TokenSequence.singleton(str_trans_abs_stx.names.SEQUENCE_OPERATOR_NAME),
            str_trans__unused.tokenization(),
        ])
        expected_remaining_source = expected_remaining_tokens.layout(the_layout)

        file_contents_syntax = string_source_abs_stx.TransformedStringSourceAbsStx(
            string_source_abs_stx.StringSourceOfFileAbsStx(
                src_rel_opt_conf.path_abs_stx_of_name(src_file.name)
            ),
            transformation_w_infix_op
        )
        checker = integration_check.checker(parse_check.rel_opts_conf_of_single(src_rel_opt_conf.relativity))
        # ACT & ASSERT #
        checker.check__abs_stx(
            self,
            file_contents_syntax,
            None,
            arrangement_w_tcds(
                tcds_contents=src_rel_opt_conf.populator_for_relativity_option_root(
                    fs.DirContents([src_file])
                ),
                symbols=to_upper_transformer.symbol_table
            ),
            Expectation.of_prim__const(
                parse=ParseExpectation(
                    source=asrt_source.source_is_not_at_end(
                        remaining_source=asrt.equals(expected_remaining_source)
                    ),
                    symbol_references=to_upper_transformer.references_assertion,
                ),
                primitive=asrt_string_source.pre_post_freeze__matches_str__const(
                    expected_contents,
                    may_depend_on_external_resources=True,
                )
            ),
            the_layout
        )