Exemplo n.º 1
0
 def test_fail_due_to_fail_of_side_effects_on_instruction_settings(self):
     with self.assertRaises(utils.TestError):
         self._check(
             utils.ParserThatGives(SUCCESSFUL_INSTRUCTION),
             single_line_source(), sut.Arrangement(),
             sut.Expectation(instruction_settings=asrt.not_(
                 asrt.is_instance(InstructionSettings))))
Exemplo n.º 2
0
 def test_fail_due_to_unexpected_result_from_post_validation(self):
     with self.assertRaises(utils.TestError):
         self._check(
             utils.ParserThatGives(SUCCESSFUL_INSTRUCTION),
             single_line_source(), sut.Arrangement(),
             sut.Expectation(
                 post_validation_result=asrt_svh.is_hard_error()))
Exemplo n.º 3
0
 def test_fail_due_to_fail_of_side_effects_on_tcds(self):
     with self.assertRaises(utils.TestError):
         self._check(
             utils.ParserThatGives(SUCCESSFUL_INSTRUCTION),
             single_line_source(), sut.Arrangement(),
             sut.Expectation(
                 main_side_effects_on_tcds=asrt.IsInstance(bool)))
Exemplo n.º 4
0
 def test_fail_due_to_fail_of_side_effects_on_sds(self):
     with self.assertRaises(utils.TestError):
         self._check(
             utils.ParserThatGives(SUCCESSFUL_INSTRUCTION),
             single_line_source(), sut.Arrangement(),
             sut.Expectation(
                 main_side_effects_on_sds=act_dir_contains_exactly(
                     DirContents([File.empty('non-existing-file.txt')]))))
Exemplo n.º 5
0
 def test_failure(self):
     with self.assertRaises(utils.TestError):
         self._check(
             utils.ParserThatGives(setup_phase_instruction_that()),
             single_line_source(),
             sut.Arrangement(
                 settings_builder=SetupSettingsBuilder.new_empty()),
             sut.Expectation(settings_builder=asrt.sub_component(
                 'stdin', lambda model: model.actual.stdin,
                 asrt.is_not_none)),
         )
Exemplo n.º 6
0
 def test_populate_non_hds(self):
     populated_dir_contents = DirContents([File.empty('non-hds-file.txt')])
     self._check(
         PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION,
         single_line_source(),
         sut.Arrangement(non_hds_contents=non_hds_populator.rel_option(
             non_hds_populator.RelNonHdsOptionType.REL_TMP,
             populated_dir_contents)),
         sut.Expectation(
             main_side_effects_on_sds=tmp_user_dir_contains_exactly(
                 populated_dir_contents)),
     )
Exemplo n.º 7
0
 def test_that_default_expectation_assumes_no_symbol_usages(self):
     with self.assertRaises(utils.TestError):
         unexpected_symbol_usages = [
             data_references.reference_to__on_direct_and_indirect(
                 'symbol_name')
         ]
         self._check(
             utils.ParserThatGives(
                 setup_phase_instruction_that(
                     symbol_usages=do_return(unexpected_symbol_usages))),
             single_line_source(),
             sut.Arrangement(),
             sut.Expectation(),
         )
Exemplo n.º 8
0
 def test_that_fails_due_to_missing_symbol_reference(self):
     with self.assertRaises(utils.TestError):
         symbol_usages_of_instruction = []
         self._check(
             utils.ParserThatGives(
                 setup_phase_instruction_that(symbol_usages=do_return(
                     symbol_usages_of_instruction))),
             single_line_source(),
             sut.Arrangement(),
             sut.Expectation(symbol_usages=asrt.matches_singleton_sequence(
                 matches_data_type_symbol_reference(
                     'symbol_name',
                     reference_restrictions.is_any_type_w_str_rendering()))
                             ),
         )
Exemplo n.º 9
0
 def arrangement(self,
                 pre_contents_population_action: TcdsAction = TcdsAction(),
                 hds_contents: hds_populators.HdsPopulator = hds_populators.empty(),
                 sds_contents_before_main: sds_populator.SdsPopulator = sds_populator.empty(),
                 tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(),
                 environ: Optional[Dict[str, str]] = None,
                 default_environ_getter: DefaultEnvironGetter = get_empty_environ,
                 os_services: OsServices = new_for_current_os(),
                 symbols: SymbolTable = None):
     return ic.Arrangement(pre_contents_population_action=pre_contents_population_action,
                           hds_contents=hds_contents,
                           sds_contents_before_main=sds_contents_before_main,
                           tcds_contents=tcds_contents,
                           process_execution_settings=ProcessExecutionSettings.from_non_immutable(environ=environ),
                           default_environ_getter=default_environ_getter,
                           os_services=os_services,
                           symbols=symbols)
Exemplo n.º 10
0
 def test_type_of_objects_given_to_assertion(self):
     self._check(
         PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION,
         single_line_source(),
         sut.Arrangement(),
         sut.Expectation(settings_builder=asrt.is_instance_with(
             SettingsBuilderAssertionModel,
             asrt.and_([
                 asrt.sub_component(
                     'SettingsBuilder', SettingsBuilderAssertionModel.
                     actual.fget, asrt.is_instance(SetupSettingsBuilder)),
                 asrt.sub_component(
                     'environment',
                     SettingsBuilderAssertionModel.environment.fget,
                     asrt.is_instance(
                         InstructionEnvironmentForPostSdsStep)),
             ]))),
     )
Exemplo n.º 11
0
    def test_populate_environ(self):
        default_from_default_getter = {'default': 'value of default'}
        default_environs = {'in_environs': 'value of var in environs'}

        def default_environ_getter() -> Dict[str, str]:
            return default_from_default_getter

        self._check(
            PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION,
            utils.single_line_source(),
            sut.Arrangement(
                default_environ_getter=default_environ_getter,
                process_execution_settings=ProcessExecutionSettings.
                from_non_immutable(environ=default_environs),
            ),
            sut.Expectation(instruction_settings=asrt_instr_settings.matches(
                environ=asrt.equals(default_environs),
                return_value_from_default_getter=asrt.equals(
                    default_from_default_getter)),
                            proc_exe_settings=asrt_pes.matches(
                                environ=asrt.equals(default_environs))),
        )
Exemplo n.º 12
0
    def test_that_symbols_from_arrangement_exist_in_environment(self):
        symbol = StringConstantSymbolContext(
            'symbol_name_in_setup_phase', 'the symbol value in setup phase')
        symbol_table_of_arrangement = symbol.symbol_table
        expected_symbol_table = symbol.symbol_table
        assertion_for_validation = do_fail_if_symbol_table_does_not_equal(
            self, expected_symbol_table,
            get_symbol_table_from_path_resolving_environment_that_is_first_arg)

        assertion_for_main = do_fail_if_symbol_table_does_not_equal(
            self, expected_symbol_table,
            get_symbol_table_from_instruction_environment_that_is_first_arg)

        self._check(
            utils.ParserThatGives(
                setup_phase_instruction_that(
                    validate_pre_sds_initial_action=assertion_for_validation,
                    validate_post_setup_initial_action=assertion_for_validation,
                    main_initial_action=assertion_for_main,
                )),
            utils.single_line_source(),
            sut.Arrangement(symbols=symbol_table_of_arrangement),
            sut.Expectation(),
        )
Exemplo n.º 13
0
 def arrangement_with_timeout(self, timeout_in_seconds: int):
     return ic.Arrangement(
         process_execution_settings=proc_exe_env_for_test(
             timeout_in_seconds=timeout_in_seconds
         )
     )
Exemplo n.º 14
0
 def test_that_cwd_for_main_and_post_validation_is_test_root(self):
     self._check(
         utils.ParserThatGives(
             InstructionThatRaisesTestErrorIfCwdIsIsNotTestRoot()),
         single_line_source(), sut.Arrangement(), sut.Expectation())
Exemplo n.º 15
0
 def test_successful_flow(self):
     self._check(utils.ParserThatGives(SUCCESSFUL_INSTRUCTION),
                 single_line_source(), sut.Arrangement(), sut.Expectation())