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), ])
def is_hard_error( assertion_on_error_message: Assertion[TextRenderer] = asrt_renderer. is_renderer_of_major_blocks()) -> Assertion[pfh.PassOrFailOrHardError]: return asrt.And([ status_is(pfh.PassOrFailOrHardErrorEnum.HARD_ERROR), failure_message_is(assertion_on_error_message) ])
def is_entity_for_type(entity_type_name: str) -> Assertion: return asrt.And([ is_entity, asrt.sub_component('entity type name', EntityCrossReferenceId.entity_type_identifier.fget, asrt.Equals(entity_type_name)) ])
def is_line(description: str = '') -> Assertion[Any]: return asrt.is_instance_with( Line, asrt.And([ asrt.sub_component('line_number', Line.line_number.fget, asrt.is_instance(int)), asrt.sub_component('text', Line.text.fget, asrt.is_instance(str)) ]), description)
def equals_line(expected: Line) -> Assertion[Any]: return asrt.is_instance_with( Line, asrt.And([ asrt.sub_component('line_number', Line.line_number.fget, asrt.equals(expected.line_number)), asrt.sub_component('text', Line.text.fget, asrt.equals(expected.text)) ]))
def assert_instruction(first_line_number: int, source_string: str) -> Assertion: return asrt.And([ asrt.sub_component('first_line_number', Instruction.first_line_number.fget, asrt.Equals(first_line_number)), asrt.sub_component('source_string', Instruction.source_string.fget, asrt.Equals(source_string)) ])
def path_relativity_variants_equals(expected: PathRelativityVariants) -> Assertion: return asrt.is_instance_with(PathRelativityVariants, asrt.And([ asrt.sub_component('rel_option_types', PathRelativityVariants.rel_option_types.fget, asrt.equals(expected.rel_option_types)), asrt.sub_component('absolute', PathRelativityVariants.absolute.fget, asrt.equals(expected.absolute)), ]))
def is_line_sequence(description: str = '') -> Assertion[LineSequence]: return asrt.is_instance_with( LineSequence, asrt.And([ asrt.sub_component('line_number', LineSequence.first_line_number.fget, asrt.is_instance(int)), asrt.sub_component_sequence('lines', LineSequence.lines.fget, asrt.is_instance(str)) ]), description)
def _equals_target_info_node__shallow(expected: TargetInfoNode, mk_equals_cross_ref_id) -> Assertion: return asrt.And([ _is_TargetInfoNodeObject_shallow, asrt.sub_component( 'target_info', TargetInfoNode.data.fget, equals_target_info(expected.data, mk_equals_cross_ref_id)), asrt.sub_component( 'children', TargetInfoNode.children.fget, asrt.len_equals(len(expected.children), 'Number of children')) ])
def _main_program_test_cases() -> list: return [ ProcessTestCase( 'Generation of html-doc SHOULD exit with 0 exit code ' 'AND output html', PlainArrangement([HELP_COMMAND] + arguments_for.html_doc()), asrt.And([ pr.is_result_for_exit_code(0), pr.stdout(begins_with(DOCTYPE_XHTML1_0)) ])) ]
def is_hard_error( assertion_on_error_message: Assertion[TextRenderer] = asrt_text_doc. is_any_text()) -> Assertion[sh.SuccessOrHardError]: return is_sh_and( asrt.And([ asrt.sub_component( 'is_hard_error', sh.SuccessOrHardError.is_hard_error.fget, asrt.equals(True, 'Status is expected to be hard-error')), asrt.sub_component('failure_message', sh.SuccessOrHardError.failure_message.fget, assertion_on_error_message) ]))
def visit_table(self, table: Table): format_assertion = asrt.sub_component('format', Table.format.fget, asrt.IsInstance(TableFormat)) is_table_row = asrt.every_element('table row cells', is_table_cell) rows_assertion = asrt.sub_component_sequence('rows', Table.rows.fget, is_table_row, '/') assertion = asrt.And([format_assertion, rows_assertion]) assertion.apply(self.put, table, self.message_builder)
def section_matches( header: Assertion[Text], contents: Assertion[SectionContents], target: Assertion[Optional[ core.CrossReferenceTarget]] = asrt.anything_goes() ) -> Assertion[Section]: return asrt.is_instance_with( Section, asrt.And([ asrt.sub_component('target', doc.Section.target.fget, target), asrt.sub_component('header', doc.Section.header.fget, header), asrt.sub_component('contents', doc.Section.contents.fget, contents) ]))
def matches_definition( name: Assertion[str], container: Assertion[SymbolContainer], ) -> Assertion[SymbolDefinition]: return asrt.is_instance_with( SymbolDefinition, asrt.And([ asrt.sub_component('name', SymbolDefinition.name.fget, asrt.is_instance_with(str, name)), asrt.sub_component( 'symbol_container', SymbolDefinition.symbol_container.fget, asrt.is_instance_with(SymbolContainer, container)), ]))
def section_contents_matches( initial_paragraphs: Assertion[ Sequence[ParagraphItem]] = asrt.anything_goes(), sections: Assertion[Sequence[SectionItem]] = asrt.anything_goes() ) -> Assertion[SectionContents]: return asrt.is_instance_with( SectionContents, asrt.And([ asrt.sub_component('initial_paragraphs', doc.SectionContents.initial_paragraphs.fget, initial_paragraphs), asrt.sub_component('sections', doc.SectionContents.sections.fget, sections) ]))
def is_section_contents(self, put: unittest.TestCase, value, message_builder: asrt.MessageBuilder = asrt.MessageBuilder()): asrt.And([ asrt.IsInstance(doc.SectionContents), asrt.sub_component_sequence('initial_paragraphs', doc.SectionContents.initial_paragraphs.fget, is_paragraph_item) ]).apply(put, value, message_builder) assert isinstance(value, doc.SectionContents) sections_message = asrt.sub_component_builder('sections', message_builder) asrt.IsInstance(list).apply(put, value.sections, sections_message) for (idx, section) in enumerate(value.sections): self.is_section_item(put, section, asrt.sub_component_builder('[%d]' % idx, sections_message))
def _non_entities_help() -> list: return [ ProcessTestCase( 'WHEN command line arguments are invalid THEN' ' exit code SHOULD indicate this' ' AND stdout SHOULD be empty', HelpInvokation(['too', 'many', 'arguments', ',', 'indeed']), asrt.And([ pr.is_result_for_exit_code(exit_codes.EXIT_INVALID_USAGE), pr.stdout(is_empty()) ])), ProcessTestCase('help for "program" SHOULD be successful', HelpInvokation(arguments_for.program()), RESULT_IS_SUCCESSFUL), ProcessTestCase('help for "help" SHOULD be successful', HelpInvokation(arguments_for.help_help()), RESULT_IS_SUCCESSFUL), ]
from exactly_lib.common.help.syntax_contents_structure import InvokationVariant, SyntaxElementDescription from exactly_lib_test.test_resources.value_assertions import value_assertion as asrt from exactly_lib_test.util.textformat.test_resources import structure as asrt_struct is_invokation_variant = asrt.is_instance_with( InvokationVariant, asrt.And([ asrt.sub_component('syntax', lambda iv: iv.syntax, asrt.IsInstance(str)), asrt.sub_component_sequence('description_rest', lambda iv: iv.description_rest, asrt_struct.is_paragraph_item) ])) is_syntax_element_description = asrt.is_instance_with( SyntaxElementDescription, asrt.And([ asrt.sub_component('name', lambda sed: sed.element_name, asrt.IsInstance(str)), asrt.sub_component_sequence('before_invokation_variants', lambda sed: sed.before_invokation_variants, asrt_struct.is_paragraph_item), asrt.sub_component_sequence('after_invokation_variants', lambda sed: sed.after_invokation_variants, asrt_struct.is_paragraph_item), asrt.sub_component_sequence('invokation_variants', lambda sed: sed.invokation_variants, is_invokation_variant) ]))
def expected_result(self) -> Assertion[SubProcessResultInfo]: return asrt.And([ process_result_info_assertions.is_process_result_for_exit_code( exit_values.EXECUTION__PASS.exit_code), ExpectedTestPathSymbolsAreSetCorrectlyAssertion(), ])
from exactly_lib.util.description import Description, DescriptionWithSubSections from exactly_lib_test.test_resources.value_assertions import value_assertion as asrt from exactly_lib_test.util.textformat.test_resources import structure as struct_check is_description = asrt.And([ asrt.IsInstance(Description), asrt.sub_component( 'single line description', Description.single_line_description.fget, struct_check.is_text), asrt.sub_component_sequence( 'rest paragraph-items', Description.rest.fget, struct_check.is_paragraph_item), ]) is_description_with_sub_sections = asrt.And([ asrt.IsInstance(DescriptionWithSubSections), asrt.sub_component( 'single line description', DescriptionWithSubSections.single_line_description.fget, struct_check.is_text), asrt.sub_component_sequence( 'rest sub-sections', DescriptionWithSubSections.rest.fget, struct_check.is_section_contents), ])
def is_exit_code(expected_exit_code: int) -> Assertion[ExitCodeOrHardError]: return asrt.And([ is_any_exit_code, asrt.sub_component('exit_code', ExitCodeOrHardError.exit_code.fget, asrt.equals(expected_exit_code)), ])
def visit_predefined_part(self, x: PredefinedHelpContentsPartReference): return equals_predefined_contents_part(x) def _is_str(component_name: str, component_getter: types.FunctionType) -> Assertion: return asrt.sub_component(component_name, component_getter, asrt.IsInstance(str)) _IS_CROSS_REFERENCE_ID_ASSERTION_GETTER = _IsCrossReferenceTargetAssertionGetter() test_case_phase_is_valid = _is_str('phase name', TestCasePhaseCrossReference.phase_name.fget) test_suite_section_is_valid = _is_str('section name', TestSuiteSectionCrossReference.section_name.fget) entity_is_valid = asrt.And([ _is_str('entity type name', EntityCrossReferenceId.entity_type_identifier.fget), _is_str('entity name', EntityCrossReferenceId.entity_name.fget), ]) def is_entity_for_type(entity_type_name: str) -> Assertion: return asrt.And([ is_entity, asrt.sub_component('entity type name', EntityCrossReferenceId.entity_type_identifier.fget, asrt.Equals(entity_type_name)) ]) def equals_predefined_contents_part(x: PredefinedHelpContentsPartReference) -> Assertion[CrossReferenceId]: return asrt.is_instance_with(PredefinedHelpContentsPartReference, asrt.sub_component('part',
from typing import List from exactly_lib.cli.definitions.common_cli_options import HELP_COMMAND from exactly_lib_test.test_resources.main_program.constant_arguments_check import Arrangement from exactly_lib_test.test_resources.value_assertions import process_result_assertions as pr from exactly_lib_test.test_resources.value_assertions import value_assertion as asrt from exactly_lib_test.test_resources.value_assertions.value_assertion_str import is_not_only_space class HelpInvokation(Arrangement): def __init__(self, help_arguments: List[str]): self.help_arguments = help_arguments def command_line_arguments(self) -> List[str]: return [HELP_COMMAND] + self.help_arguments RESULT_IS_SUCCESSFUL = asrt.And( [pr.is_result_for_exit_code(0), pr.stdout(is_not_only_space())])
def is_string_text_that_equals(expected: str) -> Assertion: return asrt.And([ is_string_text, asrt.sub_component('value', core.StringText.value.fget, asrt.equals(expected)), ])
asrt.sub_component('value', core.StringText.value.fget, asrt.IsInstance(str)), asrt.sub_component('tags', core.StringText.tags.fget, is_tags_set), ])) is_cross_reference_text = asrt.is_instance_with(core.CrossReferenceText, asrt.And([ asrt.sub_component('target', core.CrossReferenceText.target.fget, asrt.IsInstance(core.CrossReferenceTarget)), asrt.sub_component('title', core.CrossReferenceText.title_text.fget, 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,
import unittest from exactly_lib.util.textformat.section_target_hierarchy.targets import TargetInfo, TargetInfoNode from exactly_lib.util.textformat.structure import core from exactly_lib.util.textformat.structure.core import CrossReferenceTarget from exactly_lib_test.test_resources.value_assertions import value_assertion as asrt from exactly_lib_test.test_resources.value_assertions.value_assertion import Assertion, AssertionBase from exactly_lib_test.util.textformat.test_resources.structure import is_string_text is_target_info = asrt.And([ asrt.IsInstance(TargetInfo), asrt.sub_component('presentation', TargetInfo.presentation_text.fget, is_string_text), asrt.sub_component('target', TargetInfo.target.fget, asrt.IsInstance(core.CrossReferenceTarget)), ]) def equals_target_info( expected: TargetInfo, mk_equals_cross_ref_id=lambda x: asrt.anything_goes() ) -> Assertion: return _IsTargetInfoAndEquals(expected, mk_equals_cross_ref_id) def equals_target_info_node( expected: TargetInfoNode, mk_equals_cross_ref_id=lambda x: asrt.anything_goes() ) -> Assertion: """ Traverses every node in the node tree, and checks that it is equal to the corresponding
def is_svh_and( assertion: Assertion[svh.SuccessOrValidationErrorOrHardError] ) -> Assertion[svh.SuccessOrValidationErrorOrHardError]: return asrt.And( [asrt.IsInstance(svh.SuccessOrValidationErrorOrHardError), assertion])
def test_two_element_list__with_stop_assertion__last(self): assertions = [sut.Constant(False), _AssertionThatRaisesStopAssertion()] with self.assertRaises(TestException): sut.And(assertions).apply(self.put, 'value')
def _check_instance_and(self, object_name: str, expected_class: type, additional: Assertion, actual): asrt.And([asrt.IsInstance(expected_class), additional]).apply(self.put, actual, asrt.MessageBuilder(object_name))
def test_two_element_list__with_stop_assertion__first(self): assertions = [_AssertionThatRaisesStopAssertion(), sut.Constant(False)] sut.And(assertions).apply(self.put, 'value')