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_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_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_single_definition(self): symbol_name = 'STRING_SYMBOL' case_with_single_def = File('test.case', lines_content([ phase_names.SETUP.syntax, sym_def.define_string(symbol_name, 'value'), ])) 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(symbol_name, ValueType.STRING, num_refs=0), ])), ) )
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_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_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_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_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_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_superfluous_symbol_name(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', '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_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_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_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_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))