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_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_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' not_the_name_of_an_existing_symbol = 'NON_EXISTING_SYMBOL' case_with_single_def = File( 'test.xly', lines_content([ phase_names.SETUP.syntax, sym_def.define_string(name_of_existing_symbol, 'value'), ])) check_case_and_suite( self, symbol_command_arguments=symbol_args.individual__references( 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_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(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_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_empty_file(self): emtpy_test_case_file = File.empty('empty.xly') check_case_and_suite( self, symbol_command_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_superfluous_arguments(self): case_file = File.empty('test.xly') check_case_and_suite( self, symbol_command_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 = File.empty('test.xly') check_case_and_suite( self, symbol_command_arguments=symbol_args.individual__references( 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_superfluous_symbol_name(self): case_file = File.empty('test.case') check_case_and_suite( self, symbol_command_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_option(self): case_file = File.empty('test.xly') check_case_and_suite( self, symbol_command_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_syntax(self): file_with_invalid_syntax = File( 'invalid-syntax.xly', lines_content([ SectionName('nonExistingSection').syntax, ])) check_case_and_suite( self, [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_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_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 test_invalid_symbol_reference(self): file_with_invalid_case = File( 'invalid-symbol-reference.xly', lines_content([ phase_names.SETUP.syntax, sym_def.reference_to('UNDEFINED_SYMBOL', ValueType.STRING), ])) check_case_and_suite( self, symbol_command_arguments=[file_with_invalid_case.name], arrangement=Arrangement( main_program_config=sym_def.main_program_config(), cwd_contents=DirContents([ file_with_invalid_case, ])), expectation=asrt_proc_result.is_result_for_empty_stdout( exit_values.EXECUTION__VALIDATION_ERROR.exit_code))
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_arguments(self): # ARRANGE # file_name = 'file.xly' cases = [ NameAndValue('file-arg is missing', []), NameAndValue('file-arg is not existing', [file_name]), ] for case in cases: with self.subTest(case.name): cli_arguments = case.value # ACT & ASSERT # check_case_and_suite( self, cli_arguments, arrangement=Arrangement(), expectation=asrt_proc_result.is_result_for_empty_stdout( exit_codes.EXIT_INVALID_USAGE))
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_syntax_of_act_phase(self): file_with_invalid_syntax = File( 'invalid-syntax.xly', lines_content([ phase_names.ACT.syntax, 'invalid contents', ])) check_case_and_suite( self, symbol_command_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__SYNTAX_ERROR.exit_code))
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_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_hard_error_from_instruction_in_conf_phase(self): file_with_failing_conf_phase_instruction = File( 'hard-error.xly', lines_content([ phase_names.CONFIGURATION.syntax, sym_def.UNCONDITIONALLY_HARD_ERROR_CONF_PHASE_INSTRUCTION_NAME, ])) check_case_and_suite( self, symbol_command_arguments=[ file_with_failing_conf_phase_instruction.name ], arrangement=Arrangement( main_program_config=sym_def.main_program_config(), cwd_contents=DirContents([ file_with_failing_conf_phase_instruction, ])), expectation=asrt_proc_result.is_result_for_empty_stdout( exit_values.EXECUTION__HARD_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_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_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 check(self, put: unittest.TestCase, tmp_cwd_dir_path: pathlib.Path, actual_result: SubProcessResult): expectation = is_result_for_empty_stdout(exit_codes.EXIT_INVALID_USAGE) expectation.apply_without_message(put, actual_result)
def check(self, put: unittest.TestCase, tmp_cwd_dir_path: pathlib.Path, actual_result: SubProcessResult): expectation = is_result_for_empty_stdout(exit_codes.EXIT_INVALID_USAGE) expectation.apply_without_message(put, actual_result)