def test(self): expected_defined_symbol = ConstantSuffixPathDdvSymbolContext( 'name', RelOptionType.REL_ACT, 'component') argument_cases = [ NameAndValue('value on same line', '{rel_act} {suffix}'), NameAndValue('value on following line', '{new_line} {rel_act} {suffix}'), ] for argument_case in argument_cases: with self.subTest(arguments=argument_case.name): instruction_argument = src2( ValueType.PATH, expected_defined_symbol.name, argument_case.value, suffix=expected_defined_symbol.path_suffix) for source in equivalent_source_variants__with_source_check__consume_last_line( self, instruction_argument): INSTRUCTION_CHECKER.check( self, source, Arrangement.phase_agnostic(), Expectation.phase_agnostic( symbol_usages=asrt.matches_singleton_sequence( expected_defined_symbol. assert_matches_definition_of_sdv), symbols_after_main=assert_symbol_table_is_singleton( expected_defined_symbol.name, expected_defined_symbol.value. assert_matches_container_of_sdv)))
def test(self): with tmp_dir() as abs_path_of_dir_containing_last_file_base_name: fs_location_info = FileSystemLocationInfo( FileLocationInfo( abs_path_of_dir_containing_last_file_base_name)) instruction_argument = src2(ValueType.PATH, 'name', '{rel_source_file} component') for source in equivalent_source_variants__with_source_check__consume_last_line( self, instruction_argument): expected_path_sdv = path_sdvs.constant( path_ddvs.rel_abs_path( abs_path_of_dir_containing_last_file_base_name, path_ddvs.constant_path_part('component'))) expected_symbol_value = PathSymbolValueContext.of_sdv( expected_path_sdv) expected_symbol = PathSymbolContext('name', expected_symbol_value) INSTRUCTION_CHECKER.check( self, source, Arrangement.phase_agnostic( fs_location_info=fs_location_info), Expectation.phase_agnostic( symbol_usages=asrt.matches_singleton_sequence( expected_symbol.assert_matches_definition_of_sdv), symbols_after_main=assert_symbol_table_is_singleton( 'name', expected_symbol_value. assert_matches_container_of_sdv)))
def test_assignment_of_symbols_and_constant_text_within_soft_quotes(self): # ARRANGE # referred_symbol1 = SymbolWithReferenceSyntax('referred_symbol_1') referred_symbol2 = SymbolWithReferenceSyntax('referred_symbol_2') assigned_symbol = StringSymbolContext.of_sdv( 'defined_symbol', string_sdv_from_fragments([ symbol(referred_symbol1.name), constant(' between '), symbol(referred_symbol2.name), ])) source = single_line_source('{string_type} {name} = {soft_quote}{sym_ref1} between {sym_ref2}{soft_quote}', soft_quote=SOFT_QUOTE_CHAR, name=assigned_symbol.name, sym_ref1=referred_symbol1, sym_ref2=referred_symbol2) expectation = Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ assigned_symbol.assert_matches_definition_of_sdv, ]), symbols_after_main=assert_symbol_table_is_singleton( assigned_symbol.name, assigned_symbol.value.assert_matches_container_of_sdv, ) ) # ACT & ASSERT # INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
def test_assignment_of_list_with_multiple_constant_elements(self): # ARRANGE # value_without_space = 'value_without_space' value_with_space = 'value with space' symbol_to_assign = ListSymbolContext.of_sdv( 'the_symbol_name', sdvs.from_str_constants([value_without_space, value_with_space])) syntax = _syntax( symbol_to_assign, NonEmptyListAbsStx([ ListElementStringAbsStx.of_str(value_without_space), ListElementStringAbsStx.of_str(value_with_space, QuoteType.SOFT), ])) expectation = MultiSourceExpectation.phase_agnostic( symbol_usages=asrt.matches_sequence( [symbol_to_assign.assert_matches_definition_of_sdv]), symbols_after_main=assert_symbol_table_is_singleton( symbol_to_assign.name, symbol_to_assign.value.assert_matches_container_of_sdv, ), ) # ACT & ASSERT # INSTRUCTION_CHECKER.check__abs_stx__layout_and_source_variants( self, syntax, Arrangement.phase_agnostic(), expectation, )
def test_assignment_of_empty_list(self): symbol_name = 'the_symbol_name' sb = SB.new_with(symbol_name=symbol_name) cases = [ SourceCase('No following lines', source=sb.single_line('{list_type} {symbol_name} = '), source_assertion=asrt_source.source_is_at_end ), SourceCase('Following lines', source=sb.lines(['{list_type} {symbol_name} = ', 'following line'], ), source_assertion=asrt_source.is_at_beginning_of_line(2) ), ] expected_resolver = lrs.empty() expected_resolver_container = container(expected_resolver) for case in cases: with self.subTest(case.name): expectation = Expectation( symbol_usages=asrt.matches_sequence([ vs_asrt.equals_symbol(SymbolDefinition(symbol_name, expected_resolver_container), ignore_source_line=True) ]), symbols_after_main=assert_symbol_table_is_singleton( symbol_name, equals_container(expected_resolver_container), ), source=case.source_assertion ) self._check(case.source, ArrangementWithSds(), expectation)
def test(self): instruction_argument = src2( ValueType.PATH, 'ASSIGNED_NAME', '{rel_symbol} REFERENCED_SYMBOL component') for source in equivalent_source_variants__with_source_check__consume_last_line( self, instruction_argument): expected_path_sdv = path_sdvs.rel_symbol( SymbolReference( 'REFERENCED_SYMBOL', ReferenceRestrictionsOnDirectAndIndirect( PathAndRelativityRestriction( type_parser.REL_OPTIONS_CONFIGURATION. accepted_relativity_variants))), path_part_sdvs.from_constant_str('component')) expected_symbol_value = PathSymbolValueContext.of_sdv( expected_path_sdv) expected_symbol = PathSymbolContext('ASSIGNED_NAME', expected_symbol_value) INSTRUCTION_CHECKER.check( self, source, Arrangement.phase_agnostic(), Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence( [expected_symbol.assert_matches_definition_of_sdv]), symbols_after_main=assert_symbol_table_is_singleton( expected_symbol.name, expected_symbol_value. assert_matches_container_of_sdv)))
def test_assignment_of_single_symbol_reference(self): # ARRANGE # referred_symbol = SymbolWithReferenceSyntax('referred_symbol') expected_sdv = string_sdv_from_fragments([symbol(referred_symbol.name), constant('\n')]) assigned_symbol = StringSymbolContext.of_sdv( 'defined_symbol', expected_sdv, ) sb = SB.new_with(referred_symbol=referred_symbol, name_of_defined_symbol=assigned_symbol.name) source = sb.lines( here_doc_lines(first_line_start='{string_type} {name_of_defined_symbol} = ', marker='EOF', contents_lines=[str(referred_symbol)]) ) # EXPECTATION # expectation = Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ assigned_symbol.assert_matches_definition_of_sdv, ]), symbols_after_main=assert_symbol_table_is_singleton( assigned_symbol.name, assigned_symbol.value.assert_matches_container_of_sdv, ) ) # ACT & ASSERT # INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
def test_successful_parse_of_arbitrary_matcher(self): defined_name = 'defined_name' # ARRANGE # source = single_line_source( src('{string_matcher_type} {defined_name} = {matcher_argument}', defined_name=defined_name, matcher_argument=arg_syntax.arbitrary_single_line_value_that_must_not_be_quoted()), ) # EXPECTATION # expected_container = matches_container( matches_string_matcher_resolver() ) expectation = Expectation( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition(asrt.equals(defined_name), expected_container) ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, ) ) # ACT & ASSERT # self._check(source, ArrangementWithSds(), expectation)
def test_assignment_of_single_constant_line(self): value_str = 'value' symbol_name = 'name1' sb = SB.new_with(value_str=value_str, symbol_name=symbol_name) source = sb.lines( here_doc_lines(first_line_start='{string_type} {symbol_name} = ', marker='EOF', contents_lines=['{value_str}']) + ['following line'] ) # EXPECTATION # expected_symbol = StringConstantSymbolContext(symbol_name, value_str + '\n') expectation = Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ expected_symbol.assert_matches_definition_of_sdv ]), symbols_after_main=assert_symbol_table_is_singleton( symbol_name, expected_symbol.value.assert_matches_container_of_sdv, ), source=asrt_source.is_at_beginning_of_line(4) ) # ACT & ASSERT # INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
def test_assignment_of_single_constant_line(self): value_str = 'value' symbol_name = 'name1' sb = SB.new_with(value_str=value_str, symbol_name=symbol_name) source = sb.lines( here_doc_lines(first_line_start='{string_type} {symbol_name} = ', marker='EOF', contents_lines=['{value_str}']) + ['following line'] ) # EXPECTATION # expected_container = string_constant_container(value_str + '\n') expected_definition = SymbolDefinition(symbol_name, expected_container) expectation = Expectation( symbol_usages=asrt.matches_sequence([ vs_asrt.equals_symbol(expected_definition, ignore_source_line=True) ]), symbols_after_main=assert_symbol_table_is_singleton( symbol_name, equals_container(expected_container), ), source=asrt_source.is_at_beginning_of_line(4) ) # ACT & ASSERT # self._check(source, ArrangementWithSds(), expectation)
def test_assignment_of_single_symbol_reference(self): # ARRANGE # referred_symbol = SymbolWithReferenceSyntax('referred_symbol') name_of_defined_symbol = 'defined_symbol' sb = SB.new_with(referred_symbol=referred_symbol, name_of_defined_symbol=name_of_defined_symbol) source = sb.lines( here_doc_lines(first_line_start='{string_type} {name_of_defined_symbol} = ', marker='EOF', contents_lines=[str(referred_symbol)]) ) # EXPECTATION # expected_resolver = string_resolver_from_fragments([symbol(referred_symbol.name), constant('\n')]) container_of_expected_resolver = container(expected_resolver) expected_definition = SymbolDefinition(name_of_defined_symbol, container_of_expected_resolver) expectation = Expectation( symbol_usages=asrt.matches_sequence([ vs_asrt.equals_symbol(expected_definition, ignore_source_line=True), ]), symbols_after_main=assert_symbol_table_is_singleton( name_of_defined_symbol, equals_container(container_of_expected_resolver), ) ) # ACT & ASSERT # self._check(source, ArrangementWithSds(), expectation)
def test_successful_parse_WHEN_rhs_is_empty_THEN_result_SHOULD_be_identity_transformer(self): defined_name = 'defined_name' # ARRANGE # source = single_line_source( src('{lines_trans_type} {defined_name} = ', defined_name=defined_name), ) # EXPECTATION # expected_container = matches_container( resolved_value_equals_string_transformer(IdentityStringTransformer()) ) expectation = Expectation( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition(asrt.equals(defined_name), expected_container) ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, ) ) # ACT & ASSERT # self._check(source, ArrangementWithSds(), expectation)
def test_assignment_of_symbols_and_constant_text_within_soft_quotes(self): # ARRANGE # referred_symbol1 = SymbolWithReferenceSyntax('referred_symbol_1') referred_symbol2 = SymbolWithReferenceSyntax('referred_symbol_2') name_of_defined_symbol = 'defined_symbol' source = single_line_source('{string_type} {name} = {soft_quote}{sym_ref1} between {sym_ref2}{soft_quote}', soft_quote=SOFT_QUOTE_CHAR, name=name_of_defined_symbol, sym_ref1=referred_symbol1, sym_ref2=referred_symbol2) expected_resolver = string_resolver_from_fragments([ symbol(referred_symbol1.name), constant(' between '), symbol(referred_symbol2.name), ]) container_of_expected_resolver = container(expected_resolver) expected_definition = SymbolDefinition(name_of_defined_symbol, container_of_expected_resolver) expectation = Expectation( symbol_usages=asrt.matches_sequence([ vs_asrt.equals_symbol(expected_definition, ignore_source_line=True), ]), symbols_after_main=assert_symbol_table_is_singleton( name_of_defined_symbol, equals_container(container_of_expected_resolver), ) ) # ACT & ASSERT # self._check(source, ArrangementWithSds(), expectation)
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_assignment_of_list_with_symbol_references(self): # ARRANGE # referred_symbol_name = 'referred_symbol' expected_symbol_reference = references.reference_to__w_str_rendering( referred_symbol_name) symbol_to_assign = ListSymbolContext.of_sdv( 'the_symbol_name', sdvs.from_elements( [sdvs.symbol_element(expected_symbol_reference)])) syntax = _syntax(symbol_to_assign, ListSymbolReferenceAbsStx(referred_symbol_name)) # ACT & ASSERT # INSTRUCTION_CHECKER.check__abs_stx__layout_and_source_variants( self, syntax, Arrangement.phase_agnostic(), MultiSourceExpectation.phase_agnostic( symbol_usages=asrt.matches_sequence( [symbol_to_assign.assert_matches_definition_of_sdv]), symbols_after_main=assert_symbol_table_is_singleton( symbol_to_assign.name, symbol_to_assign.value.assert_matches_container_of_sdv, ), ), )
def test_assignment_of_list_with_symbol_references(self): symbol_name = 'the_symbol_name' referred_symbol = SymbolWithReferenceSyntax('referred_symbol') source = remaining_source(src( '{list_type} {symbol_name} = {symbol_reference} ', symbol_name=symbol_name, symbol_reference=referred_symbol, ), ['following line'], ) expected_symbol_reference = references.reference_to_any_data_type_value(referred_symbol.name) expected_resolver = lrs.from_elements([lrs.symbol_element(expected_symbol_reference)]) expected_resolver_container = container(expected_resolver) expectation = Expectation( symbol_usages=asrt.matches_sequence([ vs_asrt.equals_symbol(SymbolDefinition(symbol_name, expected_resolver_container), ignore_source_line=True) ]), symbols_after_main=assert_symbol_table_is_singleton( symbol_name, equals_container(expected_resolver_container), ), source=asrt_source.is_at_beginning_of_line(2), ) self._check(source, ArrangementWithSds(), expectation)
def test_successful_parse_of_regex(self): # ARRANGE # regex_str = 'the_regex' symbol = NameAndValue('the_symbol_name', LineMatcherConstant(False)) regex_matcher_syntax = argument_syntax.syntax_for_regex_matcher(regex_str) matcher_argument = argument_syntax.syntax_for_and([ symbol.name, regex_matcher_syntax, ]) defined_name = 'defined_name' source = remaining_source( src('{line_match_type} {defined_name} = {matcher_argument}', defined_name=defined_name, matcher_argument=matcher_argument), following_lines=['following line'], ) # EXPECTATION # the_and_matcher = LineMatcherAnd([ symbol.value, LineMatcherRegex(re.compile(regex_str)), ]) expected_container = matches_container( assertion_on_resolver= resolved_value_equals_line_matcher( the_and_matcher, references=asrt.matches_sequence([ is_line_matcher_reference_to(symbol.name), ]), symbols=SymbolTable({ symbol.name: container(LineMatcherConstantResolver(symbol.value)), }), ) ) expectation = Expectation( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition(asrt.equals(defined_name), expected_container) ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, ) ) # ACT & ASSERT # self._check(source, ArrangementWithSds(), expectation)
def test_assignment_of_single_constant_word(self): source = single_line_source('{string_type} name1 = v1') expected_definition = SymbolDefinition('name1', string_constant_container('v1')) expectation = Expectation( symbol_usages=asrt.matches_sequence([ vs_asrt.equals_symbol(expected_definition, ignore_source_line=True) ]), symbols_after_main=assert_symbol_table_is_singleton( 'name1', equals_container(string_constant_container('v1')), ) ) self._check(source, ArrangementWithSds(), expectation)
def test_successful_parse_and_application_of_non_trivial_matcher(self): # ARRANGE # defined_name = 'defined_name' expected_container = matches_container( asrt.equals(ValueType.FILES_MATCHER), type_sdv_assertions.matches_sdv_of_files_matcher() ) not_num_files_beginning_with_a_eq_1_arg = self._not_num_files_beginning_with_a_eq_1_arg() cases = [ NEA('should match', expected=matcher_assertions.is_matching_success(), actual=DirContents([ File.empty('a.x'), File.empty('a.y'), File.empty('b.x'), File.empty('b.y'), ]) ), NEA('should not match', expected=matcher_assertions.is_arbitrary_matching_failure(), actual=DirContents([ File.empty('a.x'), File.empty('b.y'), File.empty('b.x'), ]) ), ] for case in cases: source = single_line_source( src2(ValueType.FILES_MATCHER, defined_name, not_num_files_beginning_with_a_eq_1_arg), ) expectation = Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition(asrt.equals(defined_name), expected_container) ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, ), instruction_environment= AssertApplicationOfMatcherInSymbolTable(defined_name, actual_dir_contents=case.actual, expected_matcher_result=case.expected), )
class TestSuccessfulScenarios(unittest.TestCase): def test_successful_parse_of_arbitrary_matcher(self): defined_name = 'defined_name' file_name = 'the-file-name' # ARRANGE # argument_cases = [ NameAndValue('value on same line', '{files_condition}' ), NameAndValue('value on following line', '{new_line} {files_condition}' ), ] for case in argument_cases: with self.subTest(case.name): source = remaining_source( src2(ValueType.FILES_CONDITION, defined_name, case.value, files_condition=arg_syntax.FilesCondition([arg_syntax.FileCondition(file_name)])), ) # EXPECTATION # expected_container = matches_container( asrt.equals(ValueType.FILES_CONDITION), type_sdv_assertions.matches_sdv_of_files_condition_constant( primitive_value=asrt_primitive.files_matches({ PurePosixPath(file_name): asrt.is_none }) ) ) expectation = Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition(asrt.equals(defined_name), expected_container) ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, ) ) # ACT & ASSERT # INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
def test_succeed_WHEN_table_contains_the_expected_element(self): a_symbol = NameAndValue('symbol name', ASymbolTableValue('symbol value')) cases = [ ('assertion is', a_symbol, asrt.is_(a_symbol.value)), ('assertion has expected value', a_symbol, assert_string_value_equals(a_symbol.value.value)), ] for name, symbol, value_assertion in cases: with self.subTest(name=name): # ARRANGE # actual = SymbolTable({symbol.name: symbol.value}) assertion = sut.assert_symbol_table_is_singleton( symbol.name, value_assertion) # ACT # assertion.apply_without_message(self, actual)
def test_successful_parse_and_application_of_non_trivial_matcher(self): defined_name = 'defined_name' expected_container = matches_container( matches_string_matcher_resolver() ) not_num_lines_eq_1_matcher_arg = self._not_num_lines_eq_1_matcher_arg() cases = [ NEA('should match', expected=matcher_assertions.is_matching_success(), actual=lines_content([ '1st line', '2nd line', ]) ), NEA('should not match', expected=matcher_assertions.is_arbitrary_matching_failure(), actual='a single line' ), ] for case in cases: source = single_line_source( src('{string_matcher_type} {defined_name} = {matcher_argument}', defined_name=defined_name, matcher_argument=not_num_lines_eq_1_matcher_arg), ) expectation = Expectation( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition(asrt.equals(defined_name), expected_container) ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, ), assertion_on_instruction_environment= AssertApplicationOfMatcherInSymbolTable(defined_name, actual_model_contents=case.actual, expected_matcher_result=case.expected), ) with self.subTest(case.name): # ACT & ASSERT # self._check(source, ArrangementWithSds(), expectation)
def test_assignment_of_program_without_arguments(self): python_source = 'exit(72)' resolver_of_referred_program = program_resolvers.for_py_source_on_command_line(python_source) name_of_defined_symbol = 'the_symbol' referred_symbol = NameAndValue( 'PRE_EXISTING_PROGRAM_SYMBOL', resolver_of_referred_program ) symbols = SymbolTable({ referred_symbol.name: symbol_utils.container(referred_symbol.value) }) program = pgm_args.symbol_ref_command_line(sym_ref_args.sym_ref_cmd_line( referred_symbol.name)) source = multi_line_source('{program_type} {defined_symbol} = {program}', ['following line'], defined_symbol=name_of_defined_symbol, program=program) expected_symbol_container = asrt_rs.matches_container( assertion_on_resolver=asrt_resolver.matches_resolver_of_program( references=asrt.matches_sequence([ is_program_reference_to(referred_symbol.name) ]), resolved_program_value=asrt_dir_dep_val.matches_multi_dir_dependent_value( DirDependencies.NONE, lambda tcds: matches_py_source_on_cmd_line_program(python_source)), symbols=symbols )) expectation = Expectation( source=asrt_source.is_at_beginning_of_line(2), symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition( name=asrt.equals(name_of_defined_symbol), container=expected_symbol_container) ]), symbols_after_main=assert_symbol_table_is_singleton( expected_name=name_of_defined_symbol, value_assertion=expected_symbol_container, ) ) self._check(source, ArrangementWithSds(), expectation)
def test(self): instruction_argument = src('{path_type} name = component') for source in equivalent_source_variants__with_source_check(self, instruction_argument): expected_file_ref_resolver = file_ref_resolvers.constant( file_refs.of_rel_option(REL_OPTIONS_CONFIGURATION.default_option, file_refs.constant_path_part('component'))) expected_container = resolver_container(expected_file_ref_resolver) self._check(source, ArrangementWithSds(), Expectation( symbol_usages=assert_symbol_usages_is_singleton_list( vs_asrt.equals_symbol( SymbolDefinition('name', expected_container))), symbols_after_main=assert_symbol_table_is_singleton( 'name', equals_container(expected_container))) )
def test_successful_parse_of_reference(self): defined_name = 'defined_name' referenced_symbol = NameAndValue('referenced_name', ARBITRARY_RESOLVER) symbols = SymbolTable({ referenced_symbol.name: symbol_utils.container(referenced_symbol.value) }) # ARRANGE # source = single_line_source( src('{string_matcher_type} {defined_name} = {matcher_argument}', defined_name=defined_name, matcher_argument=referenced_symbol.name), ) arrangement = ArrangementWithSds() # EXPECTATION # expected_container = matches_container( matches_string_matcher_resolver( references=asrt.matches_sequence([ is_reference_to_string_matcher(referenced_symbol.name) ]), symbols=symbols) ) expectation = Expectation( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition(asrt.equals(defined_name), expected_container), ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, ) ) # ACT & ASSERT # self._check(source, arrangement, expectation)
class TestSuccessfulScenarios(unittest.TestCase): def test_successful_parse_of_arbitrary_matcher(self): defined_name = 'defined_name' # ARRANGE # argument_cases = [ NameAndValue('value on same line', '{matcher_argument}' ), NameAndValue('value on following line', '{new_line} {matcher_argument}' ), ] for case in argument_cases: with self.subTest(case.name): source = single_line_source( src2(ValueType.FILES_MATCHER, defined_name, case.value, matcher_argument=arg_syntax.arbitrary_single_line_value_that_must_not_be_quoted()), ) # EXPECTATION # expected_container = matches_container( asrt.equals(ValueType.FILES_MATCHER), type_sdv_assertions.matches_sdv_of_files_matcher() ) expectation = Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition(asrt.equals(defined_name), expected_container) ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, ) ) # ACT & ASSERT # INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
def test_assignment_of_list_with_multiple_constant_elements(self): symbol_name = 'the_symbol_name' value_without_space = 'value_without_space' value_with_space = 'value with space' expected_resolver = lrs.from_str_constants([value_without_space, value_with_space]) expected_resolver_container = container(expected_resolver) sb = SB.new_with(symbol_name=symbol_name, value_without_space=value_without_space, value_with_space=value_with_space) cases = [ SourceCase('No following lines', source=sb.single_line( '{list_type} {symbol_name} = ' '{value_without_space} {soft_quote}{value_with_space}{soft_quote} '), source_assertion=asrt_source.source_is_at_end ), SourceCase('Following lines', source=sb.lines( [ '{list_type} {symbol_name} = ' '{value_without_space} {soft_quote}{value_with_space}{soft_quote}', 'following line', ]), source_assertion=asrt_source.is_at_beginning_of_line(2) ), ] for case in cases: with self.subTest(case.name): expectation = Expectation( symbol_usages=asrt.matches_sequence([ vs_asrt.equals_symbol(SymbolDefinition(symbol_name, expected_resolver_container), ignore_source_line=True) ]), symbols_after_main=assert_symbol_table_is_singleton( symbol_name, equals_container(expected_resolver_container), ), source=case.source_assertion, ) self._check(case.source, ArrangementWithSds(), expectation)
def runTest(self): python_source = 'exit(72)' name_of_defined_symbol = 'the_symbol' referred_symbol = ProgramSymbolContext.of_sdv( 'PRE_EXISTING_PROGRAM_SYMBOL', program_sdvs.for_py_source_on_command_line(python_source)) symbols = referred_symbol.symbol_table program_abs_stx = ProgramOfSymbolReferenceAbsStx(referred_symbol.name) define_symbol_syntax = DefineSymbolWMandatoryValue( name_of_defined_symbol, ValueType.PROGRAM, program_abs_stx, ) expected_symbol_container = matches_container( asrt.equals(ValueType.PROGRAM), sdv=type_sdv_assertions.matches_sdv_of_program_constant( references=asrt.matches_sequence( [referred_symbol.reference_assertion]), primitive_value=matches_py_source_on_cmd_line_program( python_source), symbols=symbols)) expectation = MultiSourceExpectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition( name=asrt.equals(name_of_defined_symbol), container=expected_symbol_container) ]), symbols_after_main=assert_symbol_table_is_singleton( expected_name=name_of_defined_symbol, value_assertion=expected_symbol_container, )) INSTRUCTION_CHECKER.check__abs_stx__layout_and_source_variants( self, define_symbol_syntax, Arrangement.phase_agnostic(), expectation, )
def test_assignment_of_single_symbol_reference(self): # ARRANGE # referred_symbol = SymbolWithReferenceSyntax('referred_symbol') assigned_symbol = StringSymbolContext.of_sdv('defined_symbol', string_sdv_from_fragments([symbol(referred_symbol.name)])) source = single_line_source('{string_type} {name} = {symbol_reference}', name=assigned_symbol.name, symbol_reference=referred_symbol) expectation = Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ assigned_symbol.assert_matches_definition_of_sdv, ]), symbols_after_main=assert_symbol_table_is_singleton( assigned_symbol.name, assigned_symbol.value.assert_matches_container_of_sdv, ) ) # ACT & ASSERT # INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
def _expect_definition_of( defined_name: str, symbols_for_evaluation: SymbolTable, references: Assertion[Sequence[SymbolReference]], expected_contents: str, may_depend_on_external_resources: bool, ) -> Expectation[None]: sdv_expectation = type_sdv_assertions.matches_sdv( asrt.is_instance(StringSourceSdv), references=references, symbols=symbols_for_evaluation, resolved_value=asrt.anything_goes(), custom=asrt.is_instance_with( StringSourceSdv, str_src_check.execution_assertion( intgr_arr_exp.Arrangement( symbols=symbols_for_evaluation, tcds=TcdsArrangement(), ), primitive=str_src_check.primitive__const( asrt_string_source.pre_post_freeze__matches_str__const( expected_contents, may_depend_on_external_resources=may_depend_on_external_resources ) ) ) ) ) expected_container = matches_container( asrt.equals(ValueType.STRING_SOURCE), sdv_expectation, ) return Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition(asrt.equals(defined_name), expected_container), ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, ) )
def test_successful_parse(self): name_pattern = 'the name pattern' cases = [ ('empty RHS SHOULD give selection of all files', '', file_matchers.FileMatcherConstant(True), ), ('name pattern in RHS SHOULD give selection of name pattern', file_matcher_arguments(name_pattern=name_pattern), file_matchers.FileMatcherNameGlobPattern(name_pattern), ), ('file type in RHS SHOULD give selection of name pattern', file_matcher_arguments(type_match=FileType.REGULAR), file_matchers.FileMatcherType(FileType.REGULAR), ), ] # ARRANGE # defined_name = 'defined_name' for name, rhs_source, expected_file_matcher in cases: with self.subTest(name=name): source = single_line_source( src('{file_matcher_type} {defined_name} = {selector_argument}', defined_name=defined_name, selector_argument=rhs_source), ) expected_container = matches_container( resolved_value_equals_file_matcher(expected_file_matcher) ) expectation = Expectation( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition(asrt.equals(defined_name), expected_container) ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, ) ) # ACT & ASSERT # self._check(source, ArrangementWithSds(), expectation)
def test_successful_parse_and_application_of_non_trivial_matcher(self): defined_name = 'defined_name' expected_container = matches_container( asrt.equals(ValueType.STRING_MATCHER), matches_sdv_of_string_matcher()) not_num_lines_eq_1_matcher_arg = self._not_num_lines_eq_1_matcher_arg() cases = [ NEA('should match', expected=matcher_assertions.is_matching_success(), actual=lines_content([ '1st line', '2nd line', ])), NEA('should not match', expected=matcher_assertions.is_arbitrary_matching_failure(), actual='a single line'), ] for case in cases: source = single_line_source( src2(ValueType.STRING_MATCHER, defined_name, not_num_lines_eq_1_matcher_arg), ) expectation = Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition( asrt.equals(defined_name), expected_container) ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, ), instruction_environment=AssertApplicationOfMatcherInSymbolTable( self, defined_name, actual_model_contents=case.actual, expected_matcher_result=case.expected), ) with self.subTest(case.name):
def test_assignment_of_empty_list(self): list_symbol = ListSymbolContext.of_empty('the_symbol_name') syntax = _syntax(list_symbol, EmptyListAbsStx()) expectation = MultiSourceExpectation.phase_agnostic( symbol_usages=asrt.matches_sequence( [list_symbol.assert_matches_definition_of_sdv]), symbols_after_main=assert_symbol_table_is_singleton( list_symbol.name, list_symbol.value.assert_matches_container_of_sdv, ), ) INSTRUCTION_CHECKER.check__abs_stx__layout_and_source_variants( self, syntax, Arrangement.phase_agnostic(), expectation, )
def test(self): expected_defined_symbol = ConstantSuffixPathDdvSymbolContext( 'name', type_parser.REL_OPTIONS_CONFIGURATION.default_option, 'component') instruction_argument = src2(ValueType.PATH, expected_defined_symbol.name, expected_defined_symbol.path_suffix) for source in equivalent_source_variants__with_source_check__consume_last_line( self, instruction_argument): INSTRUCTION_CHECKER.check( self, source, Arrangement.phase_agnostic(), Expectation.phase_agnostic( symbol_usages=asrt.matches_singleton_sequence( expected_defined_symbol. assert_matches_definition_of_sdv), symbols_after_main=assert_symbol_table_is_singleton( 'name', expected_defined_symbol.value. assert_matches_container_of_sdv)))
def test_succeed_WHEN_table_contains_the_expected_element(self): a_symbol = NameAndValue('symbol name', ASymbolTableValue('symbol value')) cases = [ ('assertion is', a_symbol, asrt.is_(a_symbol.value) ), ('assertion has expected value', a_symbol, assert_string_value_equals(a_symbol.value.value) ), ] for name, symbol, value_assertion in cases: with self.subTest(name=name): # ARRANGE # actual = SymbolTable({symbol.name: symbol.value}) assertion = sut.assert_symbol_table_is_singleton(symbol.name, value_assertion) # ACT # assertion.apply_without_message(self, actual)
def test(self): with tmp_dir() as abs_path_of_dir_containing_last_file_base_name: fs_location_info = FileSystemLocationInfo( FileLocationInfo(abs_path_of_dir_containing_last_file_base_name)) instruction_argument = src('{path_type} name = {rel_source_file} component') for source in equivalent_source_variants__with_source_check(self, instruction_argument): expected_file_ref_resolver = file_ref_resolvers.constant( file_refs.rel_abs_path(abs_path_of_dir_containing_last_file_base_name, file_refs.constant_path_part('component'))) expected_container = resolver_container(expected_file_ref_resolver) self._check(source, ArrangementWithSds(fs_location_info=fs_location_info), Expectation( symbol_usages=assert_symbol_usages_is_singleton_list( vs_asrt.equals_symbol( SymbolDefinition('name', expected_container))), symbols_after_main=assert_symbol_table_is_singleton( 'name', equals_container(expected_container)) ) )
def test_successful_parse_of_reference(self): defined_name = 'defined_name' referenced_symbol = FilesMatcherSymbolContext.of_arbitrary_value('referenced_name') symbols = referenced_symbol.symbol_table # ARRANGE # source = single_line_source( src2(ValueType.FILES_MATCHER, defined_name, referenced_symbol.name), ) arrangement = Arrangement.phase_agnostic() # EXPECTATION # expected_container = matches_container( asrt.equals(ValueType.FILES_MATCHER), type_sdv_assertions.matches_sdv_of_files_matcher( references=asrt.matches_sequence([ referenced_symbol.reference_assertion ]), symbols=symbols) ) expectation = Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition(asrt.equals(defined_name), expected_container), ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, ) ) # ACT & ASSERT # INSTRUCTION_CHECKER.check(self, source, arrangement, expectation)
def _expect_definition_of( defined_name: str, symbols_for_evaluation: SymbolTable, model: FileSystemElements, references: Assertion[Sequence[SymbolReference]], expected_output: Assertion[pathlib.Path], ) -> Expectation[pathlib.Path]: sdv_expectation = type_sdv_assertions.matches_sdv( asrt.is_instance(FilesSourceSdv), references=references, symbols=symbols_for_evaluation, resolved_value=asrt.anything_goes(), custom=asrt.is_instance_with( FilesSourceSdv, file_src_check.execution_assertion( model, intgr_arr_exp.Arrangement( symbols=symbols_for_evaluation, tcds=TcdsArrangement(), ), ExecutionExpectation( main_result=expected_output, ) ), ) ) expected_container = matches_container( asrt.equals(ValueType.FILES_SOURCE), sdv_expectation, ) return Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition(asrt.equals(defined_name), expected_container), ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, ) )
def test_assignment_of_single_symbol_reference(self): # ARRANGE # referred_symbol = SymbolWithReferenceSyntax('referred_symbol') name_of_defined_symbol = 'defined_symbol' source = single_line_source('{string_type} {name} = {symbol_reference}', name=name_of_defined_symbol, symbol_reference=referred_symbol) expected_resolver = string_resolver_from_fragments([symbol(referred_symbol.name)]) container_of_expected_resolver = container(expected_resolver) expected_definition = SymbolDefinition(name_of_defined_symbol, container_of_expected_resolver) expectation = Expectation( symbol_usages=asrt.matches_sequence([ vs_asrt.equals_symbol(expected_definition, ignore_source_line=True), ]), symbols_after_main=assert_symbol_table_is_singleton( name_of_defined_symbol, equals_container(container_of_expected_resolver), ) ) # ACT & ASSERT # self._check(source, ArrangementWithSds(), expectation)
def test(self): instruction_argument = src('{path_type} ASSIGNED_NAME = {rel_symbol} REFERENCED_SYMBOL component') for source in equivalent_source_variants__with_source_check(self, instruction_argument): expected_file_ref_resolver = file_ref_resolvers.rel_symbol( SymbolReference('REFERENCED_SYMBOL', ReferenceRestrictionsOnDirectAndIndirect(FileRefRelativityRestriction( REL_OPTIONS_CONFIGURATION.accepted_relativity_variants))), path_part_resolvers.from_constant_str('component')) expected_container = resolver_container(expected_file_ref_resolver) self._check(source, ArrangementWithSds(), Expectation( symbol_usages=asrt.matches_sequence([ vs_asrt.equals_symbol( SymbolDefinition('ASSIGNED_NAME', expected_container), ignore_source_line=True) ]), symbols_after_main=assert_symbol_table_is_singleton( 'ASSIGNED_NAME', equals_container(expected_container))) )
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_assignment_of_single_constant_word(self): argument_cases = [ NameAndValue('value on same line', '{string_type} name1 = v1' ), NameAndValue('value on following line', '{string_type} name1 = {new_line} v1' ), ] for argument_case in argument_cases: with self.subTest(argument_case.name): source = arbitrary_string_source(argument_case.value) expected_symbol = StringConstantSymbolContext('name1', 'v1') expectation = Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ expected_symbol.assert_matches_definition_of_sdv ]), symbols_after_main=assert_symbol_table_is_singleton( 'name1', expected_symbol.value.assert_matches_container_of_sdv, ) ) INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
def test_successful_parse(self): name_pattern = 'the name pattern' non_matching_name = 'non-matching name' glob_pattern_arguments = file_matcher_arguments( name_pattern=name_pattern) sut_parser = parse_file_matcher.parsers().full expected_glob_pattern_matcher_sdv = sut_parser.parse( remaining_source(glob_pattern_arguments)) expected_glob_pattern_matcher = resolving_helper__fake( ).resolve_matcher(expected_glob_pattern_matcher_sdv) cases = [ NIE( 'name pattern in RHS SHOULD give selection of name pattern', asrt_matcher.is_equivalent_to(expected_glob_pattern_matcher, [ asrt_matcher.ModelInfo( file_matcher_models.FileMatcherModelForDescribedPath( described_path.new_primitive( pathlib.Path(name_pattern)), )), asrt_matcher.ModelInfo( file_matcher_models.FileMatcherModelForDescribedPath( described_path.new_primitive( pathlib.Path(non_matching_name)), )), ]), glob_pattern_arguments, ), ] # ARRANGE # defined_name = 'defined_name' argument_cases = [ NameAndValue('value on same line', '{selector_argument}'), NameAndValue('value on following line', '{new_line} {selector_argument}'), ] for case in cases: for argument_case in argument_cases: with self.subTest(case.name, arguments=argument_case.name): source = single_line_source( src2(ValueType.FILE_MATCHER, defined_name, argument_case.value, selector_argument=case.input_value), ) expected_container = matches_container( asrt.equals(ValueType.FILE_MATCHER), type_sdv_assertions.matches_sdv_of_file_matcher( references=asrt.is_empty_sequence, primitive_value=case.expected_value)) expectation = Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition( asrt.equals(defined_name), expected_container) ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, )) # ACT & ASSERT # INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
def test_successful_parse_of_regex(self): # ARRANGE # regex_str = 'the_regex' models_for_equivalence_check = [ asrt_matcher.ModelInfo((1, regex_str)), asrt_matcher.ModelInfo((2, 'before' + regex_str + 'after')), asrt_matcher.ModelInfo((1, 'no match')), ] symbol = LineMatcherSymbolContext.of_sdv('the_symbol_name', CONSTANT_TRUE_MATCHER_SDV) regex_matcher_syntax = argument_syntax.syntax_for_regex_matcher( regex_str) matcher_argument = argument_syntax.syntax_for_and([ symbol.name, regex_matcher_syntax, ]) defined_name = 'defined_name' argument_cases = [ NameAndValue('value on same line', '{matcher_argument}'), NameAndValue('value on following line', '{new_line} {matcher_argument}'), ] for argument_case in argument_cases: with self.subTest(argument_case.name): source = remaining_source( src2(ValueType.LINE_MATCHER, defined_name, argument_case.value, matcher_argument=matcher_argument), following_lines=['following line'], ) # EXPECTATION # symbol_table = symbol.symbol_table expected_matcher_sdv = parse_line_matcher.parsers().full.parse( remaining_source(matcher_argument)) expected_matcher = resolving_helper( symbol_table).resolve_matcher(expected_matcher_sdv) expected_container = matches_container( asrt.equals(ValueType.LINE_MATCHER), sdv=type_sdv_assertions.matches_sdv_of_line_matcher( references=asrt.matches_sequence([ is_reference_to_line_matcher(symbol.name), ]), primitive_value=asrt_matcher.is_equivalent_to( expected_matcher, models_for_equivalence_check), symbols=symbol_table, )) expectation = Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition( asrt.equals(defined_name), expected_container) ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, )) # ACT & ASSERT # INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
def test_successful_parse_of_sequence(self): # ARRANGE # regex_str = 'the_regex' replacement_str = 'the_replacement' symbol = StringTransformerSymbolContext.of_primitive( 'the_symbol_name', string_transformers.must_not_be_used() ) replace_transformer_syntax = argument_syntax.syntax_for_replace_transformer(regex_str, replacement_str) defined_name = 'defined_name' cases = [ SourceCase('Expression on single line', source= remaining_source( src2(ValueType.STRING_TRANSFORMER, defined_name, argument_syntax.syntax_for_sequence_of_transformers([ symbol.name, replace_transformer_syntax, ])), following_lines=['following line'], ), source_assertion=asrt_source.is_at_beginning_of_line(2) ), SourceCase('Expression on following line', source= remaining_source( src2(ValueType.STRING_TRANSFORMER, defined_name, '{new_line} {transformer_argument}', transformer_argument=argument_syntax.syntax_for_sequence_of_transformers([ symbol.name, replace_transformer_syntax, ])), following_lines=['following line'], ), source_assertion=asrt_source.is_at_beginning_of_line(3) ), SourceCase('1st expr on first line followed by operator, 2nd expr on next line', source= remaining_source( src2(ValueType.STRING_TRANSFORMER, defined_name, '{the_symbol_name} {sequence_operator}', the_symbol_name=symbol.name, sequence_operator=SEQUENCE_OPERATOR_NAME), following_lines=[replace_transformer_syntax], ), source_assertion=asrt_source.source_is_at_end ), SourceCase('1st expr on first line followed by operator, 2nd expr on next line, non-exr on 3rd line', source= remaining_source( src2(ValueType.STRING_TRANSFORMER, defined_name, '{the_symbol_name} {sequence_operator}', the_symbol_name=symbol.name, sequence_operator=SEQUENCE_OPERATOR_NAME), following_lines=[replace_transformer_syntax, 'following line'], ), source_assertion=asrt_source.is_at_beginning_of_line(3) ), ] # EXPECTATION # expected_container = matches_container( asrt.equals(ValueType.STRING_TRANSFORMER), sdv=matches_sdv_of_string_transformer_constant( references=asrt.matches_sequence([ is_reference_to_string_transformer(symbol.name), ]), primitive_value=asrt_string_transformer.is_identity_transformer(False), symbols=symbol.symbol_table, ) ) for source_case in cases: with self.subTest(source_case.name): expectation = Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition(asrt.equals(defined_name), expected_container) ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, ), source=source_case.source_assertion ) # ACT & ASSERT # INSTRUCTION_CHECKER.check(self, source_case.source, Arrangement.phase_agnostic(), expectation)
def test_successful_parse_of_sequence(self): # ARRANGE # regex_str = 'the_regex' replacement_str = 'the_replacement' symbol = NameAndValue('the_symbol_name', transformers.CustomStringTransformerTestImpl()) replace_transformer_syntax = argument_syntax.syntax_for_replace_transformer(regex_str, replacement_str) defined_name = 'defined_name' cases = [ SourceCase('Expression on single line', source= remaining_source( src('{lines_trans_type} {defined_name} = {transformer_argument}', defined_name=defined_name, transformer_argument=argument_syntax.syntax_for_sequence_of_transformers([ symbol.name, replace_transformer_syntax, ])), following_lines=['following line'], ), source_assertion=asrt_source.is_at_beginning_of_line(2) ), SourceCase('1st expr on first line followed by operator, 2nd expr on next line', source= remaining_source( src('{lines_trans_type} {defined_name} = {symbol_name} {sequence_operator}', defined_name=defined_name, symbol_name=symbol.name, sequence_operator=SEQUENCE_OPERATOR_NAME), following_lines=[replace_transformer_syntax], ), source_assertion=asrt_source.source_is_at_end ), SourceCase('1st expr on first line followed by operator, 2nd expr on next line, non-exr on 3rd line', source= remaining_source( src('{lines_trans_type} {defined_name} = {symbol_name} {sequence_operator}', defined_name=defined_name, symbol_name=symbol.name, sequence_operator=SEQUENCE_OPERATOR_NAME), following_lines=[replace_transformer_syntax, 'following line'], ), source_assertion=asrt_source.is_at_beginning_of_line(3) ), ] # EXPECTATION # the_sequence_transformer = SequenceStringTransformer([ symbol.value, transformers.replace_transformer(regex_str, replacement_str), ]) expected_container = matches_container( assertion_on_resolver= resolved_value_equals_string_transformer( the_sequence_transformer, references=asrt.matches_sequence([ is_reference_to_string_transformer(symbol.name), ]), symbols=SymbolTable({ symbol.name: container(StringTransformerConstant(symbol.value)), }), ) ) for source_case in cases: with self.subTest(source_case.name): expectation = Expectation( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition(asrt.equals(defined_name), expected_container) ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, ), source=source_case.source_assertion ) # ACT & ASSERT # self._check(source_case.source, ArrangementWithSds(), expectation)