Пример #1
0
    def test_that_symbols_from_arrangement_exist_in_environment(self):
        symbol = StringConstantSymbolContext('symbol_name', 'the symbol value')
        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(
                before_assert_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(),
        )
Пример #2
0
 def test_fail_due_to_unexpected_result__from_main(self):
     with self.assertRaises(utils.TestError):
         self._check(
             PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION,
             single_line_source(),
             sut.arrangement(),
             sut.Expectation(main_result=sh_assertions.is_hard_error()),
         )
Пример #3
0
 def test_fail_due_to_fail_of_side_effects_on_tcds(self):
     with self.assertRaises(utils.TestError):
         self._check(
             PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION,
             single_line_source(),
             sut.arrangement(),
             sut.Expectation(
                 main_side_effects_on_tcds=asrt.IsInstance(bool)),
         )
Пример #4
0
 def test_fail_due_to_fail_of_side_effects_on_instruction_settings(self):
     with self.assertRaises(utils.TestError):
         self._check(
             PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION,
             single_line_source(),
             sut.arrangement(),
             sut.Expectation(
                 instruction_settings=asrt.not_(asrt.is_instance(InstructionSettings)),
             ),
         )
Пример #5
0
 def expect_failing_validation_post_setup(
     self,
     error_message: Assertion[TextRenderer] = asrt_text_doc.is_any_text(),
     symbol_usages: Assertion[
         Sequence[SymbolUsage]] = asrt.is_empty_sequence,
 ):
     return ic.Expectation(
         main_result=asrt_sh.is_hard_error(error_message),
         symbol_usages=symbol_usages,
     )
Пример #6
0
 def expect_failing_validation_pre_sds(
     self,
     error_message: Assertion[TextRenderer] = asrt_text_doc.is_any_text(),
     symbol_usages: Assertion[
         Sequence[SymbolUsage]] = asrt.is_empty_sequence,
 ):
     return ic.Expectation(
         symbol_usages=symbol_usages,
         validation_pre_sds=svh_assertions.is_validation_error(
             error_message))
Пример #7
0
 def expect_failure_of_main(
     self,
     assertion_on_error_message: Assertion[TextRenderer] = asrt_text_doc.
     is_any_text(),
     symbol_usages: Assertion[
         Sequence[SymbolUsage]] = asrt.is_empty_sequence,
 ):
     return ic.Expectation(
         symbol_usages=symbol_usages,
         main_result=asrt_sh.is_hard_error(assertion_on_error_message))
Пример #8
0
 def test_fail_due_to_fail_of_side_effects_on_sds(self):
     with self.assertRaises(utils.TestError):
         self._check(
             PARSER_THAT_GIVES_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')]))
             ),
         )
Пример #9
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(
                 before_assert_phase_instruction_that(
                     symbol_usages=do_return(unexpected_symbol_usages))),
             single_line_source(),
             sut.arrangement(),
             sut.Expectation(),
         )
Пример #10
0
 def test_populate_sds(self):
     populated_dir_contents = DirContents([File.empty('sds-file.txt')])
     self._check(
         PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION,
         utils.single_line_source(),
         sut.arrangement(
             sds_contents_before_main=sds_populator.contents_in(
                 sds_populator.RelSdsOptionType.REL_TMP,
                 populated_dir_contents)),
         sut.Expectation(
             main_side_effects_on_sds=tmp_user_dir_contains_exactly(
                 populated_dir_contents)),
     )
Пример #11
0
 def test_that_fails_due_to_missing_symbol_reference(self):
     with self.assertRaises(utils.TestError):
         symbol_usages_of_instruction = []
         self._check(
             utils.ParserThatGives(
                 before_assert_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()
                     )
                 )),
         )
Пример #12
0
 def expect_success(
     self,
     main_side_effects_on_sds: Assertion = asrt.anything_goes(),
     symbol_usages: Assertion = asrt.is_empty_sequence,
     source: Assertion[ParseSource] = asrt.anything_goes(),
     proc_exe_settings: Assertion[ProcessExecutionSettings] = asrt.
     is_instance(ProcessExecutionSettings),
     instruction_settings: Assertion[InstructionSettings] = asrt.
     is_instance(InstructionSettings),
 ):
     return ic.Expectation(
         source=source,
         symbol_usages=symbol_usages,
         main_side_effects_on_sds=main_side_effects_on_sds,
         proc_exe_settings=proc_exe_settings,
         instruction_settings=instruction_settings,
     )
Пример #13
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)
                )
            ),
        )