示例#1
0
def expectation_that_file_for_actual_contents_is_invalid(
        conf: RelativityOptionConfiguration) -> Expectation:
    if conf.exists_pre_sds:
        return Expectation(
            validation_pre_sds=svh_assertions.is_validation_error(),
            symbol_usages=conf.symbols.usages_expectation(),
        )
    else:
        return Expectation(
            main_result=pfh_assertions.is_hard_error__with_arbitrary_message(),
            symbol_usages=conf.symbols.usages_expectation(),
        )
示例#2
0
 def test_invalid_arguments_with_symbol_references(self):
     symbol_name = SymbolWithReferenceSyntax('symbol_name')
     operand_arg_with_symbol_ref_list = [
         ' {op} {sym}'.format(op=comparators.EQ.name, sym=symbol_name),
     ]
     invalid_symbol_values = [
         'not_a_number',
         '1.5',
         '72 87',
     ]
     for invalid_symbol_value in invalid_symbol_values:
         symbol = StringConstantSymbolContext(symbol_name.name,
                                              invalid_symbol_value)
         for operand_arg_with_symbol_ref in operand_arg_with_symbol_ref_list:
             arguments = self._conf().arguments_constructor.apply(
                 operand_arg_with_symbol_ref)
             with self.subTest(argument=arguments,
                               invalid_symbol_value=invalid_symbol_value):
                 for source in equivalent_source_variants__with_source_check__consume_last_line(
                         self, arguments):
                     self._check(
                         source,
                         ArrangementPostAct(symbols=symbol.symbol_table),
                         Expectation(
                             validation_pre_sds=svh_asrt.
                             is_validation_error(),
                             symbol_usages=asrt.matches_sequence([
                                 symbol.
                                 reference_assertion__string__w_all_indirect_refs_are_strings
                             ]),
                         ),
                     )
    def _check_(
        self,
        instruction_source: ParseSource,
        etc: ExpectationTypeConfigForPfh,
        main_result_for_positive_expectation: PassOrFail,
        rel_opt_config: RelativityOptionConfiguration,
        contents_of_relativity_option_root: DirContents = empty_dir_contents(),
        test_case_name: str = '',
        following_symbols_setup: SymbolsArrEx = SymbolsArrEx.empty()):

        with self.put.subTest(case_name=test_case_name,
                              expectation_type=etc.expectation_type.name,
                              arguments=instruction_source.source_string):
            instruction_check.check(
                self.put, self.parser, instruction_source,
                ArrangementPostAct(
                    pre_contents_population_action=
                    MAKE_CWD_OUTSIDE_OF_EVERY_REL_OPT_DIR,
                    tcds_contents=rel_opt_config.
                    populator_for_relativity_option_root(
                        contents_of_relativity_option_root),
                    symbols=_symbol_table_of(rel_opt_config.symbols,
                                             following_symbols_setup),
                ),
                Expectation(
                    main_result=etc.main_result(
                        main_result_for_positive_expectation),
                    symbol_usages=asrt.matches_sequence(
                        rel_opt_config.symbols.usage_expectation_assertions() +
                        following_symbols_setup.expected_usages_list),
                ))
示例#4
0
    def runTest(self):
        output_from_program = 'first second'
        transformer_of_program = transformers_setup.DELETE_INITIAL_WORD_TRANSFORMER
        transformer_of_instruction = transformers_setup.DUPLICATE_WORDS_TRANSFORMER

        program_that_outputs_something = pgm_args.program(
            pgm_args.interpret_py_source_line(
                self.configuration.py_source_for_print(output_from_program)),
            transformation=transformer_of_program.name)
        result_when_positive = pfh_expectation_type_config(
            ExpectationType.POSITIVE)

        self._check_positive_and_negated(
            result_when_positive,
            program_that_outputs_something,
            matcher_arguments.equals_matcher(
                ab.quoted_string('second second')),
            lambda main_result: Expectation(
                main_result=main_result,
                symbol_usages=asrt.matches_sequence([
                    is_reference_to_string_transformer__usage(
                        transformer_of_program.name),
                    is_reference_to_string_transformer__usage(
                        transformer_of_instruction.name),
                ])),
            arrangement=ArrangementPostAct(
                symbols=transformers_setup.SYMBOL_TABLE),
            transformation=transformer_of_instruction.name)
 def test_fail_due_to_unexpected_result_from_pre_validation(self):
     with self.assertRaises(utils.TestError):
         self._check(
             utils.ParserThatGives(_SUCCESSFUL_INSTRUCTION),
             utils.single_line_source(),
             sut.ArrangementPostAct(),
             Expectation(validation_pre_sds=svh_assertions.is_hard_error()),
         )
示例#6
0
 def expectation(self) -> Expectation:
     return Expectation(
         symbol_usages=asrt.matches_singleton_sequence(
             is_reference_to_files_matcher__usage(
                 self.name_of_referenced_symbol)),
         main_result=asrt_pfh.is_hard_error(
             is_string_for_test_that_equals(self.error_message)),
     )
 def test_fail_due_to_fail_of_side_effects_on_instruction_settings(self):
     with self.assertRaises(utils.TestError):
         self._check(
             utils.ParserThatGives(_SUCCESSFUL_INSTRUCTION),
             utils.single_line_source(),
             sut.ArrangementPostAct(),
             Expectation(instruction_settings=asrt.not_(
                 asrt.is_instance(InstructionSettings))),
         )
 def test_fail_due_to_unexpected_result_from_main(self):
     with self.assertRaises(utils.TestError):
         self._check(
             utils.ParserThatGives(_SUCCESSFUL_INSTRUCTION),
             utils.single_line_source(),
             sut.ArrangementPostAct(),
             Expectation(main_result=pfh_assertions.
                         is_fail__with_arbitrary_message()),
         )
 def test_fail_due_to_fail_of_side_effects_on_sds(self):
     with self.assertRaises(utils.TestError):
         self._check(
             utils.ParserThatGives(_SUCCESSFUL_INSTRUCTION),
             utils.single_line_source(),
             sut.ArrangementPostAct(),
             Expectation(main_side_effects_on_sds=act_dir_contains_exactly(
                 DirContents([File.empty('non-existing-file.txt')]))),
         )
示例#10
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 Expectation(
         main_result=pfh_assertions.is_hard_error(error_message),
         symbol_usages=symbol_usages,
     )
示例#11
0
 def expect_hard_error_of_main__any(
     self,
     symbol_usages: Assertion[
         Sequence[SymbolUsage]] = asrt.is_empty_sequence,
 ):
     return Expectation(
         main_result=pfh_assertions.is_hard_error(
             asrt_text_doc.is_any_text()),
         symbol_usages=symbol_usages,
     )
 def expect_failing_validation_post_setup(
     self,
     assertion_on_error_message: Assertion[str] = asrt.anything_goes(),
     symbol_usages: Assertion[
         Sequence[SymbolUsage]] = asrt.is_empty_sequence,
 ):
     return Expectation(
         main_result=pfh_assertions.is_hard_error(
             asrt_text_doc.is_string_for_test(assertion_on_error_message)),
         symbol_usages=symbol_usages,
     )
示例#13
0
    def runTest(self):
        program_that_outputs_nothing = pgm_args.program(
            pgm_args.interpret_py_source_line(
                self.configuration.py_source_for_print('')))
        result_when_positive = pfh_expectation_type_config(
            ExpectationType.POSITIVE)

        self._check_positive_and_negated(
            result_when_positive, program_that_outputs_nothing,
            matcher_arguments.emptiness_matcher(),
            lambda main_result: Expectation(main_result=main_result))
示例#14
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 Expectation(
         main_result=pfh_assertions.is_fail(assertion_on_error_message),
         symbol_usages=symbol_usages,
     )
示例#15
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 Expectation(
         validation_pre_sds=svh_assertions.is_validation_error(
             error_message),
         symbol_usages=symbol_usages,
     )
    def runTest(self):
        # ARRANGE #

        program_with_ref_to_file_in_hds_ds = pgm_args.program(
            pgm_args.interpret_py_source_file(path_arguments.RelOptPathArgument('non-existing-file',
                                                                                RelOptionType.REL_HDS_CASE))
        )
        arguments = po_ab.from_program(program_with_ref_to_file_in_hds_ds,
                                       matcher_arguments.emptiness_matcher())

        # ACT & ASSERT #

        self._check(arguments,
                    ArrangementPostAct(),
                    Expectation(validation_pre_sds=asrt_svh.is_validation_error()))
    def runTest(self):
        # ARRANGE #

        program_with_ref_to_file_in_hds_ds = pgm_args.program(
            pgm_args.interpret_py_source_file(path_arguments.RelOptPathArgument('non-existing-file',
                                                                                RelOptionType.REL_ACT))
        )
        arguments = po_ab.from_program(program_with_ref_to_file_in_hds_ds,
                                       matcher_arguments.emptiness_matcher())

        # ACT & ASSERT #

        self._check(arguments,
                    ArrangementPostAct(),
                    Expectation(
                        main_result=asrt_pfh.is_hard_error__with_arbitrary_message())
                    )
示例#18
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 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,
     )
示例#19
0
    def runTest(self):
        program_that_outputs_something = pgm_args.program(
            pgm_args.interpret_py_source_line(
                self.configuration.py_source_for_print('some output')),
            transformation=transformers_setup.DELETE_EVERYTHING_TRANSFORMER.
            name)
        result_when_positive = pfh_expectation_type_config(
            ExpectationType.POSITIVE)

        self._check_positive_and_negated(
            result_when_positive, program_that_outputs_something,
            matcher_arguments.emptiness_matcher(),
            lambda main_result: Expectation(
                main_result=main_result,
                symbol_usages=asrt.matches_sequence([
                    is_reference_to_string_transformer__usage(
                        transformers_setup.DELETE_EVERYTHING_TRANSFORMER.name),
                ])),
            ArrangementPostAct(symbols=transformers_setup.SYMBOL_TABLE))
示例#20
0
 def test_invalid_arguments_without_symbol_references(self):
     test_cases = [
         ' {op} a'.format(op=comparators.EQ.name),
         '{op} 1.5'.format(op=comparators.GT.name),
     ]
     for condition_str in test_cases:
         with self.subTest(msg=condition_str):
             instr_arg = self._conf().arguments_constructor.apply(
                 condition_str)
             for source in equivalent_source_variants__with_source_check__consume_last_line(
                     self, instr_arg):
                 self._check(
                     source,
                     ArrangementPostAct(),
                     Expectation(
                         validation_pre_sds=svh_asrt.is_validation_error(),
                         symbol_usages=asrt.is_empty_sequence,
                     ),
                 )
    def check_rel_opt_variants_with_same_result_for_every_expectation_type(
        self,
        make_instruction_arguments: InstructionArgumentsVariantConstructor,
        main_result: Assertion,
        contents_of_relativity_option_root: DirContents = empty_dir_contents(),
        following_symbols_setup: SymbolsArrEx = SymbolsArrEx.empty()):

        for rel_opt_config in self.accepted_rel_opt_configurations:

            for expectation_type_of_test_case in ExpectationType:
                etc = pfh_expectation_type_config(
                    expectation_type_of_test_case)
                instruction_arguments = make_instruction_arguments.apply(
                    etc, rel_opt_config)
                instruction_source = remaining_source(instruction_arguments)

                with self.put.subTest(
                        expectation_type=etc.expectation_type.name,
                        arguments=instruction_arguments):
                    instruction_check.check(
                        self.put, self.parser, instruction_source,
                        ArrangementPostAct(
                            pre_contents_population_action=
                            MAKE_CWD_OUTSIDE_OF_EVERY_REL_OPT_DIR,
                            tcds_contents=rel_opt_config.
                            populator_for_relativity_option_root(
                                contents_of_relativity_option_root),
                            symbols=_symbol_table_of(rel_opt_config.symbols,
                                                     following_symbols_setup),
                        ),
                        Expectation(
                            main_result=main_result,
                            symbol_usages=asrt.matches_sequence(
                                rel_opt_config.symbols.
                                usage_expectation_assertions() +
                                following_symbols_setup.expected_usages_list)))
 def expectation_for_zero_exitcode(self) -> Expectation:
     return Expectation(main_result=pfh_assertions.is_pass())
 def expect_hard_error_in_main(self) -> Expectation:
     return Expectation(
         main_result=pfh_assertions.is_hard_error__with_arbitrary_message())
示例#24
0
 def expect_successful_execution_with_side_effect(
         self,
         side_effects_check: Assertion,
         symbol_usages: Assertion = asrt.is_empty_sequence):
     return Expectation(main_side_effects_on_tcds=side_effects_check,
                        symbol_usages=symbol_usages)
 def test_fail_due_to_unexpected_source_after_parse(self):
     with self.assertRaises(utils.TestError):
         self._check(
             utils.ParserThatGives(_SUCCESSFUL_INSTRUCTION),
             utils.single_line_source(), sut.ArrangementPostAct(),
             Expectation(source=asrt_source.is_at_beginning_of_line(10), ))
示例#26
0
文件: run.py 项目: emilkarlen/exactly
 def expect_failure_because_specified_file_under_sds_is_missing(
         self,
         symbol_usages: Assertion[Sequence[SymbolUsage]] = asrt.is_empty_sequence,
 ):
     return Expectation(main_result=asrt_pfh.is_hard_error(),
                        symbol_usages=symbol_usages)
示例#27
0
 def expectation_for_zero_exitcode(self) -> Expectation:
     return Expectation()
示例#28
0
 def expectation_for_non_zero_exitcode(self) -> Expectation:
     return Expectation(
         main_result=pfh_assertions.is_fail__with_arbitrary_message())
示例#29
0
 def expect_target_is_not_a_directory(self):
     return Expectation(
         main_result=pfh_assertions.is_hard_error__with_arbitrary_message())
示例#30
0
 def expect_failure_to_create_dir(
         self, symbol_usages: Assertion = asrt.is_empty_sequence):
     return Expectation(
         main_result=asrt_pfh.is_hard_error__with_arbitrary_message(),
         symbol_usages=symbol_usages)