예제 #1
0
 def test_single_file_in_root_dir(self):
     # ARRANGE #
     expected_file = File.empty('file-name.txt')
     for phase_is_after_act in [False, True]:
         checker = integration_check.checker(phase_is_after_act)
         for rel_opt_conf in ALLOWED_DST_FILE_RELATIVITIES:
             with self.subTest(
                     relativity_option_string=rel_opt_conf.option_argument,
                     phase_is_after_act=phase_is_after_act):
                 instruction_syntax = abs_stx.without_contents(
                     rel_opt_conf.path_abs_stx_of_name(expected_file.name))
                 # ACT & ASSERT #
                 checker.check__abs_stx__std_layouts_and_source_variants(
                     self, instruction_syntax,
                     Arrangement.phase_agnostic(tcds=TcdsArrangement(
                         pre_population_action=
                         SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, ),
                                                ),
                     MultiSourceExpectation.phase_agnostic(
                         main_result=IS_SUCCESS,
                         side_effects_on_hds=f_asrt.dir_is_empty(),
                         symbol_usages=asrt.is_empty_sequence,
                         main_side_effects_on_sds=
                         non_hds_dir_contains_exactly(
                             rel_opt_conf.root_dir__non_hds,
                             fs.DirContents([expected_file])),
                     ))
예제 #2
0
 def test_contents_from_here_doc(self):
     # ARRANGE #
     string_value = rich_str_abs_stx.HereDocAbsStx(
         'single line in here doc\n')
     expected_file = fs.File('a-file-name.txt', string_value.value)
     rel_opt_conf = ARBITRARY_ALLOWED_DST_FILE_RELATIVITY
     dst_path = rel_opt_conf.path_abs_stx_of_name(expected_file.name)
     instruction_syntax = instr_abs_stx.create_w_explicit_contents(
         dst_path,
         string_source_abs_stx.StringSourceOfStringAbsStx(string_value),
     )
     for phase_is_after_act in [False, True]:
         checker = integration_check.checker(phase_is_after_act)
         with self.subTest(phase_is_after_act=phase_is_after_act):
             # ACT & ASSERT #
             checker.check__abs_stx__std_layouts_and_source_variants(
                 self, instruction_syntax,
                 Arrangement.phase_agnostic(tcds=TcdsArrangement(
                     pre_population_action=
                     SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, ), ),
                 MultiSourceExpectation.phase_agnostic(
                     main_result=IS_SUCCESS,
                     side_effects_on_hds=f_asrt.dir_is_empty(),
                     symbol_usages=asrt.is_empty_sequence,
                     main_side_effects_on_sds=non_hds_dir_contains_exactly(
                         rel_opt_conf.root_dir__non_hds,
                         fs.DirContents([expected_file])),
                 ))
예제 #3
0
    def runTest(self):
        text_printed_by_program = 'single line of output'

        expected_file_contents = text_printed_by_program.upper()
        expected_file = fs.File('dst-file.txt', expected_file_contents)

        to_upper_transformer = StringTransformerSymbolContext.of_primitive(
            'TO_UPPER_CASE',
            to_uppercase(),
        )
        symbols = to_upper_transformer.symbol_table

        dst_rel_opt_conf = conf_rel_non_hds(RelNonHdsOptionType.REL_TMP)

        program_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)),
                transformation=to_upper_transformer.abstract_syntax,
            ))
        instruction_syntax = instr_abs_stx.create_w_explicit_contents(
            dst_rel_opt_conf.path_abs_stx_of_name(expected_file.name),
            program_syntax,
        )

        instruction_checker = self.conf.instruction_checker
        parser = self.conf.parser()
        for source_case in equivalent_source_variants__with_source_check__consume_last_line__abs_stx(
                instruction_syntax):
            with self.subTest(source_case.name):
                source = source_case.value.source
                # ACT #
                instruction = parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
                # ASSERT #
                source_case.value.expectation.apply_with_message(
                    self, source, 'source-after-parse')
                # ACT & ASSERT #
                instruction_checker.check(
                    self, instruction,
                    self.conf.arrangement(
                        pre_contents_population_action=
                        SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR,
                        symbols=symbols),
                    self.conf.expect_success(
                        symbol_usages=asrt.matches_sequence([
                            to_upper_transformer.reference_assertion,
                        ]),
                        main_side_effects_on_sds=non_hds_dir_contains_exactly(
                            dst_rel_opt_conf.root_dir__non_hds,
                            fs.DirContents([expected_file])),
                    ))
예제 #4
0
    def runTest(self):
        # ARRANGE #
        dst_file_name = 'dst-file_name-file.txt'
        src_file = File('src-file_name-file.txt', 'contents')
        home_dir_contents = DirContents([src_file])
        expected_destination_dir_contents = DirContents([File(dst_file_name, src_file.contents)])

        dst_rel_option = rel_opt_conf.symbol_conf_rel_non_hds(
            defs.ARBITRARY_LEGAL_RELATIVITY__DST__NON_HDS,
            'DST_SYMBOL',
            defs.PATH_RELATIVITY_VARIANTS__DST,
        )
        for phase_is_after_act in [False, True]:
            with self.subTest(phase_is_after_act=phase_is_after_act):
                checker = instruction_embryo_check.Checker(sut.EmbryoParser(phase_is_after_act))
                src_rel_option = rel_opt_conf.symbol_conf_rel_hds(
                    defs.ARBITRARY_LEGAL_RELATIVITY__SRC__HDS,
                    'SRC_SYMBOL',
                    defs.path_relativity_variants__src(phase_is_after_act),
                )
                # ACT & ASSERT #
                checker.check(
                    self,
                    args.copy(src_rel_option.path_argument_of_rel_name(src_file.name),
                              dst_rel_option.path_argument_of_rel_name(dst_file_name)
                              ).as_remaining_source,
                    Arrangement.phase_agnostic(
                        tcds=TcdsArrangement(
                            hds_contents=src_rel_option.populator_for_relativity_option_root__hds(home_dir_contents),
                        ),
                        symbols=SymbolContext.symbol_table_of_contexts(
                            src_rel_option.symbols.contexts_for_arrangement() +
                            dst_rel_option.symbols.contexts_for_arrangement()
                        )
                    ),
                    Expectation.phase_agnostic_2(
                        symbol_usages=asrt.matches_sequence(
                            src_rel_option.symbols.usage_expectation_assertions() +
                            dst_rel_option.symbols.usage_expectation_assertions()
                        ),
                        main_side_effects_on_sds=sds_contents_check.non_hds_dir_contains_exactly(
                            dst_rel_option.root_dir__non_hds,
                            expected_destination_dir_contents),

                    ),
                )
예제 #5
0
 def _sub_test__copy_file(
         self,
         src_rel_option: rel_opt_conf.RelativityOptionConfigurationRelHds,
         dst_rel_option: rel_opt_conf.RelativityOptionConfigurationForRelNonHds,
         src_file_name: str,
         dst_file_name: str,
         expected_destination_dir_contents: DirContents,
         sds_populator_before_main: sds_populator.SdsPopulator,
         hds_contents: hds_populators.HdsPopulator = hds_populators.empty(),
 ):
     arguments = args.copy(src_rel_option.path_argument_of_rel_name(src_file_name),
                           dst_rel_option.path_argument_of_rel_name(dst_file_name))
     for parser_case in _EXECUTION_CHECKERS:
         with self.subTest(parser=parser_case.name,
                           arguments=arguments.as_str):
             symbols_in_arrangement = SymbolContext.symbol_table_of_contexts(
                 src_rel_option.symbols.contexts_for_arrangement() +
                 dst_rel_option.symbols.contexts_for_arrangement()
             )
             expected_symbol_usages = asrt.matches_sequence(
                 src_rel_option.symbols.usage_expectation_assertions() +
                 dst_rel_option.symbols.usage_expectation_assertions()
             )
             parser_case.value.check__w_source_variants(
                 self,
                 arguments.as_str,
                 Arrangement.phase_agnostic(
                     tcds=TcdsArrangement(
                         pre_population_action=MAKE_SUB_DIR_OF_SDS_CURRENT_DIRECTORY,
                         hds_contents=hds_contents,
                         sds_contents=sds_populator_before_main,
                     ),
                     symbols=symbols_in_arrangement,
                 ),
                 MultiSourceExpectation.phase_agnostic(
                     symbol_usages=expected_symbol_usages,
                     main_result=asrt.is_none,
                     main_side_effects_on_sds=sds_contents_check.non_hds_dir_contains_exactly(
                         dst_rel_option.root_dir__non_hds,
                         expected_destination_dir_contents),
                 ),
             )
예제 #6
0
 def assert_root_dir_contains_exactly(
         self, contents: DirContents) -> Assertion[SandboxDs]:
     return sds_contents_check.non_hds_dir_contains_exactly(
         self.root_dir__non_hds, contents)
예제 #7
0
    def runTest(self):
        non_zero_exit_code = 1
        text_printed_by_program = 'the output from the program'

        py_file = File(
            'exit-with-hard-coded-exit-code.py',
            py_programs.py_pgm_with_stdout_stderr_exit_code(
                stdout_output=text_printed_by_program,
                stderr_output='',
                exit_code=non_zero_exit_code,
            ),
        )

        expected_file = fs.File(
            'dst-file.txt',
            text_printed_by_program.upper(),
        )

        to_upper_transformer = StringTransformerSymbolContext.of_primitive(
            'TO_UPPER_CASE',
            to_uppercase(),
        )
        symbols = to_upper_transformer.symbol_table

        py_src_file_rel_opt_conf = rel_opt.conf_rel_any(
            RelOptionType.REL_HDS_CASE)
        dst_file_rel_opt_conf = conf_rel_non_hds(RelNonHdsOptionType.REL_TMP)

        program_string_source_syntax = string_source_abs_stx.StringSourceOfProgramAbsStx(
            ProcOutputFile.STDOUT,
            program_abs_stx.FullProgramAbsStx(
                program_abs_stx.ProgramOfPythonInterpreterAbsStx.
                of_execute_python_src_file(
                    py_src_file_rel_opt_conf.path_abs_stx_of_name(
                        py_file.name)),
                transformation=to_upper_transformer.abstract_syntax,
            ),
            ignore_exit_code=True,
        )
        instruction_syntax = instr_abs_stx.create_w_explicit_contents(
            dst_file_rel_opt_conf.path_abs_stx_of_name(expected_file.name),
            program_string_source_syntax,
        )

        instruction_checker = self.conf.instruction_checker
        parser = self.conf.parser()
        for source_case in equivalent_source_variants__with_source_check__consume_last_line__abs_stx(
                instruction_syntax):
            with self.subTest(source_case.name):
                source = source_case.value.source
                # ACT #
                instruction = parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
                # ASSERT #
                source_case.value.expectation.apply_with_message(
                    self, source, 'source-after-parse')
                # ACT & ASSERT #
                instruction_checker.check(
                    self, instruction,
                    self.conf.arrangement(
                        pre_contents_population_action=
                        SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR,
                        symbols=symbols,
                        tcds_contents=py_src_file_rel_opt_conf.
                        populator_for_relativity_option_root(
                            DirContents([py_file]))),
                    self.conf.expect_success(
                        symbol_usages=asrt.matches_sequence([
                            to_upper_transformer.reference_assertion,
                        ]),
                        main_side_effects_on_sds=non_hds_dir_contains_exactly(
                            dst_file_rel_opt_conf.root_dir__non_hds,
                            fs.DirContents([expected_file])),
                    ))
예제 #8
0
    def _test(self,
              text_printed_by_program: str,
              expected_file_contents: str,
              make_arguments: Callable[[TransformableProgramAbsStxBuilder], ProgramAbsStx],
              additional_symbols: Dict[str, SymbolContainer],
              additional_symbol_references: List[Assertion[SymbolReference]],
              ):
        expected_file = fs.File('a-file-name.txt', expected_file_contents)

        for proc_output_file in ProcOutputFile:
            python_source = py_programs.single_line_pgm_that_prints_to(proc_output_file,
                                                                       text_printed_by_program)

            program_that_executes_py_source_symbol = ProgramSymbolContext.of_sdv(
                'PROGRAM_THAT_EXECUTES_PY_SOURCE',
                program_sdvs.for_py_source_on_command_line(python_source)
            )

            program_cases = [
                ProgramCase(
                    'python interpreter',
                    program_abs_stx.ProgramOfPythonInterpreterAbsStx.of_execute_python_src_string(python_source),
                    []
                ),
                ProgramCase(
                    'symbol reference program',
                    ProgramOfSymbolReferenceAbsStx(program_that_executes_py_source_symbol.name),
                    [program_that_executes_py_source_symbol.reference_assertion],
                ),
            ]

            symbols_dict = {
                program_that_executes_py_source_symbol.name:
                    program_that_executes_py_source_symbol.symbol_table_container,
            }
            symbols_dict.update(additional_symbols)
            symbols = SymbolTable(symbols_dict)

            for program_case in program_cases:
                program_syntax_builder = TransformableProgramAbsStxBuilder(program_case.source)
                program_syntax = make_arguments(program_syntax_builder)

                rel_opt_conf = ARBITRARY_ALLOWED_DST_FILE_RELATIVITY

                expected_symbol_references = program_case.expected_references + additional_symbol_references

                instruction_syntax = instr_abs_stx.create_w_explicit_contents(
                    rel_opt_conf.path_abs_stx_of_name(expected_file.name),
                    string_source_abs_stx.StringSourceOfProgramAbsStx(proc_output_file, program_syntax,
                                                                      ignore_exit_code=False)
                )

                with self.subTest(relativity_option_string=str(rel_opt_conf.option_argument),
                                  program=program_case.name,
                                  output_channel=proc_output_file):
                    integration_check.CHECKER__BEFORE_ACT.check__abs_stx__layout_and_source_variants(
                        self,
                        instruction_syntax,
                        Arrangement.phase_agnostic(
                            symbols=symbols,
                            tcds=TcdsArrangement(),
                        ),
                        MultiSourceExpectation.phase_agnostic(
                            main_result=IS_SUCCESS,
                            side_effects_on_hds=f_asrt.dir_is_empty(),
                            symbol_usages=asrt.matches_sequence(expected_symbol_references),
                            main_side_effects_on_sds=non_hds_dir_contains_exactly(rel_opt_conf.root_dir__non_hds,
                                                                                  fs.DirContents([expected_file])),
                        )
                    )