def test_fail__different_fragment_value(self): # ARRANGE # actual = sut.ListDdv([csv.string_ddv_of_single_string('actual value')]) expected = sut.ListDdv( [csv.string_ddv_of_single_string('expected value')]) assertion = sut.equals_list_ddv(expected) # ASSERT # assert_that_assertion_fails(assertion, actual)
def test_resolve_with_concatenation_of_referenced_list_symbols(self): empty_list_symbol = ListDdvSymbolContext('empty_list_symbol', ListDdv([])) multi_element_list_symbol = ListDdvSymbolContext( 'multi_element_list_symbol', ListDdv( [string_ddv_of_single_string('multi list element 1'), string_ddv_of_single_string('multi list element 2')]) ) cases = [ Case( 'WHEN list is a single symbol reference AND symbol is an empty list ' 'THEN resolved value' 'SHOULD be an empty list', sdv_to_check= sut.ListSdv([list_sdvs.symbol_element(empty_list_symbol.reference__w_str_rendering)]), symbols= empty_list_symbol.symbol_table, expected_resolved_value= empty_list_symbol.ddv, ), Case( 'WHEN list is a single symbol reference AND symbol is a non-empty list ' 'THEN resolved value' 'SHOULD be equal to the non-empty list', sdv_to_check= sut.ListSdv([list_sdvs.symbol_element(multi_element_list_symbol.reference__w_str_rendering)]), symbols= multi_element_list_symbol.symbol_table, expected_resolved_value= multi_element_list_symbol.ddv, ), Case( 'WHEN list is multiple symbol reference AND all symbols are lists' 'THEN resolved value' 'SHOULD be equal to the concatenation of referenced lists', sdv_to_check= sut.ListSdv([list_sdvs.symbol_element(multi_element_list_symbol.reference__w_str_rendering), list_sdvs.symbol_element(empty_list_symbol.reference__w_str_rendering), list_sdvs.symbol_element(multi_element_list_symbol.reference__w_str_rendering)]), symbols= SymbolContext.symbol_table_of_contexts([ multi_element_list_symbol, empty_list_symbol, ]), expected_resolved_value= ListDdv(list(list(multi_element_list_symbol.ddv.string_elements) + list(multi_element_list_symbol.ddv.string_elements))), ), ] self._check('concatenation of referenced list symbols', cases)
def test_description(self): # ARRANGE # s1 = 'string1' s2 = 'string2' cases = [ NameAndValue( 'empty', [], ), NameAndValue( 'singleton element', [s1], ), NameAndValue( 'multiple elements', [s1, s2], ), ] for case in cases: with self.subTest(case.name): elements = [string_ddv_of_single_string(s) for s in case.value] list_fragment = sut.ListDdv(elements) # ACT # actual = list_fragment.describer().render_sequence() # ASSERT # self.assertEqual(case.value, actual)
def test_resolve_without_symbol_references(self): string_constant_1 = 'string constant 1' string_constant_2 = 'string constant 2' string_symbol = StringConstantSymbolContext('string_symbol_name', 'string symbol value') cases = [ Case( 'no elements', sdv_to_check= sut.ListSdv([]), symbols= empty_symbol_table(), expected_resolved_value= ListDdv([]), ), Case( 'single constant element', sdv_to_check= sut.ListSdv([list_sdvs.str_element(string_constant_1)]), symbols= empty_symbol_table(), expected_resolved_value= ListDdv([string_ddv_of_single_string(string_constant_1)]), ), Case( 'multiple constant elements', sdv_to_check= sut.ListSdv([list_sdvs.str_element(string_constant_1), list_sdvs.str_element(string_constant_2)]), symbols= empty_symbol_table(), expected_resolved_value= ListDdv([string_ddv_of_single_string(string_constant_1), string_ddv_of_single_string(string_constant_2)]), ), Case( 'single string symbol reference element', sdv_to_check= sut.ListSdv([list_sdvs.symbol_element(string_symbol.reference__w_str_rendering)]), symbols= string_symbol.symbol_table, expected_resolved_value= ListDdv([string_ddv_of_single_string(string_symbol.str_value)]), ), ] self._check('resolve without symbol references', cases)
def test_reference_to_symbol_that_are_not_lists(self): string_symbol_str = 'string constant' string_symbol = StringConstantSymbolContext('string_symbol', string_symbol_str) path_symbol = arbitrary_path_symbol_context('path_symbol') cases = [ Case( 'reference to string symbol', sdv_to_check= sut.ListSdv([list_sdvs.symbol_element(string_symbol.reference__w_str_rendering)]), symbols= string_symbol.symbol_table, expected_resolved_value= ListDdv([string_ddv_of_single_string(string_symbol.str_value)]), ), Case( 'reference to path symbol ' 'SHOULD resolve to string representation of the path value', sdv_to_check= sut.ListSdv([list_sdvs.symbol_element(path_symbol.reference__w_str_rendering)]), symbols= path_symbol.symbol_table, expected_resolved_value= ListDdv([string_ddv_of_single_path(path_symbol.ddv)]), ), Case( 'combination of string and path value', sdv_to_check= sut.ListSdv([list_sdvs.symbol_element(string_symbol.reference__w_str_rendering), list_sdvs.symbol_element(path_symbol.reference__w_str_rendering)]), symbols= SymbolContext.symbol_table_of_contexts([ string_symbol, path_symbol, ]), expected_resolved_value= ListDdv([string_ddv_of_single_string(string_symbol.str_value), string_ddv_of_single_path(path_symbol.ddv)]), ), ] self._check('reference to symbol that are not lists', cases)
def test_description(self): # ARRANGE # expected = 'the string' string_value_fragment = strings.StringDdvFragmentDdv(string_ddv_of_single_string(expected)) # ACT # actual = string_value_fragment.describer().render() # ASSERT # self.assertEqual(expected, actual)
def test_not_equals(self): string_symbol = StringConstantSymbolContext('string_symbol_name', 'string symbol value') cases = [ MatchesCase('different number of elements', expected= lr.ListDdv([]), expected_references= asrt.is_empty_sequence, actual= list_sdvs.from_str_constants(['value']), ), MatchesCase('different value of single string', expected= lr.ListDdv([string_ddv_of_single_string('expected value')]), expected_references= asrt.is_empty_sequence, actual= list_sdvs.from_str_constants(['actual value']), ), MatchesCase('different references', expected= lr.ListDdv([string_ddv_of_single_string(string_symbol.str_value)]), expected_references= asrt.matches_sequence([string_symbol.reference_assertion__w_str_rendering]), actual= list_sdvs.from_elements([list_sdvs.string_element( string_sdvs.symbol_reference( SymbolReference(string_symbol.name, OrReferenceRestrictions([])), ))]), symbols= string_symbol.symbol_table, ), ] for case in cases: with self.subTest(msg=case.name): assertion = sut.matches_list_sdv(case.expected, case.expected_references, case.symbols) assert_that_assertion_fails(assertion, case.actual)
def test(self): string_of_path_rel_home = string_ddv_of_single_path( path_ddvs.of_rel_option(path_ddvs.RelOptionType.REL_HDS_CASE, PathPartDdvAsNothing())) string_1 = 'string value 1' string_2 = 'string value 2' cases = [ ( 'single string constant element', strings.ListFragmentDdv(strings.ListDdv([string_ddv_of_single_string(string_1)])), AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return(string_1), get_value_of_any_dependency=do_return(string_1)), ), ( 'multiple string constant element', strings.ListFragmentDdv(strings.ListDdv([string_ddv_of_single_string(string_1), string_ddv_of_single_string(string_2)])), AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return(list_formatting.format_elements([string_1, string_2])), get_value_of_any_dependency=do_return(list_formatting.format_elements([string_1, string_2]))), ), ( 'dependency on ' + str(DirectoryStructurePartition.HDS), strings.ListFragmentDdv(strings.ListDdv([string_of_path_rel_home])), AMultiDirDependentValue( resolving_dependencies={DirectoryStructurePartition.HDS}, get_value_of_any_dependency=lambda h_s: str( string_of_path_rel_home.value_of_any_dependency(h_s))), ), ] for test_case_name, expected, actual in cases: assertion = matches_multi_dir_dependent_value(expected) with self.subTest(name=test_case_name): assertion.apply_without_message(self, actual)
def test_pass(self): cases = [ ( 'no elements', sut.ListDdv([]), ), ( 'single element', sut.ListDdv([csv.string_ddv_of_single_string('value')]), ), ] for name, value in cases: with self.subTest(name=name): assertion = sut.equals_list_ddv(value) assertion.apply_without_message(self, value)
def test_equals(self): string_symbol = StringConstantSymbolContext('string_symbol_name', 'string symbol value') cases = [ MatchesCase('empty list of fragments', expected= lr.ListDdv([]), expected_references= asrt.is_empty_sequence, actual= list_sdvs.empty(), ), MatchesCase('single fragment', expected= lr.ListDdv([string_ddv_of_single_string('expected value')]), expected_references= asrt.is_empty_sequence, actual= list_sdvs.from_str_constants(['expected value']), ), MatchesCase('symbol reference', expected= lr.ListDdv([string_ddv_of_single_string(string_symbol.str_value)]), expected_references= asrt.matches_sequence([string_symbol.reference_assertion__w_str_rendering]), actual= list_sdvs.from_elements([list_sdvs.string_element( string_sdvs.symbol_reference(string_symbol.reference__w_str_rendering) )]), symbols= string_symbol.symbol_table, ), ] for case in cases: with self.subTest(msg=case.name): assertion = sut.matches_list_sdv(case.expected, case.expected_references, case.symbols) assertion.apply_without_message(self, case.actual)
def _ddv_of_constant(elements: Sequence[str]) -> ListDdv: return ListDdv( [string_ddv_of_single_string(element) for element in elements])
def sdv_with_single_constant_fragment(element_value: str) -> sut.ListSdv: return sut.ListSdv([string_ddv_of_single_string(element_value)])
def list_ddv_of_string_constants(str_list: Sequence[str]) -> ListDdv: return ListDdv([string_ddv_of_single_string(s) for s in str_list])
def test_dependence_and_resolving(self): string_fragment_1 = 'string fragment 1' string_fragment_2 = 'string fragment 2' path_rel_home = path_ddvs.of_rel_option( path_ddvs.RelOptionType.REL_HDS_CASE, PathPartDdvAsNothing()) path_rel_sds = path_ddvs.of_rel_option(path_ddvs.RelOptionType.REL_ACT, PathPartDdvAsNothing()) single_element_with_dep_on_home = sv.string_ddv_of_single_path( path_rel_home) single_element_with_dep_on_sds = sv.string_ddv_of_single_path( path_rel_sds) cases = [ ( 'no elements', sut.ListDdv([]), AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return([]), get_value_of_any_dependency=do_return([])), ), ( 'single string constant element', sut.ListDdv( [sv.string_ddv_of_single_string(string_fragment_1)]), AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return( [string_fragment_1]), get_value_of_any_dependency=do_return([string_fragment_1 ])), ), ( 'multiple string constant element', sut.ListDdv([ sv.string_ddv_of_single_string(string_fragment_1), sv.string_ddv_of_single_string(string_fragment_2) ]), AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return( [string_fragment_1, string_fragment_2]), get_value_of_any_dependency=do_return( [string_fragment_1, string_fragment_2])), ), ( 'single dir dependent value/pre sds', sut.ListDdv([single_element_with_dep_on_home]), AMultiDirDependentValue( resolving_dependencies={DirectoryStructurePartition.HDS}, get_value_of_any_dependency=lambda h_s: [ single_element_with_dep_on_home. value_of_any_dependency(h_s) ]), ), ( 'single dir dependent value/post sds', sut.ListDdv([single_element_with_dep_on_sds]), AMultiDirDependentValue( resolving_dependencies={ DirectoryStructurePartition.NON_HDS }, get_value_of_any_dependency=lambda h_s: [ single_element_with_dep_on_sds.value_of_any_dependency( h_s) ]), ), ( 'multiple dir dependent value/pre sds + post sds', sut.ListDdv([ single_element_with_dep_on_home, single_element_with_dep_on_sds ]), AMultiDirDependentValue( resolving_dependencies={ DirectoryStructurePartition.HDS, DirectoryStructurePartition.NON_HDS }, get_value_of_any_dependency=lambda h_s: [ single_element_with_dep_on_home. value_of_any_dependency(h_s), single_element_with_dep_on_sds.value_of_any_dependency( h_s) ]), ), ] for test_case_name, expected, actual in cases: assertion = matches_multi_dir_dependent_value(expected) with self.subTest(name=test_case_name): assertion.apply_without_message(self, actual)