示例#1
0
    def test_matches(self):
        accessor_error = sut.AccessorError(
            sut.AccessErrorType.PRE_PROCESS_ERROR,
            self._ERROR_INFO_WITH_DESCRIPTION)

        cases = [
            NEA(
                'default',
                actual=accessor_error,
                expected=sut.accessor_error_matches(),
            ),
            NEA(
                'error',
                actual=accessor_error,
                expected=sut.accessor_error_matches(
                    error=asrt.is_(accessor_error.error)),
            ),
            NEA(
                'error_info',
                actual=accessor_error,
                expected=sut.accessor_error_matches(
                    error_info=asrt.is_(accessor_error.error_info)),
            ),
        ]
        for case in cases:
            with self.subTest(case.name):
                case.expected.apply_without_message(self, case.actual)
示例#2
0
    def test(self):
        # ARRANGE #
        detail = sut.StringDetail('a detail')
        child = sut.Node('child header', False, (), ())
        root_header = 'root header'
        root_data = True
        root = sut.Node(root_header, root_data, (detail,), (child,))

        # ACT & ASSERT #

        self.assertEqual(root_header,
                         root.header,
                         'root header')

        self.assertEqual(root_data,
                         root.data,
                         'root data')

        expected_root_details = asrt.matches_singleton_sequence(
            asrt.is_(detail)
        )

        expected_root_details.apply_with_message(self,
                                                 root.details,
                                                 'root details')

        expected_root_children = asrt.matches_singleton_sequence(
            asrt.is_(child)
        )

        expected_root_children.apply_with_message(self,
                                                  root.children,
                                                  'root children')
示例#3
0
    def test_not_matches(self):
        # ARRANGE #
        expected_instruction = Instruction()
        expected_description = 'the description'
        instruction_info = InstructionInfo(expected_instruction, expected_description)
        expected_source = LineSequence(1, ('expected',))
        actual_element = ParsedInstruction(expected_source, instruction_info)

        cases = [
            NameAndValue('mismatch on source',
                         sut.matches_instruction(asrt.not_(equals_line_sequence(expected_source)),
                                                 matches_instruction_info(asrt.equals(expected_description),
                                                                          asrt.is_(expected_instruction)))
                         ),
            NameAndValue('mismatch on description',
                         sut.matches_instruction(equals_line_sequence(expected_source),
                                                 matches_instruction_info(asrt.not_(asrt.equals(expected_description)),
                                                                          asrt.is_(expected_instruction)))
                         ),
            NameAndValue('mismatch on instruction',
                         sut.matches_instruction(equals_line_sequence(expected_source),
                                                 matches_instruction_info(asrt.not_(asrt.equals(expected_description)),
                                                                          asrt.not_(asrt.is_(expected_instruction))))
                         ),
        ]
        for nav in cases:
            with self.subTest(nav.name):
                # ACT & ASSERT #
                assert_that_assertion_fails(nav.value, actual_element)
示例#4
0
 def test_matches(self):
     command = system_program_command('program', [])
     stdin_data = ()
     transformer = IdentityStringTransformer()
     sut.matches_program(
         command=asrt.is_(command),
         stdin=asrt.is_(stdin_data),
         transformer=asrt.matches_singleton_sequence(asrt.is_(transformer)),
     )
示例#5
0
 def test_matches(self):
     command = system_program_command('program', [])
     stdin_data = StdinData([])
     transformer = IdentityStringTransformer()
     sut.matches_program(
         command=asrt.is_(command),
         stdin=asrt.is_(stdin_data),
         transformer=asrt.is_(transformer),
     )
示例#6
0
 def test_success(self):
     # ARRANGE #
     reference = data_symbol_utils.symbol_reference('symbol_name')
     string_resolver = _StringResolverTestImpl(resolve_constant(STRING_VALUE), [reference])
     assertion = sut.matches_resolver(sut.is_resolver_of_string_type(),
                                      asrt.len_equals(1),
                                      asrt.is_(STRING_VALUE),
                                      asrt.is_(string_resolver))
     # ACT & ASSERT #
     assertion.apply_without_message(self, string_resolver)
示例#7
0
 def test_success(self):
     # ARRANGE #
     path_symbol = PathDdvSymbolContext(
         'symbol_name', path_ddvs.of_rel_option(RelOptionType.REL_ACT))
     reference = data_references.reference_to__on_direct_and_indirect(
         path_symbol.name)
     path_sdv = PathSdvTestImplWithConstantPathAndSymbolReferences(
         path_symbol.ddv, [reference])
     assertion = sut.matches_sdv(asrt.is_instance(PathSdv),
                                 asrt.len_equals(1),
                                 asrt.is_(path_symbol.ddv),
                                 asrt.is_(path_sdv),
                                 symbols=path_symbol.symbol_table)
     # ACT & ASSERT #
     assertion.apply_without_message(self, path_sdv)
示例#8
0
def equals_container(
        expected: SymbolContainer,
        ignore_source_line: bool = True) -> Assertion[SymbolContainer]:
    """
    :param expected: Must contain a data type value
    """

    component_assertions = [
        asrt.sub_component('value_type', SymbolContainer.value_type.fget,
                           asrt.is_(expected.value_type)),
    ]

    if not ignore_source_line:
        component_assertions.append(
            asrt.sub_component(
                'definition_source', SymbolContainer.definition_source.fget,
                equals_line_sequence(expected.definition_source)))
    component_assertions.append(
        asrt.sub_component(
            'source_location', SymbolContainer.source_location.fget,
            asrt.is_none_or_instance_with(
                SourceLocationInfo,
                asrt_src_loc.is_valid_source_location_info())), )

    expected_sdv = expected.sdv
    assert isinstance(expected_sdv,
                      DataTypeSdv), 'All actual values must be DataTypeSdv'
    component_assertions.append(
        asrt.sub_component('sdv', SymbolContainer.sdv.fget,
                           equals_data_type_sdv(expected_sdv)))
    return asrt.is_instance_with(SymbolContainer,
                                 asrt.and_(component_assertions))
示例#9
0
def is_resolver_of_data_type(data_value_type: DataValueType,
                             value_type: ValueType) -> ValueAssertion[rs.SymbolValueResolver]:
    return asrt.is_instance_with(DataValueResolver,
                                 asrt.and_([
                                     asrt.sub_component('type_category',
                                                        rs.get_type_category,
                                                        asrt.is_(TypeCategory.DATA)),

                                     asrt.sub_component('data_value_type',
                                                        get_data_value_type,
                                                        asrt.is_(data_value_type)),

                                     asrt.sub_component('value_type',
                                                        rs.get_value_type,
                                                        asrt.is_(value_type)),
                                 ]))
示例#10
0
def is_resolver_of_logic_type(logic_value_type: LogicValueType,
                              value_type: ValueType) -> ValueAssertion[rs.SymbolValueResolver]:
    return asrt.is_instance_with(LogicValueResolver,
                                 asrt.and_([
                                     asrt.sub_component('type_category',
                                                        rs.get_type_category,
                                                        asrt.is_(TypeCategory.LOGIC)),

                                     asrt.sub_component('logic_value_type',
                                                        get_logic_value_type,
                                                        asrt.is_(logic_value_type)),

                                     asrt.sub_component('value_type',
                                                        rs.get_value_type,
                                                        asrt.is_(value_type)),
                                 ]))
示例#11
0
    def test_transformation_only_as_source_argument(self):
        # ARRANGE #
        transformer = StringTransformerPrimitiveSymbolContext(
            'STRING_TRANSFORMER', string_transformers.to_uppercase())

        for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference(
        ):
            program_w_transformer = FullProgramAbsStx(
                pgm_and_args_case.pgm_and_args,
                transformation=transformer.abstract_syntax)

            symbols = list(pgm_and_args_case.symbols) + [transformer]

            with self.subTest(command=pgm_and_args_case.name):
                # ACT & ASSERT #
                CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input(
                    self, equivalent_source_variants__for_expr_parse__s__nsc,
                    program_w_transformer,
                    pgm_and_args_case.mk_arrangement(
                        SymbolContext.symbol_table_of_contexts(symbols)),
                    MultiSourceExpectation(
                        symbol_references=SymbolContext.
                        references_assertion_of_contexts(symbols),
                        primitive=lambda env: (asrt_pgm_val.matches_program(
                            asrt_command.
                            matches_command(driver=pgm_and_args_case.
                                            expected_command_driver(env),
                                            arguments=asrt.is_empty_sequence),
                            stdin=asrt_pgm_val.is_no_stdin(),
                            transformer=asrt.matches_singleton_sequence(
                                asrt.is_(transformer.primitive)),
                        ))))
示例#12
0
def is_skipped() -> Assertion[FullExeResult]:
    return matches(status=asrt.is_(FullExeResultStatus.SKIPPED),
                   failure_info=asrt.is_none,
                   has_sds=asrt.equals(False),
                   sds=asrt.is_none,
                   has_action_to_check_outcome=asrt.equals(False),
                   action_to_check_outcome=asrt.is_none)
示例#13
0
def is_skipped() -> ValueAssertion[FullExeResult]:
    return matches(status=asrt.is_(FullExeResultStatus.SKIPPED),
                   failure_info=asrt.is_none,
                   has_sds=asrt.equals(False),
                   sds=asrt.is_none,
                   has_action_to_check_outcome=asrt.equals(False),
                   action_to_check_outcome=asrt.is_none)
 def test_element_from_instruction_parser_SHOULD_be_assigned_to_section_contents_element(self):
     expected_instruction_info = InstructionInfo(Instruction(),
                                                 'description')
     expected = sut.ParsedInstruction(line_source.LineSequence(1,
                                                               ('first line text',)),
                                      expected_instruction_info)
     parser = sut.standard_syntax_element_parser(_InstructionParserThatGivesConstant(expected))
     source = _source_for_lines(['ignored', 'source', 'lines'])
     # ACT #
     element = parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
     # ASSERT #
     element_assertion = matches_instruction(
         source=asrt.is_(expected.source),
         instruction_info=matches_instruction_info(
             assertion_on_description=asrt.is_(expected_instruction_info.description),
             assertion_on_instruction=asrt.is_(expected_instruction_info.instruction)))
     element_assertion.apply_with_message(self, element, 'element')
示例#15
0
 def test_fail_due_to_unexpected_resolved_value(self):
     # ARRANGE #
     string_resolver = _StringResolverTestImpl(resolve_constant(STRING_VALUE))
     assertion = sut.matches_resolver(asrt.anything_goes(),
                                      asrt.anything_goes(),
                                      asrt.not_(asrt.is_(STRING_VALUE)))
     # ACT & ASSERT #
     test_of_test_resources_util.assert_that_assertion_fails(assertion, string_resolver)
def is_value_type_restriction(expected: ValueType) -> ValueAssertion[ReferenceRestrictions]:
    """
    Assertion on a :class:`ReferenceRestrictions`,
    that it is a :class:`TypeCategoryRestriction`,
    with a given :class:`TypeCategory`.
    """
    expected_type_category = value_type.VALUE_TYPE_2_TYPE_CATEGORY[expected]
    return asrt.is_instance_with(ValueTypeRestriction,
                                 asrt.and_([
                                     asrt.sub_component('value_type',
                                                        ValueTypeRestriction.value_type.fget,
                                                        asrt.is_(expected)),
                                     asrt.sub_component('type_category',
                                                        ValueTypeRestriction.type_category.fget,
                                                        asrt.is_(expected_type_category)),
                                 ]),
                                 )
示例#17
0
 def test_fail_due_to_unexpected_resolved_value(self):
     # ARRANGE #
     string_sdv = _StringSdvTestImpl(resolve_constant(STRING_DDV))
     assertion = sut.matches_sdv(asrt.anything_goes(), asrt.anything_goes(),
                                 asrt.not_(asrt.is_(STRING_DDV)))
     # ACT & ASSERT #
     test_of_test_resources_util.assert_that_assertion_fails(
         assertion, string_sdv)
示例#18
0
    def test_accept_visitor_invokes_correct_method(self):
        # ARRANGE #
        operand1 = constant.MatcherWithConstantResult(False)
        operand2 = constant.MatcherWithConstantResult(False)
        matcher = sut.Disjunction([operand1, operand2])

        return_value = 11
        visitor = MatcherStdTypeVisitorTestAcceptImpl.new_w_default_to_raise_exception(
            disjunction_action=assert_argument_satisfies__and_return(
                self,
                asrt.matches_sequence([asrt.is_(operand1),
                                       asrt.is_(operand2)]),
                return_value,
            ))
        actual_return_value = matcher.accept(visitor)
        # ASSERT #
        self.assertEqual(return_value, actual_return_value, 'return value')
示例#19
0
 def test_failure_of_value_type(self):
     # ARRANGE #
     actual_container = StringSymbolValueContext.of_arbitrary_value(
     ).container
     assertion_to_check = sut.matches_container(
         value_type=asrt.is_(ValueType.PATH),
         sdv=asrt.anything_goes(),
         definition_source=asrt.anything_goes())
     assert_that_assertion_fails(assertion_to_check, actual_container)
 def test_look_ahead_state_pass(self):
     # ARRANGE #
     assertion = sut.assert_token_stream(look_ahead_state=asrt.is_(LookAheadState.NULL))
     # ACT & ASSERT #
     token_stream = TokenStream('')
     self.assertTrue(token_stream.look_ahead_state is LookAheadState.NULL,
                     'sanity check: this test assumes that the constructor of the token parser '
                     'sets correct look-ahead state')
     assertion.apply_without_message(self, token_stream)
示例#21
0
def is_failure(status: FullExeResultStatus,
               failure_info: ValueAssertion[Optional[FailureInfo]] = asrt.is_instance(FailureInfo),
               sds: ValueAssertion[Optional[SandboxDirectoryStructure]] = asrt.anything_goes(),
               action_to_check_outcome: ValueAssertion[Optional[ActionToCheckOutcome]] = asrt.anything_goes(),
               ) -> ValueAssertion[FullExeResult]:
    return matches(status=asrt.is_(status),
                   sds=sds,
                   action_to_check_outcome=action_to_check_outcome,
                   failure_info=failure_info)
 def test_fail(self):
     # ARRANGE #
     assertion = sut.assert_token_stream(look_ahead_state=asrt.is_(LookAheadState.NULL))
     # ACT & ASSERT #
     token_stream = TokenStream('a_token')
     self.assertTrue(token_stream.look_ahead_state is LookAheadState.HAS_TOKEN,
                     'sanity check: this test assumes that the constructor of the token parser '
                     'sets correct look-ahead state')
     assert_that_assertion_fails(assertion, token_stream)
 def test_fail(self):
     # ARRANGE #
     assertion = sut.assert_token_stream(look_ahead_state=asrt.is_(LookAheadState.NULL))
     # ACT & ASSERT #
     token_stream = TokenStream('a_token')
     self.assertTrue(token_stream.look_ahead_state is LookAheadState.HAS_TOKEN,
                     'sanity check: this test assumes that the constructor of the token parser '
                     'sets correct look-ahead state')
     assert_that_assertion_fails(assertion, token_stream)
 def test_look_ahead_state_pass(self):
     # ARRANGE #
     assertion = sut.assert_token_stream(look_ahead_state=asrt.is_(LookAheadState.NULL))
     # ACT & ASSERT #
     token_stream = TokenStream('')
     self.assertTrue(token_stream.look_ahead_state is LookAheadState.NULL,
                     'sanity check: this test assumes that the constructor of the token parser '
                     'sets correct look-ahead state')
     assertion.apply_without_message(self, token_stream)
示例#25
0
def equals_simple_phase_step(
        expected: SimplePhaseStep) -> Assertion[SimplePhaseStep]:
    assert isinstance(expected, SimplePhaseStep), 'Must be SimplePhaseStep'
    return asrt.and_([
        asrt.sub_component('phase', SimplePhaseStep.phase.fget,
                           asrt.is_(expected.phase)),
        asrt.sub_component('step', SimplePhaseStep.step.fget,
                           asrt.equals(expected.step)),
    ])
 def test_resolver_SHOULD_be_given_as_argument_to_resolver_assertion(self):
     # ARRANGE #
     actual_resolver = string_resolvers.str_constant('s')
     actual_container = container_of_builtin(actual_resolver)
     assertion_that_is_expected_to_succeed = asrt.is_(actual_resolver)
     assertion_to_check = sut.matches_container(assertion_that_is_expected_to_succeed,
                                                assertion_on_source=asrt.anything_goes())
     # ACT & ASSERT #
     assertion_to_check.apply_without_message(self, actual_container)
 def test_pass_with_default_assertion_on_restrictions(self):
     # ARRANGE #
     symbol_name = 'symbol name'
     symbol_reference = SymbolReference(symbol_name,
                                        r.ReferenceRestrictionsOnDirectAndIndirect(
                                            vr.AnyDataTypeRestriction()))
     assertion = exactly_lib_test.symbol.test_resources.symbol_usage_assertions.matches_reference(
         asrt.is_(symbol_name))
     # ACT & ASSERT #
     assertion.apply_without_message(self, symbol_reference)
示例#28
0
def is_xpass(sds: Assertion[Optional[SandboxDs]] = asrt.is_instance(SandboxDs),
             action_to_check_outcome: Assertion[
                 Optional[ActionToCheckOutcome]] = asrt.is_instance(
                     ActionToCheckOutcome)) -> Assertion[FullExeResult]:
    return matches(status=asrt.is_(FullExeResultStatus.XPASS),
                   failure_info=asrt.is_none,
                   has_sds=asrt.equals(True),
                   sds=sds,
                   has_action_to_check_outcome=asrt.equals(True),
                   action_to_check_outcome=action_to_check_outcome)
def is_type_category_restriction(expected: TypeCategory) -> ValueAssertion[ReferenceRestrictions]:
    """
    Assertion on a :class:`ReferenceRestrictions`,
    that it is a :class:`TypeCategoryRestriction`,
    with a given :class:`TypeCategory`.
    """
    return asrt.is_instance_with(TypeCategoryRestriction,
                                 asrt.sub_component('type_category',
                                                    TypeCategoryRestriction.type_category.fget,
                                                    asrt.is_(expected)))
示例#30
0
 def test_pass_with_default_assertion_on_restrictions(self):
     # ARRANGE #
     symbol_name = 'symbol name'
     symbol_reference = SymbolReference(symbol_name,
                                        r.ReferenceRestrictionsOnDirectAndIndirect(
                                            vr.ArbitraryValueWStrRenderingRestriction.of_any()))
     assertion = symbol_usage_assertions.matches_reference(
         asrt.is_(symbol_name))
     # ACT & ASSERT #
     assertion.apply_without_message(self, symbol_reference)
示例#31
0
 def test_accept_SHOULD_invoke_method_for_non_standard_matcher(self):
     matcher = _BaseClassTestImpl()
     return_value = 5
     visitor = MatcherStdTypeVisitorTestAcceptImpl.new_w_default_to_raise_exception(
         non_standard_action=assert_argument_satisfies__and_return(
             self, asrt.is_(matcher), return_value))
     # ACT & ASSERT #
     actual_return_value = matcher.accept(visitor)
     # ASSERT #
     self.assertEqual(return_value, actual_return_value, 'return value')
示例#32
0
 def _run(self, expected: tcs.TestCaseStatus, initial: tcs.TestCaseStatus,
          argument: str):
     for source in equivalent_source_variants__with_source_check__consume_last_line(
             self, argument):
         self._check(
             sut.Parser(), source,
             Arrangement(test_case_status=initial,
                         actor=actor_that_runs_constant_actions()),
             Expectation(configuration=asrt_conf.matches(
                 status=asrt.is_(expected))))
示例#33
0
def equals_simple_phase_step(expected: SimplePhaseStep) -> ValueAssertion[SimplePhaseStep]:
    assert isinstance(expected, SimplePhaseStep), 'Must be SimplePhaseStep'
    return asrt.and_([
        asrt.sub_component('phase',
                           SimplePhaseStep.phase.fget,
                           asrt.is_(expected.phase)),
        asrt.sub_component('step',
                           SimplePhaseStep.step.fget,
                           asrt.equals(expected.step)),
    ])
示例#34
0
 def _run(self,
          expected: tcs.TestCaseStatus,
          initial: tcs.TestCaseStatus,
          argument: str):
     for source in equivalent_source_variants__with_source_check(self, argument):
         self._check(sut.Parser(),
                     source,
                     Arrangement(test_case_status=initial,
                                 actor=actor_that_runs_constant_actions()),
                     Expectation(configuration=asrt_conf.has(test_case_status=asrt.is_(expected))))
 def test_matches(self):
     # ARRANGE #
     expected_detail = StringDetail('the string detail')
     actual = sut.IndentedDetail([expected_detail])
     # EXPECTATION #
     assertion = sut.is_indented_detail(
         details=asrt.matches_singleton_sequence(asrt.is_(expected_detail))
     )
     # ACT & ASSERT #
     assertion.apply_without_message(self, actual)
示例#36
0
def is_xpass(sds: ValueAssertion[Optional[SandboxDirectoryStructure]] =
             asrt.is_instance(SandboxDirectoryStructure),
             action_to_check_outcome: ValueAssertion[Optional[ActionToCheckOutcome]] =
             asrt.is_instance(ActionToCheckOutcome)
             ) -> ValueAssertion[FullExeResult]:
    return matches(status=asrt.is_(FullExeResultStatus.XPASS),
                   failure_info=asrt.is_none,
                   has_sds=asrt.equals(True),
                   sds=sds,
                   has_action_to_check_outcome=asrt.equals(True),
                   action_to_check_outcome=action_to_check_outcome)
示例#37
0
def matches2(status: FullExeResultStatus,
             sds: ValueAssertion[FullExeResult],
             action_to_check_outcome: ValueAssertion[FullExeResult],
             failure_info: ValueAssertion[Optional[FailureInfo]] = asrt.anything_goes()
             ) -> ValueAssertion[FullExeResult]:
    return asrt.and_([
        matches(status=asrt.is_(status),
                failure_info=failure_info),
        sds,
        action_to_check_outcome,
    ])
示例#38
0
    def test_SHOULD_match_WHEN_references_match(self):
        # ARRANGE #
        actual_reference = data_references.reference_to__on_direct_and_indirect(
            'referenced element')
        actual_references = [actual_reference]
        actual_sdv = arbitrary_sdv_with_references(actual_references)

        assertion_to_check = _matches_string_matcher_sdv(
            references=asrt.matches_sequence([asrt.is_(actual_reference)]), )
        # ACT & ASSERT #
        assertion_to_check.apply_without_message(self, actual_sdv)
示例#39
0
def matches2(
    status: FullExeResultStatus,
    sds: Assertion[FullExeResult],
    action_to_check_outcome: Assertion[FullExeResult],
    failure_info: Assertion[Optional[FailureInfo]] = asrt.anything_goes()
) -> Assertion[FullExeResult]:
    return asrt.and_([
        matches(status=asrt.is_(status), failure_info=failure_info),
        sds,
        action_to_check_outcome,
    ])
示例#40
0
    def test_not_matches(self):
        expected_command = system_program_command('program', [])
        expected_stdin_data = StdinData([])
        expected_transformer = IdentityStringTransformer()

        assertion = sut.matches_program(
            command=asrt.is_(expected_command),
            stdin=asrt.is_(expected_stdin_data),
            transformer=asrt.is_(expected_transformer),
        )

        actual_command = system_program_command('program', [])
        actual_stdin_data = StdinData([])
        actual_transformer = IdentityStringTransformer()

        cases = [
            NameAndValue('unexpected command',
                         Program(
                             command=actual_command,
                             stdin=expected_stdin_data,
                             transformation=expected_transformer
                         )
                         ),
            NameAndValue('unexpected stdin',
                         Program(
                             command=expected_command,
                             stdin=actual_stdin_data,
                             transformation=expected_transformer
                         )
                         ),
            NameAndValue('unexpected transformer',
                         Program(
                             command=expected_command,
                             stdin=expected_stdin_data,
                             transformation=actual_transformer
                         )
                         ),
        ]
        for case in cases:
            with self.subTest(case.name):
                assert_that_assertion_fails(assertion, case.value)
 def test_element_from_instruction_parser_SHOULD_be_assigned_to_section_contents_element(
         self):
     expected_instruction_info = InstructionInfo(Instruction(),
                                                 'description')
     expected = sut.ParsedInstruction(
         line_source.LineSequence(1, ('first line text', )),
         expected_instruction_info)
     parser = sut.standard_syntax_element_parser(
         _InstructionParserThatGivesConstant(expected))
     source = _source_for_lines(['ignored', 'source', 'lines'])
     # ACT #
     element = parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
     # ASSERT #
     element_assertion = matches_instruction(
         source=asrt.is_(expected.source),
         instruction_info=matches_instruction_info(
             assertion_on_description=asrt.is_(
                 expected_instruction_info.description),
             assertion_on_instruction=asrt.is_(
                 expected_instruction_info.instruction)))
     element_assertion.apply_with_message(self, element, 'element')
示例#42
0
def is_failure(
    status: FullExeResultStatus,
    failure_info: Assertion[Optional[FailureInfo]] = asrt.is_instance(
        FailureInfo),
    sds: Assertion[Optional[SandboxDs]] = asrt.anything_goes(),
    action_to_check_outcome: Assertion[
        Optional[ActionToCheckOutcome]] = asrt.anything_goes(),
) -> Assertion[FullExeResult]:
    return matches(status=asrt.is_(status),
                   sds=sds,
                   action_to_check_outcome=action_to_check_outcome,
                   failure_info=failure_info)
示例#43
0
    def test_matches(self):
        # ARRANGE #
        instruction = Instruction()
        description = 'the description'
        instruction_info = InstructionInfo(instruction, description)
        actual_element = ParsedInstruction(LINE_SEQUENCE, instruction_info)

        assertion = sut.matches_instruction(equals_line_sequence(LINE_SEQUENCE),
                                            matches_instruction_info(asrt.equals(description),
                                                                     asrt.is_(instruction)))
        # ACT & ASSERT #
        assertion.apply_without_message(self, actual_element)
示例#44
0
    def test_SHOULD_match_WHEN_references_match(self):
        # ARRANGE #
        actual_reference = data_symbol_utils.symbol_reference('referenced element')
        actual_references = [actual_reference]
        actual_resolver = arbitrary_resolver_with_references(actual_references)

        assertion_to_check = sut.matches_string_matcher_resolver(references=asrt.matches_sequence([
            asrt.is_(actual_reference)
        ]),
        )
        # ACT & ASSERT #
        assertion_to_check.apply_without_message(self, actual_resolver)
 def expected_program(
         env: AssertionResolvingEnvironment) -> Assertion[Program]:
     return asrt_pgm_val.matches_program(
         asrt_command.matches_command(
             driver=pgm_and_args_case.expected_command_driver(env),
             arguments=asrt.equals(arguments),
         ),
         stdin=asrt.matches_singleton_sequence(
             asrt_str_src.matches__str(
                 asrt.equals(str_src_contents), )),
         transformer=asrt.matches_singleton_sequence(
             asrt.is_(transformer_symbol.primitive)),
     )
 def test_matches(self):
     ex = ValueError('an exception')
     cases = [
         NEA('expected type of exception',
             expected=
             sut.matches_exception(asrt.is_(ex)),
             actual=
             FailureDetails.new_exception(ex),
             ),
     ]
     for case in cases:
         with self.subTest(case.name):
             case.expected.apply_without_message(self, case.actual)
    def test_arbitrary_failure(self):
        # ARRANGE #
        actual_container = container_of_builtin(string_resolvers.str_constant('s'))
        actual_definition = SymbolDefinition('the name',
                                             actual_container)

        assertion_that_is_expected_to_succeed = asrt.not_(asrt.is_(actual_container))

        assertion_to_check = exactly_lib_test.symbol.test_resources.symbol_usage_assertions.matches_definition(
            name=asrt.anything_goes(),
            container=assertion_that_is_expected_to_succeed)
        # ACT & ASSERT #
        assert_that_assertion_fails(assertion_to_check, actual_definition)
    def test_container_SHOULD_be_given_as_argument_to_assertion_on_container(self):
        # ARRANGE #
        actual_container = container_of_builtin(string_resolvers.str_constant('s'))
        actual_definition = SymbolDefinition('the name',
                                             actual_container)

        assertion_that_is_expected_to_succeed = asrt.is_(actual_container)

        assertion_to_check = exactly_lib_test.symbol.test_resources.symbol_usage_assertions.matches_definition(
            name=asrt.anything_goes(),
            container=assertion_that_is_expected_to_succeed)
        # ACT & ASSERT #
        assertion_to_check.apply_without_message(self, actual_definition)
示例#49
0
 def test_sdv_SHOULD_be_given_as_argument_to_sdv_assertion(self):
     # ARRANGE #
     actual_sdv = string_sdvs.str_constant('s')
     builtin_symbol = StringSymbolValueContext.of_sdv(
         actual_sdv, definition_source=None)
     assertion_that_is_expected_to_succeed = asrt.is_(actual_sdv)
     assertion_to_check = sut.matches_container(
         asrt.anything_goes(),
         assertion_that_is_expected_to_succeed,
         definition_source=asrt.anything_goes())
     # ACT & ASSERT #
     assertion_to_check.apply_without_message(self,
                                              builtin_symbol.container)
示例#50
0
    def test_symbol_table_is_passed_to_resolve_method(self):
        # ARRANGE #
        symbol_name = 'symbol_name'
        string_resolver = _StringResolverTestImpl(resolve_string_via_symbol_table(symbol_name))
        symbol_table = singleton_symbol_table_2(symbol_name,
                                                data_symbol_utils.string_value_constant_container2(STRING_VALUE))

        assertion = sut.matches_resolver(asrt.anything_goes(),
                                         asrt.anything_goes(),
                                         asrt.is_(STRING_VALUE),
                                         symbols=symbol_table)
        # ACT & ASSERT #
        assertion.apply_without_message(self, string_resolver)
示例#51
0
    def test_accept_visitor_invokes_correct_method(self):
        # ARRANGE #
        operand = constant.MatcherWithConstantResult(False)
        matcher = sut.Negation(operand)

        return_value = 5
        visitor = MatcherStdTypeVisitorTestAcceptImpl.new_w_default_to_raise_exception(
            negation_action=assert_argument_satisfies__and_return(
                self, asrt.is_(operand), return_value))
        # ACT & ASSERT #
        actual_return_value = matcher.accept(visitor)
        # ASSERT #
        self.assertEqual(return_value, actual_return_value, 'return value')
示例#52
0
 def test_equals_references(self):
     # ARRANGE #
     actual_reference = data_symbol_utils.symbol_reference('referenced element')
     actual_references = [actual_reference]
     actual_resolver = LineMatcherResolverConstantTestImpl(
         LineMatcherConstant(False),
         references=actual_references)
     assertion_to_check = sut.resolved_value_equals_line_matcher(actual_resolver.resolved_value,
                                                                 references=asrt.matches_sequence([
                                                                     asrt.is_(actual_reference)
                                                                 ]),
                                                                 )
     # ACT & ASSERT #
     assertion_to_check.apply_without_message(self, actual_resolver)
示例#53
0
    def test_container_SHOULD_be_given_as_argument_to_assertion_on_container(self):
        # ARRANGE #
        builtin_symbol = StringSymbolContext.of_constant('the name', 's',
                                                         definition_source=None)
        actual_definition = builtin_symbol.definition
        actual_container = actual_definition.symbol_container

        assertion_that_is_expected_to_succeed = asrt.is_(actual_container)

        assertion_to_check = symbol_usage_assertions.matches_definition(
            name=asrt.anything_goes(),
            container=assertion_that_is_expected_to_succeed)
        # ACT & ASSERT #
        assertion_to_check.apply_without_message(self, actual_definition)
示例#54
0
    def runTest(self):
        # ARRANGE #
        transformer = StringTransformerPrimitiveSymbolContext(
            'STRING_TRANSFORMER', string_transformers.to_uppercase())
        after_bin_op = 'after bin op'
        after_bin_op_syntax = CustomStringTransformerAbsStx.of_str(
            after_bin_op)
        composition_string_transformer = StringTransformerCompositionAbsStx(
            [transformer.abstract_syntax, after_bin_op_syntax],
            within_parens=False,
            allow_elements_on_separate_lines=False,
        )
        expected_source_after_parse = asrt_source.is_at_line(
            current_line_number=2,
            remaining_part_of_current_line=' '.join(
                [composition_string_transformer.operator_name(),
                 after_bin_op]),
        )
        for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference(
        ):
            command_followed_by_transformer = FullProgramAbsStx(
                pgm_and_args_case.pgm_and_args,
                transformation=composition_string_transformer,
            )
            symbols = list(pgm_and_args_case.symbols) + [transformer]

            with self.subTest(command=pgm_and_args_case.name):
                source = remaining_source(
                    command_followed_by_transformer.tokenization().layout(
                        LayoutSpec.of_default()))
                # ACT & ASSERT #
                CHECKER_WO_EXECUTION.check(
                    self, source, None,
                    pgm_and_args_case.mk_arrangement(
                        SymbolContext.symbol_table_of_contexts(symbols)),
                    Expectation(
                        ParseExpectation(
                            source=expected_source_after_parse,
                            symbol_references=SymbolContext.
                            references_assertion_of_contexts(symbols),
                        ),
                        primitive=lambda env: (asrt_pgm_val.matches_program(
                            asrt_command.
                            matches_command(driver=pgm_and_args_case.
                                            expected_command_driver(env),
                                            arguments=asrt.is_empty_sequence),
                            stdin=asrt_pgm_val.is_no_stdin(),
                            transformer=asrt.matches_singleton_sequence(
                                asrt.is_(transformer.primitive)),
                        ))))
示例#55
0
    def test_SHOULD_not_match_WHEN_references_do_not_match(self):
        # ARRANGE #
        actual_reference = data_symbol_utils.symbol_reference('referenced element')
        actual_references = [actual_reference]
        actual_resolver = arbitrary_resolver_with_references(actual_references)

        cases = [
            NameAndValue('assert no references',
                         asrt.is_empty_sequence),
            NameAndValue('assert single invalid reference',
                         asrt.matches_sequence([
                             asrt.not_(asrt.is_(actual_reference))
                         ])),
        ]

        for case in cases:
            with self.subTest(name=case.name):
                assertion_to_check = sut.matches_regex_resolver(references=case.value)
                # ACT & ASSERT #
                assert_that_assertion_fails(assertion_to_check, actual_resolver)
 def test_succeed_WHEN_table_contains_the_expected_element(self):
     a_symbol = NameAndValue('symbol name',
                             ASymbolTableValue('symbol value'))
     cases = [
         ('assertion is',
          a_symbol,
          asrt.is_(a_symbol.value)
          ),
         ('assertion has expected value',
          a_symbol,
          assert_string_value_equals(a_symbol.value.value)
          ),
     ]
     for name, symbol, value_assertion in cases:
         with self.subTest(name=name):
             # ARRANGE #
             actual = SymbolTable({symbol.name: symbol.value})
             assertion = sut.assert_symbol_table_is_singleton(symbol.name, value_assertion)
             # ACT #
             assertion.apply_without_message(self, actual)
示例#57
0
    def test_not_equals_references(self):
        # ARRANGE #
        actual_reference = data_symbol_utils.symbol_reference('referenced element')
        actual_references = [actual_reference]
        actual_resolver = LineMatcherResolverConstantTestImpl(
            LineMatcherConstant(False),
            references=actual_references)

        cases = [
            NameAndValue('assert no references',
                         asrt.is_empty_sequence),
            NameAndValue('assert single invalid reference',
                         asrt.matches_sequence([
                             asrt.not_(asrt.is_(actual_reference))
                         ])),
        ]

        for case in cases:
            with self.subTest(name=case.name):
                assertion_to_check = sut.resolved_value_equals_line_matcher(actual_resolver.resolved_value,
                                                                            references=case.value,
                                                                            )
                # ACT & ASSERT #
                assert_that_assertion_fails(assertion_to_check, actual_resolver)
示例#58
0
 def test_false__with_message_builder(self):
     expected_object = 'expected object'
     actual_object = 'actual object'
     with self.assertRaises(TestException):
         sut.is_(expected_object).apply(self.put, actual_object,
                                        sut.MessageBuilder('head'))
示例#59
0
 def test_true(self):
     expected_object = 'expected object'
     sut.is_(expected_object).apply(self.put, expected_object)
     sut.is_(expected_object).apply(self.put, expected_object,
                                    sut.MessageBuilder('head'))
示例#60
0
    def test(self):
        test_cases = [
            # Single token
            ('a', 'a',
             assert_token_stream(is_null=asrt.is_true,
                                 look_ahead_state=asrt.is_(LookAheadState.NULL),
                                 position=asrt.equals(1),
                                 remaining_source=asrt.equals(''))),
            ('b ', 'b ',
             assert_token_stream(is_null=asrt.is_true,
                                 look_ahead_state=asrt.is_(LookAheadState.NULL),
                                 position=asrt.equals(2),
                                 remaining_source=asrt.equals(''))),
            ('x \n', 'x ',
             assert_token_stream(is_null=asrt.is_true,
                                 look_ahead_state=asrt.is_(LookAheadState.NULL),
                                 position=asrt.equals(2),
                                 remaining_source=asrt.equals('\n'))
             ),
            ('x\ny', 'x',
             assert_token_stream(head_token=assert_plain('y'),
                                 look_ahead_state=asrt.is_not(LookAheadState.NULL),
                                 position=asrt.equals(1),
                                 remaining_source=asrt.equals('\ny'))
             ),
            ('x\n y', 'x',
             assert_token_stream(head_token=assert_plain('y'),
                                 look_ahead_state=asrt.is_not(LookAheadState.NULL),
                                 position=asrt.equals(1),
                                 remaining_source=asrt.equals('\n y'))
             ),
            # Multiple tokens
            ('a A', 'a A',
             assert_token_stream(is_null=asrt.is_true,
                                 look_ahead_state=asrt.is_(LookAheadState.NULL),
                                 position=asrt.equals(3),
                                 remaining_source=asrt.equals(''))
             ),
            ('a A\nb B', 'a A',
             assert_token_stream(head_token=assert_plain('b'),
                                 look_ahead_state=asrt.is_not(LookAheadState.NULL),
                                 position=asrt.equals(3),
                                 remaining_source=asrt.equals('\nb B'))
             ),
            ('a A\ninvalid_token"', 'a A',
             assert_token_stream(look_ahead_state=asrt.is_(LookAheadState.SYNTAX_ERROR),
                                 is_null=asrt.is_true,
                                 position=asrt.equals(3),
                                 remaining_source=asrt.equals('\ninvalid_token"'))
             ),
            # No tokens
            ('', '',
             assert_token_stream(is_null=asrt.is_true,
                                 look_ahead_state=asrt.is_(LookAheadState.NULL),
                                 position=asrt.equals(0),
                                 remaining_source=asrt.equals(''))
             ),
            (' ', ' ',
             assert_token_stream(is_null=asrt.is_true,
                                 look_ahead_state=asrt.is_(LookAheadState.NULL),
                                 position=asrt.equals(1),
                                 remaining_source=asrt.equals(''))
             ),
            (' \n', ' ',
             assert_token_stream(is_null=asrt.is_true,
                                 look_ahead_state=asrt.is_(LookAheadState.NULL),
                                 position=asrt.equals(1),
                                 remaining_source=asrt.equals('\n'))
             ),
            (' \n ', ' ',
             assert_token_stream(is_null=asrt.is_true,
                                 look_ahead_state=asrt.is_(LookAheadState.NULL),
                                 position=asrt.equals(1),
                                 remaining_source=asrt.equals('\n '))
             ),
            (' \n"invalid quoting', ' ',
             assert_token_stream(look_ahead_state=asrt.is_(LookAheadState.SYNTAX_ERROR),
                                 position=asrt.equals(1),
                                 remaining_source=asrt.equals('\n"invalid quoting'))
             ),

        ]
        for source, expected_consumed_string, token_stream_assertion in test_cases:
            with self.subTest(msg=repr(source)):
                ts = sut.TokenStream(source)
                # ACT #
                actual_consumed_string = ts.consume_remaining_part_of_current_line_as_string()
                # ASSERT #
                self.assertEqual(expected_consumed_string,
                                 actual_consumed_string,
                                 'consumed string')
                token_stream_assertion.apply_with_message(self, ts, 'token stream after parse')