def test_invalid_suite_syntax(self): suite_file_contents_with_invalid_syntax = lines_content([ SectionName('nonExistingSection').syntax, ]) valid_empty_case_file = empty_file('empty-valid.case') for suite_case in suite_cases('invalid-syntax.suite'): with self.subTest(suite_case.name): test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.arguments( suite_case.value.suite_arguments + [valid_empty_case_file.name] ), arrangement= Arrangement( cwd_contents=DirContents([ suite_case.value.suite_file(suite_file_contents_with_invalid_syntax), valid_empty_case_file, ]) ), expectation= asrt_proc_result.is_result_for_empty_stdout( exit_values.NO_EXECUTION__SYNTAX_ERROR.exit_code ) )
def test_invalid_syntax_of_act_phase(self): file_with_invalid_syntax = File( 'invalid-syntax.case', lines_content([ phase_names.ACT.syntax, 'invalid contents', ])) test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.arguments([file_with_invalid_syntax.name]), arrangement= Arrangement( main_program_config=sym_def.main_program_config( ActorThatRaisesParseException() ), cwd_contents=DirContents([ file_with_invalid_syntax, ]) ), expectation= asrt_proc_result.is_result_for_empty_stdout( exit_values.EXECUTION__VALIDATION_ERROR.exit_code ) )
def test_preprocessor_that_fails(self): valid_file_without_symbol_definitions = empty_file('valid.case') py_pgm_that_fails_unconditionally = File( 'preprocessor.py', preprocessor_utils.PREPROCESSOR_THAT_FAILS_UNCONDITIONALLY__PY_SRC ) test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.py_preprocessing_and_case(py_pgm_that_fails_unconditionally.name, valid_file_without_symbol_definitions.name), arrangement= Arrangement( cwd_contents=DirContents([ py_pgm_that_fails_unconditionally, valid_file_without_symbol_definitions, ]) ), expectation= asrt_proc_result.is_result_for_empty_stdout( exit_values.NO_EXECUTION__PRE_PROCESS_ERROR.exit_code ) )
def test_invalid_case_file(self): case_file_arg = 'test.case' cases = [ NEA('file does not exist', expected= asrt_proc_result.is_result_for_empty_stdout(exit_codes.EXIT_INVALID_USAGE), actual= DirContents([]) ), NEA('file is a directory', expected= asrt_proc_result.is_result_for_failure_exit_value_on_stderr( exit_values.NO_EXECUTION__FILE_ACCESS_ERROR ), actual= DirContents([ empty_dir(case_file_arg) ]) ), ] for case in cases: with self.subTest(case.name): test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.arguments([case_file_arg]), arrangement= Arrangement( cwd_contents=case.actual ), expectation= case.expected)
def test(self): name_of_existing_symbol = 'STRING_SYMBOL' case_with_single_def = File('test.case', lines_content([ phase_names.SETUP.syntax, sym_def.define_string(name_of_existing_symbol, 'value'), ])) expected_first_line = output.list_of([output.SymbolReport(name_of_existing_symbol, ValueType.STRING, num_refs=0)]).rstrip() test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.individual__definition( case_with_single_def.name, name_of_existing_symbol, ), arrangement= Arrangement( cwd_contents=DirContents([ case_with_single_def, ]), main_program_config=sym_def.main_program_config(), ), expectation= asrt_proc_result.sub_process_result( exitcode=asrt.equals(exit_codes.EXIT_OK), stdout=asrt_str.first_line(asrt.equals(expected_first_line))) )
def test(self): name_of_existing_symbol = 'STRING_SYMBOL' not_the_name_of_an_existing_symbol = 'NON_EXISTING_SYMBOL' case_with_single_def = File('test.case', lines_content([ phase_names.SETUP.syntax, sym_def.define_string(name_of_existing_symbol, 'value'), ])) test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.individual__definition( case_with_single_def.name, not_the_name_of_an_existing_symbol, ), arrangement= Arrangement( cwd_contents=DirContents([ case_with_single_def, ]), main_program_config=sym_def.main_program_config(), ), expectation= asrt_proc_result.is_result_for_empty_stdout( exit_values.EXECUTION__HARD_ERROR.exit_code ) )
def test_single_definition_in_default_suite_file(self): symbol_name = 'STRING_SYMBOL' suite_with_single_def = File( DEFAULT_SUITE_FILE, lines_content([ phase_names.SETUP.syntax, sym_def.define_string(symbol_name, 'value'), ])) dir_arg = Dir('a-dir', [suite_with_single_def]) test_with_files_in_tmp_dir.check( self, command_line_arguments=symbol_args.arguments__suite([dir_arg.name ]), arrangement=Arrangement( cwd_contents=DirContents([ dir_arg, ]), main_program_config=sym_def.main_program_config(), ), expectation=asrt_proc_result.sub_process_result( exitcode=asrt.equals(exit_codes.EXIT_OK), stdout=asrt.equals( output.list_of([ output.SymbolSummary(symbol_name, ValueType.STRING, num_refs=0), ])), ))
def test_definition_and_reference_in_definition(self): leaf_name = 'LEAF_SYMBOL_SYMBOL' referrer_name = 'REFERRER_SYMBOL' case_with_single_def = File( 'test.case', lines_content([ phase_names.SETUP.syntax, sym_def.define_string(leaf_name, 'value'), sym_def.define_string(referrer_name, symbol_reference_syntax_for_name(leaf_name)), ])) test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.arguments([case_with_single_def.name]), arrangement= Arrangement( cwd_contents=DirContents([ case_with_single_def, ]), main_program_config=sym_def.main_program_config(), ), expectation= asrt_proc_result.sub_process_result( exitcode=asrt.equals(exit_codes.EXIT_OK), stdout=asrt.equals(output.list_of([ output.SymbolReport(leaf_name, ValueType.STRING, num_refs=1), output.SymbolReport(referrer_name, ValueType.STRING, num_refs=0), ])), ) )
def test_invalid_suite_file(self): case_file = empty_file('test.case') suite_file_name = 'test.suite' cases = [ NameAndValue('file does not exist', [] ), NameAndValue('file is a directory', [ empty_dir(suite_file_name) ]), ] for case in cases: with self.subTest(case.name): test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.arguments( symbol_args.explicit_suite_and_case( suite_file_name, case_file.name, ) ), arrangement= Arrangement( cwd_contents=DirContents( case.value + [case_file] ) ), expectation= asrt_proc_result.is_result_for_empty_stdout( exit_codes.EXIT_INVALID_USAGE ) )
def test_missing_test_case_file_argument(self): test_with_files_in_tmp_dir.check( self, symbol_args.arguments([]), Arrangement(), asrt_proc_result.is_result_for_empty_stdout( exit_codes.EXIT_INVALID_USAGE ) )
def test_file_is_dir_that_do_not_contain_default_suite_file(self): # ARRANGE # a_dir = Dir.empty('dir') test_with_files_in_tmp_dir.check( self, symbol_args.arguments__suite([a_dir.name]), arrangement=Arrangement(cwd_contents=DirContents([a_dir])), expectation=asrt_proc_result.is_result_for_empty_stdout( exit_codes.EXIT_INVALID_USAGE))
def test_definition_in_suite_and_case(self): # ARRANGE # symbol_in_suite = 'SUITE_STRING_SYMBOL' symbol_in_case__before_preproc = 'CASE_STRING_SYMBOL__BEFORE_PRE_PROC' symbol_in_case__after_preproc = 'CASE_STRING_SYMBOL' suite_with_preprocessor = File( 'with-preprocessor.suite', lines_content([ section_names.CONFIGURATION.syntax, suite_instructions.set_search_replace_preprocessor( symbol_in_case__before_preproc, symbol_in_case__after_preproc ), phase_names.SETUP.syntax, sym_def.define_string(symbol_in_suite, 'suite-value'), ]) ) case_with_single_def = File( 'test.case', lines_content([ phase_names.SETUP.syntax, sym_def.define_string(symbol_in_case__before_preproc, 'case-value'), ])) # ACT & ASSERT # test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.explicit_suite_and_case(suite_with_preprocessor.name, case_with_single_def.name), arrangement= Arrangement( cwd_contents=DirContents([ suite_with_preprocessor, case_with_single_def, ]), main_program_config=sym_def.main_program_config(), ), expectation= asrt_proc_result.sub_process_result( exitcode=asrt.equals(exit_codes.EXIT_OK), stdout=asrt.equals(output.list_of([ output.SymbolReport(symbol_in_suite, ValueType.STRING, num_refs=0), output.SymbolReport(symbol_in_case__after_preproc, ValueType.STRING, num_refs=0), ])), ) )
def test_definition_in_suite_and_case(self): # ARRANGE # symbol_in_suite = 'SUITE_STRING_SYMBOL' symbol_in_case__before_preproc = 'CASE_STRING_SYMBOL__BEFORE_PRE_PROC' symbol_in_case__after_preproc = 'CASE_STRING_SYMBOL' suite_with_preprocessor = File( 'with-preprocessor.suite', lines_content([ section_names.CONFIGURATION.syntax, suite_instructions.set_search_replace_preprocessor( symbol_in_case__before_preproc, symbol_in_case__after_preproc), phase_names.SETUP.syntax, sym_def.define_string(symbol_in_suite, 'suite-value'), ])) case_with_single_def = File( 'test.case', lines_content([ phase_names.SETUP.syntax, sym_def.define_string(symbol_in_case__before_preproc, 'case-value'), ])) # ACT & ASSERT # test_with_files_in_tmp_dir.check( self, command_line_arguments=symbol_args.explicit_suite_and_case( suite_with_preprocessor.name, case_with_single_def.name), arrangement=Arrangement( cwd_contents=DirContents([ suite_with_preprocessor, case_with_single_def, ]), main_program_config=sym_def.main_program_config(), ), expectation=asrt_proc_result.sub_process_result( exitcode=asrt.equals(exit_codes.EXIT_OK), stdout=asrt.equals( output.list_of([ output.SymbolSummary(symbol_in_suite, ValueType.STRING, num_refs=0), output.SymbolSummary(symbol_in_case__after_preproc, ValueType.STRING, num_refs=0), ])), ))
def test_invalid_type_of_file_arguments(self): # ARRANGE # a_dir = Dir.empty('a-dir') test_with_files_in_tmp_dir.check( self, symbol_args.arguments([a_dir.name]), arrangement= Arrangement( cwd_contents=DirContents([a_dir]) ), expectation= asrt_proc_result.is_result_for_exit_value_on_stderr_and_empty_stdout( exit_values.NO_EXECUTION__FILE_ACCESS_ERROR, contents_after_exit_value_allowed=True, ) )
def test_preprocessor_that_fails_with_no_output(self): valid_successful_case = File.empty('valid.case') py_pgm_that_fails_unconditionally = File( 'preprocessor.py', preprocessor_utils.PREPROCESSOR_THAT_FAILS_UNCONDITIONALLY__PY_SRC) test_with_files_in_tmp_dir.check( self, command_line_arguments=cli_arguments.py_preprocessing_and_case( py_pgm_that_fails_unconditionally.name, valid_successful_case.name), arrangement=Arrangement(cwd_contents=DirContents([ py_pgm_that_fails_unconditionally, valid_successful_case, ])), expectation=asrt_proc_result.is_result_for_exit_value( exit_values.NO_EXECUTION__PRE_PROCESS_ERROR))
def test_empty_files(self): empty_suite_file_contents = '' valid_empty_case_file = File.empty('empty-valid.case') for suite_case in suite_cases('empty.suite'): with self.subTest(suite_case.name): test_with_files_in_tmp_dir.check( self, command_line_arguments=symbol_args.arguments( suite_case.value.suite_arguments + [valid_empty_case_file.name]), arrangement=Arrangement(cwd_contents=DirContents([ suite_case.value.suite_file(empty_suite_file_contents), valid_empty_case_file, ])), expectation=asrt_proc_result.is_result_for_empty_stdout( exit_codes.EXIT_OK))
def test_multiple_definition(self): setup_symbol_name = 'SETUP_SYMBOL' before_assert_symbol_name = 'BEFORE_ASSERT_SYMBOL' assert_symbol_name = 'ASSERT_SYMBOL' cleanup_symbol_name = 'CLEANUP_SYMBOL' case_with_one_def_per_phase = File( 'test.case', lines_content([ phase_names.SETUP.syntax, sym_def.define_string(setup_symbol_name, setup_symbol_name + 'value'), phase_names.BEFORE_ASSERT.syntax, sym_def.define_string(before_assert_symbol_name, before_assert_symbol_name + 'value'), phase_names.ASSERT.syntax, sym_def.define_string(assert_symbol_name, assert_symbol_name + 'value'), phase_names.CLEANUP.syntax, sym_def.define_string(cleanup_symbol_name, cleanup_symbol_name + 'value'), ])) test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.arguments([case_with_one_def_per_phase.name]), arrangement= Arrangement( cwd_contents=DirContents([ case_with_one_def_per_phase, ]), main_program_config=sym_def.main_program_config(), ), expectation= asrt_proc_result.sub_process_result( exitcode=asrt.equals(exit_codes.EXIT_OK), stdout=asrt.equals(output.list_of([ output.SymbolReport(setup_symbol_name, ValueType.STRING, num_refs=0), output.SymbolReport(before_assert_symbol_name, ValueType.STRING, num_refs=0), output.SymbolReport(assert_symbol_name, ValueType.STRING, num_refs=0), output.SymbolReport(cleanup_symbol_name, ValueType.STRING, num_refs=0), ])), ) )
def test_preprocessor_that_fails(self): valid_file_without_symbol_definitions = File.empty('valid.case') py_pgm_that_fails_unconditionally = File( 'preprocessor.py', preprocessor_utils.PREPROCESSOR_THAT_FAILS_UNCONDITIONALLY__PY_SRC) test_with_files_in_tmp_dir.check( self, command_line_arguments=symbol_args.py_preprocessing_and_case( py_pgm_that_fails_unconditionally.name, valid_file_without_symbol_definitions.name), arrangement=Arrangement(cwd_contents=DirContents([ py_pgm_that_fails_unconditionally, valid_file_without_symbol_definitions, ])), expectation=asrt_proc_result.is_result_for_empty_stdout( exit_values.NO_EXECUTION__PRE_PROCESS_ERROR.exit_code))
def check_case_and_suite(put: unittest.TestCase, symbol_command_arguments: List[str], arrangement: Arrangement, expectation: Assertion[SubProcessResult]): """ Runs one test with arguments for test-case and one for test-suite. Adds (prepends) command line arguments for triggering the "symbol" command. :param symbol_command_arguments: Command line arguments except those that specifies the "symbol" command. """ for source_type_case in _SOURCE_TYPE_CASES: with put.subTest(source_type=source_type_case.name, arguments=symbol_command_arguments): test_with_files_in_tmp_dir.check(put, source_type_case.value(symbol_command_arguments), arrangement, expectation)
def test_empty_file(self): emtpy_test_case_file = empty_file('empty.case') test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.arguments([emtpy_test_case_file.name]), arrangement= Arrangement( cwd_contents=DirContents([ emtpy_test_case_file, ]) ), expectation= asrt_proc_result.is_result_for_empty_stdout( exit_codes.EXIT_OK ) )
def test_invalid_syntax(self): file_with_invalid_syntax = File( 'invalid-syntax.case', lines_content([ SectionName('nonExistingSection').syntax, ])) test_with_files_in_tmp_dir.check( self, symbol_args.arguments([file_with_invalid_syntax.name]), Arrangement( cwd_contents=DirContents([ file_with_invalid_syntax, ]) ), asrt_proc_result.is_result_for_empty_stdout( exit_values.NO_EXECUTION__SYNTAX_ERROR.exit_code ) )
def test_superfluous_arguments(self): case_file = empty_file('test.case') test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.individual__references( case_file.name, 'symbol_name', ) + ['superfluous'], arrangement= Arrangement( cwd_contents=DirContents([case_file]) ), expectation= asrt_proc_result.is_result_for_empty_stdout( exit_codes.EXIT_INVALID_USAGE ) )
def test_invalid_symbol_name(self): case_file = empty_file('test.case') test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.individual__definition( case_file.name, NOT_A_VALID_SYMBOL_NAME, ), arrangement= Arrangement( cwd_contents=DirContents([case_file]) ), expectation= asrt_proc_result.is_result_for_empty_stdout( exit_codes.EXIT_INVALID_USAGE ) )
def test_definition_in_suite_and_case(self): symbol_in_suite_name = 'SUITE_SYMBOL' symbol_in_case_name = 'CASE_SYMBOL' suite_with_single_def = lines_content([ section_names.CASE__SETUP.syntax, sym_def.define_string(symbol_in_suite_name, 'value'), ]) case_with_single_def = File( 'test.case', lines_content([ phase_names.SETUP.syntax, sym_def.define_string(symbol_in_case_name, 'value'), ])) for suite_case in suite_cases('single-definition.suite'): with self.subTest(suite_case.name): test_with_files_in_tmp_dir.check( self, command_line_arguments=symbol_args.arguments( suite_case.value.suite_arguments + [case_with_single_def.name]), arrangement=Arrangement( cwd_contents=DirContents([ suite_case.value.suite_file(suite_with_single_def), case_with_single_def, ]), main_program_config=sym_def.main_program_config(), ), expectation=asrt_proc_result.sub_process_result( exitcode=asrt.equals(exit_codes.EXIT_OK), stdout=asrt.equals( output.list_of([ output.SymbolSummary(symbol_in_suite_name, ValueType.STRING, num_refs=0), output.SymbolSummary(symbol_in_case_name, ValueType.STRING, num_refs=0), ])), ))
def test_invalid_suite_syntax(self): suite_file_contents_with_invalid_syntax = lines_content([ SectionName('nonExistingSection').syntax, ]) valid_empty_case_file = File.empty('empty-valid.case') for suite_case in suite_cases('invalid-syntax.suite'): with self.subTest(suite_case.name): test_with_files_in_tmp_dir.check( self, command_line_arguments=symbol_args.arguments( suite_case.value.suite_arguments + [valid_empty_case_file.name]), arrangement=Arrangement(cwd_contents=DirContents([ suite_case.value.suite_file( suite_file_contents_with_invalid_syntax), valid_empty_case_file, ])), expectation=asrt_proc_result.is_result_for_empty_stdout( exit_values.NO_EXECUTION__SYNTAX_ERROR.exit_code))
def test_invalid_option(self): case_file = empty_file('test.case') test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.arguments([ case_file.name, 'symbol_name', short_and_long_option_syntax.long_syntax('invalid'), ]), arrangement= Arrangement( cwd_contents=DirContents([case_file]) ), expectation= asrt_proc_result.is_result_for_empty_stdout( exit_codes.EXIT_INVALID_USAGE ) )
def test_invalid_suite_file(self): case_file = File.empty('test.case') suite_file_name = 'test.suite' cases = [ NameAndValue('file does not exist', []), NameAndValue('file is a directory', [Dir.empty(suite_file_name)]), ] for case in cases: with self.subTest(case.name): test_with_files_in_tmp_dir.check( self, command_line_arguments=symbol_args.arguments( symbol_args.explicit_suite_and_case( suite_file_name, case_file.name, )), arrangement=Arrangement( cwd_contents=DirContents(case.value + [case_file])), expectation=asrt_proc_result.is_result_for_empty_stdout( exit_codes.EXIT_INVALID_USAGE))
def test_single_reference_in_act_phase(self): name_of_existing_symbol = 'STRING_SYMBOL' reference_source = sym_def.reference_to(name_of_existing_symbol, ValueType.STRING) case_with_single_def = File('test.case', lines_content([ phase_names.SETUP.syntax, sym_def.define_string(name_of_existing_symbol, 'value'), phase_names.ACT.syntax, reference_source, ])) expected_reference_output = output.Reference( phase_identifier.ACT, None, [ reference_source, ] ) test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.individual__references( case_with_single_def.name, name_of_existing_symbol, ), arrangement= Arrangement( cwd_contents=DirContents([ case_with_single_def, ]), main_program_config=sym_def.main_program_config(), ), expectation= asrt_proc_result.sub_process_result( exitcode=asrt.equals(exit_codes.EXIT_OK), stdout=asrt.equals(lines_content(expected_reference_output.output_lines())) ) )
def test_invalid_case_file(self): case_file_arg = 'test.case' cases = [ NEA('file does not exist', expected=asrt_proc_result.is_result_for_empty_stdout( exit_codes.EXIT_INVALID_USAGE), actual=DirContents([])), NEA('file is a directory', expected=asrt_proc_result. is_result_for_failure_exit_value_on_stderr( exit_values.NO_EXECUTION__FILE_ACCESS_ERROR), actual=DirContents([Dir.empty(case_file_arg)])), ] for case in cases: with self.subTest(case.name): test_with_files_in_tmp_dir.check( self, command_line_arguments=symbol_args.arguments( [case_file_arg]), arrangement=Arrangement(cwd_contents=case.actual), expectation=case.expected)
def test_definition_in_suite_and_case(self): symbol_in_suite_name = 'SUITE_SYMBOL' symbol_in_case_name = 'CASE_SYMBOL' suite_with_single_def = lines_content([ section_names.CASE__SETUP.syntax, sym_def.define_string(symbol_in_suite_name, 'value'), ]) case_with_single_def = File('test.case', lines_content([ phase_names.SETUP.syntax, sym_def.define_string(symbol_in_case_name, 'value'), ])) for suite_case in suite_cases('single-definition.suite'): with self.subTest(suite_case.name): test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.arguments(suite_case.value.suite_arguments + [case_with_single_def.name]), arrangement= Arrangement( cwd_contents=DirContents([ suite_case.value.suite_file(suite_with_single_def), case_with_single_def, ]), main_program_config=sym_def.main_program_config(), ), expectation= asrt_proc_result.sub_process_result( exitcode=asrt.equals(exit_codes.EXIT_OK), stdout=asrt.equals(output.list_of([ output.SymbolReport(symbol_in_suite_name, ValueType.STRING, num_refs=0), output.SymbolReport(symbol_in_case_name, ValueType.STRING, num_refs=0), ])), ) )
def test_single_definition(self): symbol_name__before_preproc = 'STRING_SYMBOL__BEFORE_PRE_PROC' symbol_name__after_preproc = 'STRING_SYMBOL' py_pgm_that_replaces_symbol_name = File( 'replace.py', preprocessor_utils.SEARCH_REPLACE_PREPROCESSOR__PY_SRC) case_with_single_def = File( 'test.case', lines_content([ phase_names.SETUP.syntax, sym_def.define_string(symbol_name__before_preproc, 'value'), ])) test_with_files_in_tmp_dir.check( self, command_line_arguments=symbol_args. py_search_replace_preprocessing_and_case( py_pgm_that_replaces_symbol_name.name, symbol_name__before_preproc, symbol_name__after_preproc, case_with_single_def.name), arrangement=Arrangement( cwd_contents=DirContents([ py_pgm_that_replaces_symbol_name, case_with_single_def, ]), main_program_config=sym_def.main_program_config(), ), expectation=asrt_proc_result.sub_process_result( exitcode=asrt.equals(exit_codes.EXIT_OK), stdout=asrt.equals( output.list_of([ output.SymbolSummary(symbol_name__after_preproc, ValueType.STRING, num_refs=0), ])), ))
def test_single_definition(self): symbol_name__before_preproc = 'STRING_SYMBOL__BEFORE_PRE_PROC' symbol_name__after_preproc = 'STRING_SYMBOL' py_pgm_that_replaces_symbol_name = File( 'replace.py', preprocessor_utils.SEARCH_REPLACE_PREPROCESSOR__PY_SRC ) case_with_single_def = File('test.case', lines_content([ phase_names.SETUP.syntax, sym_def.define_string(symbol_name__before_preproc, 'value'), ])) test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.py_search_replace_preprocessing_and_case(py_pgm_that_replaces_symbol_name.name, symbol_name__before_preproc, symbol_name__after_preproc, case_with_single_def.name), arrangement= Arrangement( cwd_contents=DirContents([ py_pgm_that_replaces_symbol_name, case_with_single_def, ]), main_program_config=sym_def.main_program_config(), ), expectation= asrt_proc_result.sub_process_result( exitcode=asrt.equals(exit_codes.EXIT_OK), stdout=asrt.equals(output.list_of([ output.SymbolReport(symbol_name__after_preproc, ValueType.STRING, num_refs=0), ])), ) )
def test_preprocessor_that_fails_with_no_output(self): valid_successful_case = empty_file('valid.case') py_pgm_that_fails_unconditionally = File( 'preprocessor.py', preprocessor_utils.PREPROCESSOR_THAT_FAILS_UNCONDITIONALLY__PY_SRC ) test_with_files_in_tmp_dir.check( self, command_line_arguments= cli_arguments.py_preprocessing_and_case(py_pgm_that_fails_unconditionally.name, valid_successful_case.name), arrangement= Arrangement( cwd_contents=DirContents([ py_pgm_that_fails_unconditionally, valid_successful_case, ]) ), expectation= asrt_proc_result.is_result_for_exit_value( exit_values.NO_EXECUTION__PRE_PROCESS_ERROR ) )
def test_empty_files(self): empty_suite_file_contents = '' valid_empty_case_file = empty_file('empty-valid.case') for suite_case in suite_cases('empty.suite'): with self.subTest(suite_case.name): test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.arguments( suite_case.value.suite_arguments + [valid_empty_case_file.name] ), arrangement= Arrangement( cwd_contents=DirContents([ suite_case.value.suite_file(empty_suite_file_contents), valid_empty_case_file, ]) ), expectation= asrt_proc_result.is_result_for_empty_stdout( exit_codes.EXIT_OK ) )
def test_missing_test_case_file_argument(self): test_with_files_in_tmp_dir.check( self, symbol_args.arguments([]), Arrangement(), asrt_proc_result.is_result_for_empty_stdout( exit_codes.EXIT_INVALID_USAGE))
def test_references_SHOULD_be_listed_phase_order(self): name_of_existing_symbol = 'STRING_SYMBOL' reference_source = sym_def.reference_to(name_of_existing_symbol, ValueType.STRING) case_with_references = File('test.case', lines_content([ phase_names.SETUP.syntax, sym_def.define_string(name_of_existing_symbol, 'value'), phase_names.CLEANUP.syntax, reference_source, phase_names.ASSERT.syntax, reference_source, phase_names.BEFORE_ASSERT.syntax, reference_source, phase_names.ACT.syntax, reference_source, phase_names.SETUP.syntax, reference_source, ])) expected_reference_outputs = [ output.Reference( phase_identifier.SETUP, output.LineInFilePosition(case_with_references.name, 12), [reference_source] ), output.Reference( phase_identifier.ACT, None, [reference_source] ), output.Reference( phase_identifier.BEFORE_ASSERT, output.LineInFilePosition(case_with_references.name, 8), [reference_source] ), output.Reference( phase_identifier.ASSERT, output.LineInFilePosition(case_with_references.name, 6), [reference_source] ), output.Reference( phase_identifier.CLEANUP, output.LineInFilePosition(case_with_references.name, 4), [reference_source] ), ] expected_output_lines = list(itertools.chain.from_iterable( intersperse_list([''], list(map(output.Reference.output_lines, expected_reference_outputs))) ) ) test_with_files_in_tmp_dir.check( self, command_line_arguments= symbol_args.individual__references( case_with_references.name, name_of_existing_symbol, ), arrangement= Arrangement( cwd_contents=DirContents([ case_with_references, ]), main_program_config=sym_def.main_program_config(), ), expectation= asrt_proc_result.sub_process_result( exitcode=asrt.equals(exit_codes.EXIT_OK), stdout=asrt.equals(lines_content(expected_output_lines))) )