Пример #1
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')
Пример #2
0
 def __init__(self, result: bool):
     self._result = result
     self._matching_result = MatchingResult(
         self._result,
         renderers.Constant(
             tree.Node(logic.CONSTANT_MATCHER, self._result,
                       (tree.StringDetail(logic.BOOLEANS[result]), ), ())),
     )
     self._structure = renderers.Constant(
         tree.Node(logic.CONSTANT_MATCHER, None,
                   (tree.StringDetail(logic.BOOLEANS[result]), ), ()))
Пример #3
0
 def matches_w_trace(self, model: MODEL) -> MatchingResult:
     self._registry.append(model)
     return MatchingResult(self._constant_result,
                           renderers.Constant(tree.Node(self.name,
                                                        self._constant_result,
                                                        (),
                                                        ())))
Пример #4
0
 def render(self) -> tree.Node[None]:
     return tree.Node(
         self.NAME,
         None,
         [tree.StringDetail(argument)
          for argument in self._arguments],
         (),
     )
Пример #5
0
    def test_attributes(self):
        # ARRANGE #

        tree = sut.Node('header', 'data', (), ())
        detail = sut.TreeDetail(tree)

        # ACT & ASSERT #

        self.assertIs(tree,
                      detail.tree)
Пример #6
0
    def test_disjunction_followed_by_conjunction__with_negation(self):
        # ARRANGEMENT #

        sym_a = NameAndValue('_a_',
                             matchers.ConstantMatcherWithCustomName('a', True))
        sym_b = NameAndValue(
            '_b_', matchers.ConstantMatcherWithCustomName('b', False))
        sym_c = NameAndValue('_c_',
                             matchers.ConstantMatcherWithCustomName('c', True))

        all_symbols = [sym_a, sym_b, sym_c]

        arguments = ArgumentElements([
            logic.NOT_OPERATOR_NAME,
            sym_a.name,
            logic.OR_OPERATOR_NAME,
            logic.NOT_OPERATOR_NAME,
            sym_b.name,
            logic.AND_OPERATOR_NAME,
            logic.NOT_OPERATOR_NAME,
            sym_c.name,
        ])

        expected_trace = tree.Node(logic.OR_OPERATOR_NAME, False, (), [
            tree.Node(logic.NOT_OPERATOR_NAME, False,
                      (), [sym_a.value.trace_tree]),
            tree.Node(logic.AND_OPERATOR_NAME, False, (), [
                tree.Node(logic.NOT_OPERATOR_NAME, True,
                          (), [sym_b.value.trace_tree]),
                tree.Node(logic.NOT_OPERATOR_NAME, False,
                          (), [sym_c.value.trace_tree]),
            ]),
        ])

        # ACT & ASSERT #

        self._check(
            arguments,
            False,
            all_symbols,
            expected_trace,
        )
Пример #7
0
 def _expected_trace_for(self,
                         expected_result: bool,
                         operands: List[NameAndValue[MatcherBehaviour]],
                         ) -> tree.Node[bool]:
     operand_nodes = filter(lambda x: x is not None,
                            [
                                operand.value.accept(_ApplicationTraceConstructor(operand.name))
                                for operand in operands
                            ])
     return tree.Node(self.operator,
                      expected_result,
                      (),
                      list(operand_nodes),
                      )
Пример #8
0
    def test_accept_visitor(self):
        # ARRANGE #

        visitor = _VisitorThatRegistersVisitedClassesAndReturnsConstant()

        node = sut.Node('header', 'data', (), ())
        detail = sut.TreeDetail(node)

        # ACT #

        detail.accept(visitor)

        # ASSERT #
        self.assertEqual(visitor.visited_classes,
                         [sut.TreeDetail],
                         'visited classes')
Пример #9
0
 def execution_case_for(
     operand_result: bool
 ) -> NExArr[PrimAndExeExpectation[MatcherWTrace[MODEL],
                                   MatchingResult], Arrangement]:
     operand_matcher = helper.logic_type_symbol_context_from_primitive(
         symbol_name,
         matchers.ConstantMatcherWithCustomTrace(
             mk_operand_trace, operand_result))
     trace = tree.Node(logic.NOT_OPERATOR_NAME, not operand_result, (),
                       [mk_operand_trace(operand_result)])
     return NExArr(
         'operand that gives ' + str(operand_result),
         PrimAndExeExpectation.of_exe(
             main_result=asrt_matching_result.matches(
                 value=asrt.equals(not operand_result),
                 trace=trace_equals(trace))),
         Arrangement(symbols=operand_matcher.symbol_table))
Пример #10
0
    def __init__(self,
                 name: str,
                 result: bool,
                 ):
        super().__init__(result)
        self._name = name

        self._trace_tree = tree.Node(name,
                                     result,
                                     (tree.StringDetail(logic.BOOLEANS[result]),),
                                     ())
        self._matching_result = MatchingResult(
            result,
            renderers.Constant(
                self._trace_tree
            ),
        )
Пример #11
0
    def runTest(self):
        # ARRANGE #
        def get_trace(data: T) -> tree.Node[T]:
            return tree.Node.empty('name of string matcher', data)

        for string_matcher_result in [False, True]:
            string_matcher = StringMatcherSymbolContext.of_primitive(
                'STRING_MATCHER',
                ConstantMatcherWithCustomTrace(get_trace,
                                               string_matcher_result),
            )
            expected_trace = tree.Node(
                MATCHER_NAME,
                string_matcher_result,
                (),
                [get_trace(string_matcher_result)],
            )

            # ACT & ASSERT #
            with self.subTest(string_matcher_result=string_matcher_result):
                integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants(
                    self,
                    arguments=lm_args.Contents(
                        sm_args2.SymbolReferenceWReferenceSyntax(
                            string_matcher.name), ).as_arguments,
                    input_=models.ARBITRARY_MODEL,
                    arrangement=arrangement_wo_tcds(
                        symbols=string_matcher.symbol_table, ),
                    expectation=Expectation(
                        ParseExpectation(symbol_references=string_matcher.
                                         references_assertion),
                        ExecutionExpectation(
                            main_result=asrt_matching_result.matches(
                                asrt.equals(string_matcher_result),
                                trace=asrt_trace_rendering.
                                matches_node_renderer(
                                    asrt_d_tree.equals_node(expected_trace)),
                            ))),
                )
Пример #12
0
 def matches_w_trace(self, line: LineMatcherLine) -> MatchingResult:
     result = self._matches(line)
     return MatchingResult(result,
                           Constant(tree.Node(self.name, result, (), ())))
Пример #13
0
 def matches_w_trace(self, model: MODEL) -> MatchingResult:
     value = self._matches(model)
     return MatchingResult(
         value,
         renderers.Constant(tree.Node(self.NAME, value, (), ())),
     )
Пример #14
0
 def structure(self) -> StructureRenderer:
     return renderers.Constant(tree.Node(self.NAME, None, (), ()))