def test_differs__both_are_relative_but_with_different_relativity(self): # ARRANGE # expected = specific_relative_relativity(RelOptionType.REL_ACT) actual = specific_relative_relativity(RelOptionType.REL_HDS_CASE) assertion = sut.equals_path_relativity(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def test_not_matches(self): cases = [ NEA('different keys', expected={'expected key': sut.equals('value')}, actual={'actual key': 'value'}, ), NEA('different values', expected={'key': sut.equals('expected value')}, actual={'key': 'actual value'}, ), NEA('more elements in actual than in expected', expected={1: sut.equals('value')}, actual={1: 'value', 2: 'value'}, ), NEA('more elements in expected than in actual', expected={1: sut.equals('value'), 2: sut.equals('value')}, actual={1: 'value'}, ), ] for nea in cases: with self.subTest(nea.name): assertion = sut.matches_dict(nea.expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, nea.actual)
def test_differs__because_on_is_absolute(self): # ARRANGE # expected = SPECIFIC_ABSOLUTE_RELATIVITY actual = specific_relative_relativity(RelOptionType.REL_ACT) assertion = sut.equals_path_relativity(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def test_not_matches__different_size(self): element = 'an element' equals_element = sut.equals(element) cases = [ NEA('actual is empty', expected=[equals_element], actual=[], ), NEA('actual is non empty', expected=[], actual=[element], ), NEA('both are non-empty tuples', expected=(equals_element,), actual=(element, element), ), NEA('both are non-empty / more elements in expected', expected=[equals_element, equals_element], actual=[element], ), NEA('both are non-empty / more elements in actual', expected=[equals_element], actual=[element, element], ), ] for nea in cases: with self.subTest(nea.name): assertion = sut.matches_sequence(nea.expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, nea.actual)
def test_not_equals__different_value_types(self): cases = [ ArrEx( [WithStrRenderingType.STRING], [WithStrRenderingType.PATH], ), ArrEx( [WithStrRenderingType.LIST], [WithStrRenderingType.PATH], ), ArrEx( [WithStrRenderingType.LIST, WithStrRenderingType.PATH], [WithStrRenderingType.PATH], ), ArrEx( [WithStrRenderingType.PATH], [WithStrRenderingType.LIST, WithStrRenderingType.PATH], ), ] for case in cases: with self.subTest(actual=case.arrangement, expected=case.expectation): expected = ArbitraryValueWStrRenderingRestriction(case.expectation) actual = ArbitraryValueWStrRenderingRestriction(case.arrangement) assert_that_assertion_fails(sut.equals(expected), actual)
def test_not_matches(self): cases = [ NEA( 'different keys', expected={'expected key': sut.equals('value')}, actual={'actual key': 'value'}, ), NEA( 'different values', expected={'key': sut.equals('expected value')}, actual={'key': 'actual value'}, ), NEA( 'more elements in actual than in expected', expected={1: sut.equals('value')}, actual={ 1: 'value', 2: 'value' }, ), NEA( 'more elements in expected than in actual', expected={ 1: sut.equals('value'), 2: sut.equals('value') }, actual={1: 'value'}, ), ] for nea in cases: with self.subTest(nea.name): assertion = sut.matches_mapping(nea.expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, nea.actual)
def test_differs__rel_option_types__expected_has_super_set(self): expected = PathRelativityVariants( {RelOptionType.REL_ACT, RelOptionType.REL_HDS_CASE}, False) actual = PathRelativityVariants({RelOptionType.REL_ACT}, False) assertion = sut.path_relativity_variants_equals(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def test_differs__relativity(self): # ARRANGE # expected = PathDdvTestImpl(RelOptionType.REL_ACT, path_ddvs.constant_path_part('file-name')) actual = PathDdvTestImpl(RelOptionType.REL_HDS_CASE, path_ddvs.constant_path_part('file-name')) assertion = sut.matches_path_sdv(expected, asrt.ignore, empty_symbol_table()) # ACT & ASSERT # assert_that_assertion_fails(assertion, path_sdvs.constant(actual))
def test_differs__both_are_relative_but_with_different_relativity(self): # ARRANGE # expected = specific_relative_relativity(RelOptionType.REL_ACT) actual = specific_relative_relativity(RelOptionType.REL_HOME_CASE) assertion = sut.equals_path_relativity(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def test_fail__different_source_line_and_source_line_check_is_not_ignored(self): # ARRANGE # common_value = file_ref_resolvers.constant(file_ref_test_impl('common file-name')) expected = SymbolContainer(common_value, single_line_sequence(1, 'source code 1')) actual = SymbolContainer(common_value, single_line_sequence(2, 'source code 2')) assertion = sut.equals_container(expected, ignore_source_line=False) assert_that_assertion_fails(assertion, actual)
def _assert_not_matches(actual: MultiDirDependentValue, dir_dependencies: DirDependencies, resolved_value: Callable[[HomeAndSds], ValueAssertion[Any]] ): assertion = sut.matches_multi_dir_dependent_value(dir_dependencies, resolved_value) assert_that_assertion_fails(assertion, actual)
def _assert_not_matches(actual: SingleDirDependentValue, resolving_dependency: Optional[DirectoryStructurePartition], resolved_value: ValueAssertion, ): assertion = sut.matches_single_dir_dependent_value(resolving_dependency, lambda tcds: resolved_value) assert_that_assertion_fails(assertion, actual)
def test_symbol_ref_not_equals_symbol_ref_with_different_symbol_name(self): # ARRANGE # expected = list_resolvers.symbol_element(symbol_reference('expected_symbol_name')) actual = list_resolvers.symbol_element(symbol_reference('actual_symbol_name')) assertion = sut.equals_list_resolver_element(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def test_string_not_equals_string_with_different_value(self): # ARRANGE # expected = list_resolvers.str_element('expected value') actual = list_resolvers.str_element('actual value') assertion = sut.equals_list_resolver_element(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def test_symbol_ref_not_equals_string(self): # ARRANGE # string_element = list_resolvers.str_element('value') symbol_reference_element = list_resolvers.symbol_element(symbol_reference('symbol_name')) assertion = sut.equals_list_resolver_element(symbol_reference_element) # ACT & ASSERT # assert_that_assertion_fails(assertion, string_element)
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)
def test_not_matches__different_size(self): element = 'an element' equals_element = sut.equals(element) cases = [ NEA( 'actual is empty', expected=[equals_element], actual=[], ), NEA( 'actual is non empty', expected=[], actual=[element], ), NEA( 'both are non-empty tuples', expected=(equals_element, ), actual=(element, element), ), NEA( 'both are non-empty / more elements in expected', expected=[equals_element, equals_element], actual=[element], ), NEA( 'both are non-empty / more elements in actual', expected=[equals_element], actual=[element, element], ), ] for nea in cases: with self.subTest(nea.name): assertion = sut.matches_sequence(nea.expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, nea.actual)
def test_not_matches__non_matching_element(self): actual_element = 'actual element' expected_element = 'expected element' equals_expected_element = sut.equals(expected_element) cases = [ NEA( 'one element / list', expected=[equals_expected_element], actual=[actual_element], ), NEA( 'one element / tuple', expected=(equals_expected_element, ), actual=(actual_element, ), ), NEA( 'two elements', expected=[equals_expected_element, equals_expected_element], actual=[actual_element, actual_element], ), ] for nea in cases: with self.subTest(nea.name): assertion = sut.matches_sequence(nea.expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, nea.actual)
def test_not_equals__same_length__different_values(self): # ARRANGE # expected = (string_resolvers.str_fragment('expected value'),) actual = (string_resolvers.str_fragment('actual value'),) assertion = sut.equals_string_fragments(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def test_not_equals(self): string_symbol = NameAndValue('string_symbol_name', 'string symbol value') cases = [ Case('different number of elements', expected= list_resolvers.empty(), actual= list_resolvers.from_str_constants(['value']), ), Case('different value of single string', expected= list_resolvers.from_str_constants(['expected value']), actual= list_resolvers.from_str_constants(['actual value']), ), Case('different element types, but same resolved value', expected= list_resolvers.from_str_constants([string_symbol.value]), actual= list_resolvers.from_elements([list_resolvers.symbol_element(su.symbol_reference(string_symbol.name))]), symbols= su.symbol_table_with_single_string_value(string_symbol.name, string_symbol.value), ), ] for case in cases: with self.subTest(msg=case.name): assertion = sut.equals_list_resolver(case.expected, case.symbols) assert_that_assertion_fails(assertion, case.actual)
def test_fail_WHEN_restriction_is_of_other_type(self): # ARRANGE # assertion_to_check = sut.is_value_type_restriction(ValueType.PATH) restriction = reference_restrictions.is_any_data_type() # ACT & ASSERT # assert_that_assertion_fails(assertion_to_check, restriction)
def test_not_equals__replace(self): # ARRANGE # expected_regex = re.compile('expected_regex') expected_replacement = 'expected_replacement' unexpected_regex = re.compile('unexpected_regex') unexpected_replacement = 'unexpected_replacement' expected = ReplaceStringTransformer(expected_regex, expected_replacement) different_transformers = [ IdentityStringTransformer(), CustomStringTransformer(), SequenceStringTransformer([]), SelectStringTransformer(LineMatcherConstant(True)), ReplaceStringTransformer(unexpected_regex, expected_replacement), ReplaceStringTransformer(expected_regex, unexpected_replacement), ] for actual in different_transformers: assertion_to_check = sut.equals_string_transformer(expected) with self.subTest(actual=str(actual)): # ACT & ASSERT # assert_that_assertion_fails(assertion_to_check, actual)
def test_differs__exists_pre_sds(self): # ARRANGE # expected = PathDdvTestImpl(_EXISTS_PRE_SDS_RELATIVITY, path_ddvs.constant_path_part('file-name')) actual = PathDdvTestImpl(_NOT_EXISTS_PRE_SDS_RELATIVITY, path_ddvs.constant_path_part('file-name')) assertion = sut.matches_path_sdv(expected, asrt.ignore, empty_symbol_table()) # ACT & ASSERT # assert_that_assertion_fails(assertion, path_sdvs.constant(actual))
def test__default_behaviour__fail_if_path_to_failing_symbol_is_not_a_list(self): assert_that_assertion_fails( sut.is_failure_of_indirect_reference(), FailureOfIndirectReference('failing_symbol', 'this is a string - not a list', ValueRestrictionFailure('error message')) )
def test__default_behaviour__fail_if_error_message_is_not_a_string(self): assert_that_assertion_fails( sut.is_failure_of_indirect_reference(), FailureOfIndirectReference('failing_symbol', [], ValueRestrictionFailure(['this is a list - not a string'])), )
def test_fail_if_error_message_is_unexpected(self): assert_that_assertion_fails( sut.is_failure_of_indirect_reference(error_message=asrt.equals('expected error message')), FailureOfIndirectReference('failing_symbol', [], ValueRestrictionFailure('actual error message')) )
def test_fail_if_path_to_failing_symbol_is_unexpected(self): assert_that_assertion_fails( sut.is_failure_of_indirect_reference(path_to_failing_symbol=asrt.equals(['sym1', 'sym2'])), FailureOfIndirectReference('failing_symbol', ['sym1'], ValueRestrictionFailure('error message')) )
def test_not_equals(self): cases = [ NEA('unexpected driver type', expected= sut.matches_command(sut.equals_shell_command_driver(CommandDriverForShell('command')), ['arg']), actual= Command(CommandDriverForSystemProgram('command'), ['arg']), ), NEA('unexpected driver data', expected= sut.matches_command(sut.equals_system_program_command_driver(CommandDriverForSystemProgram('expected')), []), actual= Command(CommandDriverForSystemProgram('unexpected'), []), ), NEA('unexpected argument', expected= sut.matches_command(sut.equals_system_program_command_driver(CommandDriverForSystemProgram('command')), ['expected']), actual= Command(CommandDriverForSystemProgram('command'), ['expected', 'unexpected']), ), ] for case in cases: with self.subTest(case.name): assert_that_assertion_fails(case.expected, case.actual)
def test_fail_WHEN_restriction_is_of_other_type(self): # ARRANGE # assertion_to_check = sut.is_type_category_restriction(TypeCategory.DATA) restriction = reference_restrictions.is_any_data_type() # ACT & ASSERT # assert_that_assertion_fails(assertion_to_check, restriction)
def _assert_not_matches(actual: MultiDependenciesDdv, dir_dependencies: DirDependencies, resolved_value: Callable[[TestCaseDs], Assertion[Any]]): assertion = sut.matches_multi_dir_dependent_value( dir_dependencies, resolved_value) assert_that_assertion_fails(assertion, actual)
def runTest(self): # ARRANGE # may_depend_on_external_resources = False expected = 'the expected\ncontents' expected__invalid_line_sequence = ('the expected', '\ncontents') expectation = sut.ExpectationOnUnFrozenAndFrozen.equals( expected, may_depend_on_external_resources=asrt.equals(may_depend_on_external_resources), frozen_may_depend_on_external_resources=asrt.equals(may_depend_on_external_resources), ) data__valid = StringSourceData(expected, may_depend_on_external_resources) data__invalid_line_sequence = StringSourceData(expected, may_depend_on_external_resources) data__invalid_line_sequence.data__as_lines = expected__invalid_line_sequence source_constructor = self._source_constructor(data__valid, data__invalid_line_sequence) for check_variant in check_variants(expectation): with self.subTest(check_method=check_variant.name): # ACT & ASSERT # test_utils.assert_that_assertion_fails( check_variant.value, sut.SourceConstructors.of_common(source_constructor), )
def test_not_equals__same_length__different_values(self): # ARRANGE # expected = (string_sdvs.str_fragment('expected value'), ) actual = (string_sdvs.str_fragment('actual value'), ) assertion = sut.equals_string_fragments(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def test_not_equals(self): for case in self.DETAILS: assertion = sut.equals_detail(case.expected) for unexpected in case.unexpected: with self.subTest(type=type(case.expected), unexpected=unexpected.name): assert_that_assertion_fails(assertion, unexpected.value)
def test_not_equals__different_number_of_fragments__non_empty__empty(self): # ARRANGE # expected = (string_resolvers.str_fragment('value'),) actual = () assertion = sut.equals_string_fragments(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def test_symbol_ref_not_equals_symbol_ref_with_different_symbol_name(self): # ARRANGE # expected = list_sdvs.symbol_element(reference_to__on_direct_and_indirect('expected_symbol_name')) actual = list_sdvs.symbol_element(reference_to__on_direct_and_indirect('actual_symbol_name')) assertion = sut.equals_list_sdv_element(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def test_fail(self): a_symbol = NameAndValue('symbol name', ASymbolTableValue('symbol value')) a_different_symbol = NameAndValue('a different symbol name', ASymbolTableValue('a different symbol value')) cases = [ ('table is empty', empty_symbol_table(), a_symbol.name, asrt.anything_goes(), ), ('table is singleton but contains a different name', SymbolTable({a_symbol.name: a_symbol.value}), a_different_symbol.name, asrt.anything_goes(), ), ('table is singleton with given name but value assertion fails', SymbolTable({a_symbol.name: a_symbol.value}), a_symbol.name, assert_string_value_equals(a_different_symbol.value.value) ), ('table contains more than one element', SymbolTable({a_symbol.name: a_symbol.value, a_different_symbol.name: a_different_symbol.value }), a_symbol.name, asrt.anything_goes(), ), ] for name, table, symbol_name, value_assertion in cases: with self.subTest(name=name): assertion = sut.assert_symbol_table_is_singleton(symbol_name, value_assertion) assert_that_assertion_fails(assertion, table)
def test_differs__because_on_is_absolute(self): # ARRANGE # expected = SPECIFIC_ABSOLUTE_RELATIVITY actual = specific_relative_relativity(RelOptionType.REL_ACT) assertion = sut.equals_path_relativity(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def test_symbol_ref_not_equals_string(self): # ARRANGE # string_element = list_sdvs.str_element('value') symbol_reference_element = list_sdvs.symbol_element(reference_to__on_direct_and_indirect('symbol_name')) assertion = sut.equals_list_sdv_element(symbol_reference_element) # ACT & ASSERT # assert_that_assertion_fails(assertion, string_element)
def test_string_not_equals_string_with_different_value(self): # ARRANGE # expected = list_sdvs.str_element('expected value') actual = list_sdvs.str_element('actual value') assertion = sut.equals_list_sdv_element(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def test_not_equals__different_number_of_fragments__non_empty__empty(self): # ARRANGE # expected = (string_sdvs.str_fragment('value'), ) actual = () assertion = sut.equals_string_fragments(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def test_not_equals(self): location1 = SourceLocation(self.line_sequence_1, self.path_a) location2 = SourceLocation(self.line_sequence_2, self.path_b) cases = [ NEA( 'without inclusion chain/different location', expected=source_location_path_without_inclusions(location1), actual=source_location_path_without_inclusions(location2), ), NEA( 'with inclusion chain/different location', expected=SourceLocationPath(location1, [location1]), actual=SourceLocationPath(location2, [location1]), ), NEA( 'different inclusion chain / different size', expected=SourceLocationPath(location1, [location1]), actual=SourceLocationPath(location1, []), ), NEA( 'different inclusion chain / different contents', expected=SourceLocationPath(location1, [location1]), actual=SourceLocationPath(location1, [location2]), ), ] for nea in cases: with self.subTest(nea.name): assertion = sut.equals_source_location_path(nea.expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, nea.actual)
def test_differs__relativity(self): # ARRANGE # expected = FileRefTestImpl(RelOptionType.REL_ACT, file_refs.constant_path_part('file-name')) actual = FileRefTestImpl(RelOptionType.REL_HOME_CASE, file_refs.constant_path_part('file-name')) assertion = sut.matches_file_ref_resolver(expected, asrt.ignore, empty_symbol_table()) # ACT & ASSERT # assert_that_assertion_fails(assertion, file_ref_resolvers.constant(actual))
def test_differs__exists_pre_sds(self): # ARRANGE # expected = FileRefTestImpl(_EXISTS_PRE_SDS_RELATIVITY, file_refs.constant_path_part('file-name')) actual = FileRefTestImpl(_NOT_EXISTS_PRE_SDS_RELATIVITY, file_refs.constant_path_part('file-name')) assertion = sut.matches_file_ref_resolver(expected, asrt.ignore, empty_symbol_table()) # ACT & ASSERT # assert_that_assertion_fails(assertion, file_ref_resolvers.constant(actual))
def test_string_not_equals_string_with_different_value(self): # ARRANGE # fragment1 = string_resolvers.str_fragment('value 1') fragment2 = string_resolvers.str_fragment('value 2') assertion = sut.equals_string_fragment_resolver_with_exact_type(fragment1) # ACT & ASSERT # assert_that_assertion_fails(assertion, fragment2)
def test_not_matches(self): # ARRANGE # expected_line_num = 2 expected_line_text = 'line text' expected_section_name = 'section name' expected_file_path = pathlib.Path('a path') expected_file_inclusion_chain = [ SourceLocation(single_line_sequence(2, 'inclusion line'), pathlib.Path('inclusion file path')) ] expected_abs_path_of_dir_containing_file = pathlib.Path( pathlib.Path.cwd().root) assertion = sut.equals_instruction_without_description( expected_line_num, expected_line_text, expected_section_name, expected_file_path, expected_file_inclusion_chain) cases = [ NameAndValue( 'unexpected line num', new_instruction(expected_line_num + 1, expected_line_text, expected_section_name, expected_file_path, expected_file_inclusion_chain)), NameAndValue( 'unexpected line text', new_instruction(expected_line_num, expected_line_text + ' unexpected', expected_section_name, expected_file_path, expected_file_inclusion_chain)), NameAndValue( 'unexpected section name', new_instruction(expected_line_num, expected_line_text, expected_section_name + ' unexpected', expected_file_path, expected_file_inclusion_chain)), NameAndValue( 'unexpected file path', new_instruction(expected_line_num, expected_line_text, expected_section_name, expected_file_path / 'unexpected', expected_file_inclusion_chain)), NameAndValue( 'unexpected abs path of dir containing file', new_instruction(expected_line_num, expected_line_text, expected_section_name, expected_file_path / 'unexpected', expected_file_inclusion_chain)), NameAndValue( 'unexpected file inclusion chain', new_instruction(expected_line_num, expected_line_text, expected_section_name, expected_file_path, [])), NameAndValue('unexpected element type - empty', new_empty(expected_line_num, expected_line_text)), NameAndValue('unexpected element type - comment', new_comment(expected_line_num, expected_line_text)), ] for nav in cases: with self.subTest(nav.name): # ACT & ASSERT # assert_that_assertion_fails(assertion, nav.value)
def test_fail(self): actual = csv.ConstantFragment('actual value') expected = AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return('expected value'), get_value_of_any_dependency=do_return('expected value')) assertion = sut.equals_string_fragment(expected) assert_that_assertion_fails(assertion, actual)
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 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)
def test_fail__failing_assertion_on_value_restriction(self): # ARRANGE # actual_symbol_name = 'actual value name' actual = SymbolReference(actual_symbol_name, r.ReferenceRestrictionsOnDirectAndIndirect(vr.AnyDataTypeRestriction())) assertion = exactly_lib_test.symbol.test_resources.symbol_usage_assertions.matches_reference( assertion_on_restrictions=asrt.is_instance(r.OrReferenceRestrictions)) assert_that_assertion_fails(assertion, actual)
def test_differs__resolved_value(self): # ARRANGE # expected_string = 'expected value' expected = string_resolvers.str_constant(expected_string) actual = string_resolvers.str_constant('actual value') assertion = sut.equals_string_resolver(expected) # ACT & ASSERT # assert_that_assertion_fails(assertion, actual)
def _assert_not_matches( actual: Max1DependencyDdv, resolving_dependency: Optional[DirectoryStructurePartition], resolved_value: Assertion, ): assertion = sut.matches_single_dir_dependent_value( resolving_dependency, lambda tcds: resolved_value) assert_that_assertion_fails(assertion, actual)
def test_fail(self): actual = sut.Node('actual header', None, [], []) expectation = asrt_d_tree.matches_node(header=asrt.equals('expected header')) assertion = sut.matches_node_renderer(rendered_node=expectation) assert_that_assertion_fails(assertion, NodeRendererForTest(actual))
def test_not_equals__different__option_sets(self): lv = PathRelativityVariants({RelOptionType.REL_HOME_CASE, RelOptionType.REL_RESULT}, False) rv = PathRelativityVariants({RelOptionType.REL_HOME_CASE, RelOptionType.REL_ACT}, False) assertion = sut.equals_path_relativity_variants(lv) # ACT & ASSERT # assert_that_assertion_fails(assertion, rv)
def test_fail__different_number_of_elements(self): # ARRANGE # actual = sut.ListDdv([]) expected = sut.ListDdv([csv.string_ddv_of_single_string('value')]) assertion = sut.equals_list_ddv(expected) # ASSERT # assert_that_assertion_fails(assertion, actual)
def test_fail(self): actual = csv.ConstantFragmentDdv('actual value') expected = AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return('expected value'), get_value_of_any_dependency=do_return('expected value')) assertion = sut.equals_string_fragment_ddv(expected) assert_that_assertion_fails(assertion, actual)
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_fail__failing_assertion_on_value_restriction(self): # ARRANGE # actual_symbol_name = 'actual value name' actual = SymbolReference(actual_symbol_name, r.ReferenceRestrictionsOnDirectAndIndirect( vr.ArbitraryValueWStrRenderingRestriction.of_any())) assertion = symbol_usage_assertions.matches_reference( assertion_on_restrictions=asrt.is_instance(r.OrReferenceRestrictions)) assert_that_assertion_fails(assertion, actual)
def runTest(self): # ARRANGE # may_depend_on_external_resources = False expected = 'the expected contents' expectation = sut.ExpectationOnUnFrozenAndFrozen.equals( expected, may_depend_on_external_resources=asrt.equals(may_depend_on_external_resources), frozen_may_depend_on_external_resources=asrt.equals(may_depend_on_external_resources), ) data__expected = StringSourceData(expected, may_depend_on_external_resources) data__external_dependencies = StringSourceData(expected, not may_depend_on_external_resources) data__as_str = StringSourceData(expected, may_depend_on_external_resources) data__as_str.data__as_str = 'different contents of as_str' data__as_lines = StringSourceData(expected, may_depend_on_external_resources) data__as_lines.data__as_lines = as_line_sequence('different contents of as_lines') data__as_file = StringSourceData(expected, may_depend_on_external_resources) data__as_file.data__as_file = 'different contents of as_file' data__write_to = StringSourceData(expected, may_depend_on_external_resources) data__write_to.data__write_to = 'different contents of write_to' contents_cases = [ NameAndValue( 'may_depend_on_external_resources differ', data__external_dependencies, ), NameAndValue( 'as_str differ', data__as_str, ), NameAndValue( 'as_lines differ', data__as_lines, ), NameAndValue( 'as_file differ', data__as_file, ), NameAndValue( 'write_to differ', data__write_to, ), ] for contents_case in contents_cases: source_constructor = self._source_constructor(data__expected, contents_case.value) for check_variant in check_variants(expectation): with self.subTest(data_case=contents_case.name, check_method=check_variant.name): # ACT & ASSERT # test_utils.assert_that_assertion_fails( check_variant.value, sut.SourceConstructors.of_common(source_constructor), )
def test_fail__different_name(self): # ARRANGE # actual = SymbolReference('actual value name', r.ReferenceRestrictionsOnDirectAndIndirect( vr.ArbitraryValueWStrRenderingRestriction.of_any())) assertion = symbol_usage_assertions.matches_reference( asrt.equals('expected value name'), asrt.anything_goes()) assert_that_assertion_fails(assertion, actual)
def test_fail(self): actual_value = False trace = NodeRendererForTest(_trace_for(actual_value)) actual_result = MatchingResult(actual_value, trace) assertion = sut.matches(value=asrt.equals(not actual_value)) assert_that_assertion_fails(assertion, actual_result)