Esempio n. 1
0
    def test_node_with_detail_and_child(self):
        # ARRANGE #

        child = Node('the child', None, (), ())
        string_detail = StringDetail('the string detail')
        tree_in_detail = Node('the contained tree root', None,
                              (string_detail, ), (child, ))

        tree_detail = TreeDetail(tree_in_detail)

        root = Node('the root', False, [tree_detail], ())

        # EXPECTATION #

        expectation = matches_trace_with_details(
            root,
            [
                matches_detail_line_element(tree_in_detail.header, depth=0),
                matches_string_detail_line_element(string_detail, depth=1),
                matches_detail_line_element(child.header, depth=1),
            ],
        )

        # ACT & ASSERT #

        _check(self, root, expectation)
Esempio n. 2
0
    def test_node_with_detail_and_child(self):
        # ARRANGE #

        for child_data in [False, True]:
            with self.subTest(data=child_data):
                child = Node('the child', child_data, (), ())
                detail = StringDetail('the detail')
                root = Node('the root', False, [detail], [child])

                # EXPECTATION #

                expectation = asrt_struct.matches_major_block__w_plain_properties(
                    minor_blocks=asrt.matches_sequence([
                        asrt_struct.matches_minor_block(
                            line_elements=asrt.matches_sequence([
                                matches_header_line_element(root),
                                matches_string_detail_line_element(detail,
                                                                   depth=0),
                            ]),
                            properties=matches_node_properties(depth=0),
                        ),
                        asrt_struct.matches_minor_block(
                            line_elements=asrt.matches_singleton_sequence(
                                matches_header_line_element(child)),
                            properties=matches_node_properties(depth=1),
                        ),
                    ]))

                # ACT & ASSERT #

                _check(self, root, expectation)
Esempio n. 3
0
    def test_node_with_child_with_child(self):
        # ARRANGE #

        child_11 = Node('the child 11', None, (), ())
        child_1 = Node('the child 1', None, (), (child_11, ))
        tree_in_detail = Node('the contained tree root', None, (), (child_1, ))

        tree_detail = TreeDetail(tree_in_detail)

        root = Node('the root', False, [tree_detail], ())

        # EXPECTATION #

        expectation = matches_trace_with_details(
            root,
            [
                matches_detail_line_element(tree_in_detail.header, depth=0),
                matches_detail_line_element(child_1.header, depth=1),
                matches_detail_line_element(child_11.header, depth=2),
            ],
        )

        # ACT & ASSERT #

        _check(self, root, expectation)
Esempio n. 4
0
    def test_complex(self):
        # ARRANGE #

        child_11_detail = StringDetail('string detail 11')
        child_11 = Node('the child 11', None, (child_11_detail, ), ())
        child_1_detail_1 = StringDetail('string detail 1-1')
        child_1_detail_2 = StringDetail('string detail 1-2')
        child_1 = Node('the child 1', None,
                       (child_1_detail_1, child_1_detail_2), (child_11, ))
        child_2 = Node('the child 2', None, (), ())
        tree_in_detail = Node('the contained tree root', None, (),
                              (child_1, child_2))

        tree_detail = TreeDetail(tree_in_detail)

        root = Node('the root', False, [tree_detail], ())

        # EXPECTATION #

        expectation = matches_trace_with_details(
            root,
            [
                matches_detail_line_element(tree_in_detail.header, depth=0),
                matches_detail_line_element(child_1.header, depth=1),
                matches_string_detail_line_element(child_1_detail_1, depth=2),
                matches_string_detail_line_element(child_1_detail_2, depth=2),
                matches_detail_line_element(child_11.header, depth=2),
                matches_string_detail_line_element(child_11_detail, depth=3),
                matches_detail_line_element(child_2.header, depth=1),
            ],
        )

        # ACT & ASSERT #

        _check(self, root, expectation)
Esempio n. 5
0
    def test_node_with_2_details_and_2_children(self):
        for root_data in [False, True]:
            for child_1_data in [False, True]:
                for child_2_data in [False, True]:
                    with self.subTest(root_data=root_data,
                                      child_1_data=child_1_data,
                                      child_11_data=child_2_data):
                        child_1 = Node('the child 1', child_1_data, (), ())
                        child_2 = Node('the child 2', child_2_data, (), ())
                        children = [child_1, child_2]

                        detail_1 = StringDetail('the detail 1')
                        detail_2 = StringDetail('the detail 2')
                        details = [detail_1, detail_2]

                        root = Node('the root', root_data, details, children)

                        # EXPECTATION #

                        expectation = asrt_struct.matches_major_block__w_plain_properties(
                            minor_blocks=asrt.matches_sequence([
                                asrt_struct.matches_minor_block(
                                    line_elements=asrt.matches_sequence([
                                        matches_header_line_element(root),
                                        matches_string_detail_line_element(
                                            detail_1, depth=0),
                                        matches_string_detail_line_element(
                                            detail_2, depth=0),
                                    ]),
                                    properties=matches_node_properties(
                                        depth=0),
                                ),
                                asrt_struct.matches_minor_block(
                                    line_elements=asrt.
                                    matches_singleton_sequence(
                                        matches_header_line_element(child_1)),
                                    properties=matches_node_properties(
                                        depth=1),
                                ),
                                asrt_struct.matches_minor_block(
                                    line_elements=asrt.
                                    matches_singleton_sequence(
                                        matches_header_line_element(child_2)),
                                    properties=matches_node_properties(
                                        depth=1),
                                ),
                            ]))

                        # ACT & ASSERT #

                        _check(self, root, expectation)
 def test_success_WHEN_actual_is_valid(self):
     assertion = sut.matches()
     for result_case in False, True:
         renderer = NodeRendererForTest(Node('header', result_case, [], []))
         actual = MatchingResult(result_case, renderer)
         with self.subTest(case=result_case):
             assertion.apply_without_message(self, actual)
Esempio n. 7
0
 def render(self) -> Node[bool]:
     return Node(
         self._name,
         False,
         self._details().render(),
         (),
     )
Esempio n. 8
0
    def render(self) -> Node[T]:
        ds = list(custom_details.expected_rhs(self._rhs).render())
        if self._actual_lhs is not None:
            ds += custom_details.actual_lhs(self._actual_lhs).render()

        return Node(' '.join((self._op.name, self._rhs_syntax_element)),
                    self._data, ds, ())
Esempio n. 9
0
    def test_node_with_child(self):
        # ARRANGE #

        child = Node('the child', None, (), ())
        tree_in_detail = Node('the contained tree root', None, (), (child, ))

        text_style__non_neutral = TextStyle(font_style=FontStyle.BOLD)

        header_text_style_cases = [
            NEA(
                'default text style',
                TEXT_STYLE__NEUTRAL,
                TreeDetail(tree_in_detail),
            ),
            NEA(
                'custom text style',
                text_style__non_neutral,
                TreeDetail(tree_in_detail, text_style__non_neutral),
            ),
        ]

        for header_text_style_case in header_text_style_cases:
            with self.subTest(header_text_style_case.name):
                tree_detail = header_text_style_case.actual

                root = Node('the root', False, [tree_detail], ())

                # EXPECTATION #

                expectation = matches_trace_with_details(
                    root,
                    [
                        matches_detail_line_element(
                            tree_in_detail.header,
                            depth=0,
                            text_style=header_text_style_case.expected),
                        matches_detail_line_element(
                            child.header,
                            depth=1,
                            text_style=header_text_style_case.expected),
                    ],
                )

                # ACT & ASSERT #

                _check(self, root, expectation)
Esempio n. 10
0
 def render(self) -> Node[NODE_DATA]:
     return Node(
         self._header,
         self._data,
         list(
             itertools.chain.from_iterable(d.render()
                                           for d in self._details)),
         [c.render() for c in self._children],
     )
Esempio n. 11
0
 def render(self) -> Node[bool]:
     file_spec_renderer = custom_details.HeaderAndValue(
         NON_MATCHING_MATCHER,
         details.String(self._non_matching_path)
     )
     return Node(self._name,
                 False,
                 file_spec_renderer.render(),
                 (self._non_match_result.trace.render(),)
                 )
Esempio n. 12
0
    def test_node_with_child_with_child(self):
        # ARRANGE #

        for root_data in [False, True]:
            for child_1_data in [False, True]:
                for child_11_data in [False, True]:
                    with self.subTest(root_data=root_data,
                                      child_1_data=child_1_data,
                                      child_11_data=child_11_data):
                        child_11 = Node('the child 11', child_11_data, (), ())
                        child_1 = Node('the child_1', child_1_data, (),
                                       [child_11])
                        root = Node('the root', root_data, [], [child_1])

                        # EXPECTATION #

                        expectation = asrt_struct.matches_major_block__w_plain_properties(
                            minor_blocks=asrt.matches_sequence([
                                asrt_struct.matches_minor_block(
                                    line_elements=asrt.
                                    matches_singleton_sequence(
                                        matches_header_line_element(root)),
                                    properties=matches_node_properties(
                                        depth=0)),
                                asrt_struct.matches_minor_block(
                                    line_elements=asrt.
                                    matches_singleton_sequence(
                                        matches_header_line_element(child_1)),
                                    properties=matches_node_properties(
                                        depth=1)),
                                asrt_struct.matches_minor_block(
                                    line_elements=asrt.
                                    matches_singleton_sequence(
                                        matches_header_line_element(child_11)),
                                    properties=matches_node_properties(
                                        depth=2),
                                ),
                            ]))

                        # ACT & ASSERT #

                        _check(self, root, expectation)
Esempio n. 13
0
 def render(self) -> Node[NODE_DATA]:
     getter = property_getter.render()
     matcher_tree = matcher.render()
     details = list(getter.details)
     details += [tree.TreeDetail(c) for c in getter.children]
     return Node(
         getter.header,
         None,
         details,
         (matcher_tree, ),
     )
    def test_fail(self):
        actual_rendered_node = Node('actual header', False, [], [])
        actual_result = MatchingResult(
            actual_rendered_node.data,
            NodeRendererForTest(actual_rendered_node))

        renderer_assertion = asrt_trace_rendering.matches_node_renderer(
            rendered_node=asrt_d_tree.matches_node(
                header=asrt.equals('expected header')))

        assertion = sut.matches(trace=renderer_assertion)

        assert_that_assertion_fails(assertion, actual_result)
Esempio n. 15
0
 def render(self) -> Node[NODE_DATA]:
     getter = property_getter.render()
     matcher = matcher_result.trace.render()
     details = _details_list(getter.details)
     details += [
         custom_details.structure_tree_detail(c)
         for c in getter.children
     ]
     return Node(
         getter.header,
         matcher_result.value,
         details,
         (matcher, ),
     )
Esempio n. 16
0
 def render(self) -> Node[bool]:
     renderer = custom_details.ExpectedAndActual(
         _expected_file_names_renderer(self._applier.files_condition),
         custom_details.string_list(_files_in_model_list(self._actual)),
         details.HeaderAndValue(
             common.UNEXPECTED_NAME,
             details.String(self._unexpected_file.relative_to_root_dir),
         )
     )
     return Node(self._applier.name,
                 False,
                 renderer.render(),
                 (),
                 )
Esempio n. 17
0
    def test_gives_the_constant_on_first_invokation(self):
        # ARRANGE #

        node = Node('header', None, (), ())
        renderer = sut.CachedSingleInvokation(
            _ConstRendererThatRaisesExceptionOn2ndInvokation(node))

        # ACT #

        actual = renderer.render()

        # ASSERT #

        expectation = _equals_empty_node(node)

        expectation.apply_without_message(self, actual)
Esempio n. 18
0
    def test_string_detail(self):
        # ARRANGE #
        for string_object_case in STRING_OBJECT_CASES:
            with self.subTest(string_object_case.name):
                detail = StringDetail(string_object_case.value)
                root = Node('the root', False, [detail], ())

                # EXPECTATION #

                expectation = matches_trace_with_just_single_detail(
                    root,
                    matches_string_detail_line_element(detail, depth=0),
                )

                # ACT & ASSERT #

                _check(self, root, expectation)
Esempio n. 19
0
    def test_does_single_invokation(self):
        # ARRANGE #

        node = Node('header', None, (), ())
        renderer = sut.CachedSingleInvokation(
            _ConstRendererThatRaisesExceptionOn2ndInvokation(node))

        # ACT #

        actual_1 = renderer.render()
        actual_2 = renderer.render()

        # ASSERT #

        expectation = _equals_empty_node(node)

        expectation.apply_with_message(self, actual_1, '1st invokation')
        expectation.apply_with_message(self, actual_2, '2nd invokation')
Esempio n. 20
0
    def test(self):
        # ARRANGE #

        node = Node('header', None, (), ())

        def f() -> NodeRenderer[None]:
            return sut.Constant(node)

        renderer = sut.FromFunction(f)

        # ACT #

        actual = renderer.render()

        # ASSERT #

        expectation = _equals_empty_node(node)

        expectation.apply_without_message(self, actual)
Esempio n. 21
0
    def test_node_with_just_header(self):
        # ARRANGE #
        for data in [False, True]:
            with self.subTest(data=data):
                root = Node('header', data, (), ())

                # EXPECTATION #

                expectation = asrt_struct.matches_major_block__w_plain_properties(
                    minor_blocks=asrt.matches_sequence([
                        asrt_struct.matches_minor_block(
                            line_elements=asrt.matches_singleton_sequence(
                                matches_header_line_element(root)),
                            properties=matches_node_properties(depth=0),
                        )
                    ]))

                # ACT & ASSERT #

                _check(self, root, expectation)
Esempio n. 22
0
    def test_indented_detail(self):
        # ARRANGE #
        details_1 = StringDetail('indented detail 1')
        details_2 = StringDetail('indented detail 2')
        indented_detail = IndentedDetail([details_1, details_2])
        root = Node('the root', False, [indented_detail], ())

        # EXPECTATION #

        expectation = matches_trace_with_details(
            root,
            [
                matches_string_detail_line_element(details_1, depth=1),
                matches_string_detail_line_element(details_2, depth=1),
            ],
        )

        # ACT & ASSERT #

        _check(self, root, expectation)
Esempio n. 23
0
    def render(self) -> Node[bool]:
        get_explanation_and_actual = (
            self._too_few_files
            if len(self._fetch_of_expected_plus_1) < len(self._files_condition.files.keys())
            else
            self._too_many_files
        )
        explanation, actual = get_explanation_and_actual()

        expected_and_actual = custom_details.ExpectedAndActual(
            self._expected(),
            actual,
            details.String(explanation),
        )

        return Node(self._name,
                    False,
                    expected_and_actual.render(),
                    (),
                    )
Esempio n. 24
0
    def test_detail(self):
        # ARRANGE #

        for child_data in [False, True]:
            with self.subTest(data=child_data):
                detail = StringDetail('the detail')
                root = Node('the root', False, [detail], [])

                # EXPECTATION #

                expectation = asrt_struct.matches_major_block__w_plain_properties(
                    minor_blocks=asrt.matches_singleton_sequence(asrt_struct.matches_minor_block__w_plain_properties(
                        line_elements=asrt.matches_sequence([
                            _matches_header_line_element(root),
                            _matches_string_detail_line_element(detail, depth=0),
                        ]),
                    ))
                )

                # ACT & ASSERT #

                _check(self, root, expectation)
Esempio n. 25
0
    def test_header_and_value_detail(self):
        # ARRANGE #
        text_style__non_neutral = TextStyle(font_style=FontStyle.UNDERLINE)
        cases = [
            NIE(
                'without text style',
                TEXT_STYLE__NEUTRAL,
                TEXT_STYLE__NEUTRAL,
            ),
            NIE(
                'with text style',
                text_style__non_neutral,
                text_style__non_neutral,
            ),
        ]
        for case in cases:
            with self.subTest(case.name):
                value_detail = StringDetail('the value detail')
                header_and_value_detail = HeaderAndValueDetail(
                    'the header', [value_detail], case.input_value)
                root = Node('the root', False, [header_and_value_detail], ())

                # EXPECTATION #

                expectation = matches_trace_with_details(
                    root,
                    [
                        matches_detail_line_element(
                            header_and_value_detail.header,
                            depth=0,
                            text_style=case.expected_value),
                        matches_string_detail_line_element(value_detail,
                                                           depth=1),
                    ],
                )

                # ACT & ASSERT #

                _check(self, root, expectation)
Esempio n. 26
0
    def test_pre_formatted_string_detail(self):
        # ARRANGE #
        for string_object_case in STRING_OBJECT_CASES:
            for string_is_line_ended in [False, True]:
                with self.subTest(string_is_line_ended=string_is_line_ended,
                                  string_type=string_object_case.name):
                    detail = PreFormattedStringDetail(string_object_case.value,
                                                      string_is_line_ended)

                    root = Node('the root', True, [detail], ())

                    # EXPECTATION #

                    expectation = matches_trace_with_just_single_detail(
                        root,
                        matches_pre_formatted_string_detail_line_element(
                            detail, depth=0),
                    )

                    # ACT & ASSERT #

                    _check(self, root, expectation)
Esempio n. 27
0
    def test_header(self):
        # ARRANGE #
        for data in [False, True]:
            with self.subTest(data=data):
                root = Node('header', data, (), ())
                renderer = ConstantNodeRendererTestImpl(root)

                # EXPECTATION #

                expectation = asrt_struct.matches_major_block__w_plain_properties(
                    minor_blocks=asrt.matches_singleton_sequence(
                        asrt_struct.matches_minor_block__w_plain_properties(
                            line_elements=asrt.matches_singleton_sequence(
                                _matches_header_line_element(root)
                            ),
                        )
                    )
                )

                # ACT & ASSERT #

                _check(self, root, expectation)
Esempio n. 28
0
 def test_success_WHEN_actual_is_valid(self):
     assertion = sut.matches_node_renderer()
     assertion.apply_without_message(self,
                                     NodeRendererForTest(Node('header', None, [], [])))
def _trace_for(value: bool) -> Node[bool]:
    return Node('header', value, [], [])
Esempio n. 30
0
 def render(self) -> Node[bool]:
     return Node(self._matcher_name, False, self._details(), ())