def assert_source(is_at_eof: Assertion[bool] = asrt.anything_goes(),
                  is_at_eol: Assertion[bool] = asrt.anything_goes(),
                  is_at_eol__except_for_space: Assertion[bool] = asrt.anything_goes(),
                  has_current_line: Assertion[bool] = asrt.anything_goes(),
                  current_line_number: Assertion[int] = asrt.anything_goes(),
                  current_line_text: Assertion[str] = asrt.anything_goes(),
                  column_index: Assertion[int] = asrt.anything_goes(),
                  remaining_part_of_current_line: Assertion[str] = asrt.anything_goes(),
                  remaining_source: Assertion[str] = asrt.anything_goes(),
                  ) -> Assertion[ParseSource]:
    return asrt.And([
        asrt.is_instance(ParseSource, 'Value to apply assertions on must be a {}'.format(ParseSource)),
        asrt.sub_component('is_at_eof', ParseSource.is_at_eof.fget, is_at_eof),
        asrt.sub_component('has_current_line', ParseSource.has_current_line.fget, has_current_line),
        asrt.Or([
            asrt.sub_component('has_current_line', ParseSource.has_current_line.fget, asrt.equals(False)),
            # The following must only be checked if has_current_line (because of precondition of ParseSource):
            asrt.And([
                asrt.sub_component('is_at_eol', ParseSource.is_at_eol.fget, is_at_eol),
                asrt.sub_component('is_at_eol__except_for_space', ParseSource.is_at_eol__except_for_space.fget,
                                   is_at_eol__except_for_space),
                asrt.sub_component('current_line_number', ParseSource.current_line_number.fget, current_line_number),
                asrt.sub_component('column_index', ParseSource.column_index.fget, column_index),
                asrt.sub_component('current_line_text', ParseSource.current_line_text.fget, current_line_text),
                asrt.sub_component('remaining_part_of_current_line', ParseSource.remaining_part_of_current_line.fget,
                                   remaining_part_of_current_line),
            ])
        ]),
        asrt.sub_component('remaining_source', ParseSource.remaining_source.fget, remaining_source),
    ])
示例#2
0
                                                                       is_string_text),

                                                    asrt.sub_component('tags',
                                                                       core.CrossReferenceText.tags.fget,
                                                                       is_tags_set),
                                                ]))


def is_cross_reference_target_list(name: str = '') -> Assertion:
    return asrt.every_element(name, is_cross_reference_target)


is_cross_reference_target = asrt.IsInstance(core.CrossReferenceTarget)

is_concrete_text = asrt.Or([
    is_string_text,
    is_cross_reference_text,
])

is_anchor_text = asrt.is_instance_with(
    core.AnchorText,
    asrt.And([
        asrt.sub_component('anchor',
                           core.AnchorText.anchor.fget,
                           asrt.IsInstance(core.CrossReferenceTarget)),
        asrt.sub_component('anchored_text',
                           core.AnchorText.anchored_text.fget,
                           is_concrete_text),
        asrt.sub_component('tags',
                           core.AnchorText.tags.fget,
                           is_tags_set),
    ]))
示例#3
0
 def test_two_element_list__true_true(self):
     assertions = [sut.Constant(True), sut.Constant(True)]
     sut.Or(assertions).apply(self.put, 'value')
示例#4
0
 def test_two_element_list__with_stop_assertion__last(self):
     assertions = [sut.Constant(False), _AssertionThatRaisesStopAssertion()]
     sut.Or(assertions).apply(self.put, 'value')
示例#5
0
 def test_two_element_list__false_false(self):
     assertions = [sut.Constant(False), sut.Constant(False)]
     with self.assertRaises(TestException):
         sut.Or(assertions).apply(self.put, 'value')
示例#6
0
 def test_singleton_list__false(self):
     assertions = [sut.Constant(False)]
     with self.assertRaises(TestException):
         sut.Or(assertions).apply(self.put, 'value')
示例#7
0
 def test_singleton_list__true(self):
     assertions = [sut.Constant(True)]
     sut.Or(assertions).apply(self.put, 'value')
示例#8
0
 def test_empty_list__with_message_builder(self):
     with self.assertRaises(TestException):
         sut.Or([]).apply(self.put, 'value', sut.MessageBuilder('head'))
示例#9
0
 def test_empty_list__sans_message_builder(self):
     with self.assertRaises(TestException):
         sut.Or([]).apply(self.put, 'value')