def test_fail__value_post_sds(self): self._assert_not_equal( ASingleDirDependentValue(resolving_dependency=DirectoryStructurePartition.NON_HOME, value_post_sds=do_return('expected')), ASingleDirDependentValue(resolving_dependency=DirectoryStructurePartition.NON_HOME, value_post_sds=do_return('actual')), )
def test_fail__value_when_no_dir_dependencies(self): self._assert_not_equal( ASingleDirDependentValue(resolving_dependency=None, value_when_no_dir_dependencies=do_return('expected')), ASingleDirDependentValue(resolving_dependency=None, value_when_no_dir_dependencies=do_return('actual')), )
def test_assert(self): # ARRANGE # cases = { STEP__VALIDATE_POST_SETUP: { EXECUTION__VALIDATION_ERROR: assert_phase_instruction_that( validate_post_setup=SVH_VALIDATION_ERROR), EXECUTION__HARD_ERROR: assert_phase_instruction_that( validate_post_setup=SVH_HARD_ERROR), EXECUTION__INTERNAL_ERROR: assert_phase_instruction_that( validate_post_setup_initial_action=DO_RAISES_EXCEPTION), }, STEP__MAIN: { EXECUTION__FAIL: assert_phase_instruction_that( main=do_return(pfh.new_pfh_fail__str('fail msg'))), EXECUTION__HARD_ERROR: assert_phase_instruction_that(main=do_return( pfh.new_pfh_hard_error__str('hard error msg'))), EXECUTION__INTERNAL_ERROR: assert_phase_instruction_that( main_initial_action=DO_RAISES_EXCEPTION), }, } # ACT & ASSERT # self._check_and_assert_sds_is_preserved_and_is_printed( phase_identifier.ASSERT, cases)
def test_fail__value_post_sds(self): self._assert_not_equal( AMultiDirDependentValue(resolving_dependencies={DirectoryStructurePartition.NON_HOME}, get_value_of_any_dependency=do_return('expected')), AMultiDirDependentValue(resolving_dependencies={DirectoryStructurePartition.NON_HOME}, get_value_of_any_dependency=do_return('actual')), )
def test_pass(self): resolved_value = 'the resolved value' cases = [ NameAndValue( 'no dep', multi_dir_dep_val_without_dependencies(resolved_value) ), NameAndValue( str({DirectoryStructurePartition.HOME}), multi_dir_dep_val_with_dependencies({DirectoryStructurePartition.HOME}, get_value_of_any_dependency=do_return(resolved_value)), ), NameAndValue( str({DirectoryStructurePartition.NON_HOME}), multi_dir_dep_val_with_dependencies({DirectoryStructurePartition.NON_HOME}, get_value_of_any_dependency=do_return(resolved_value)), ), NameAndValue( str({DirectoryStructurePartition.HOME, DirectoryStructurePartition.NON_HOME}), multi_dir_dep_val_with_dependencies({DirectoryStructurePartition.HOME, DirectoryStructurePartition.NON_HOME}, get_value_of_any_dependency=do_return(resolved_value)), ), ] for case in cases: with self.subTest(case.name): assertion = sut.matches_multi_dir_dependent_value(case.value.dir_dependencies(), lambda tcds: asrt.equals(resolved_value)) assertion.apply_without_message(self, case.value)
def test_fail__value_when_no_dir_dependencies(self): self._assert_not_equal( AMultiDirDependentValue(resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return('expected')), AMultiDirDependentValue(resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return('actual')), )
def test_assert(self): # ARRANGE # cases = { STEP__VALIDATE_POST_SETUP: { EXECUTION__VALIDATION_ERROR: assert_phase_instruction_that(validate_post_setup=SVH_VALIDATION_ERROR), EXECUTION__HARD_ERROR: assert_phase_instruction_that(validate_post_setup=SVH_HARD_ERROR), EXECUTION__IMPLEMENTATION_ERROR: assert_phase_instruction_that(validate_post_setup_initial_action=DO_RAISES_EXCEPTION), }, STEP__MAIN: { EXECUTION__FAIL: assert_phase_instruction_that(main=do_return(pfh.new_pfh_fail('fail msg'))), EXECUTION__HARD_ERROR: assert_phase_instruction_that(main=do_return(pfh.new_pfh_hard_error('hard error msg'))), EXECUTION__IMPLEMENTATION_ERROR: assert_phase_instruction_that(main_initial_action=DO_RAISES_EXCEPTION), }, } # ACT & ASSERT # self._check_and_assert_sds_is_preserved_and_is_printed(phase_identifier.ASSERT, cases)
def test_fail(self): actual = csv.ConstantFragment('actual value') expected = AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return('expected value'), get_value_of_any_dependency=do_return('expected value')) assertion = sut.equals_string_fragment(expected) assert_that_assertion_fails(assertion, actual)
def test_fail(self): actual = csv.ConstantFragmentDdv('actual value') expected = AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return('expected value'), get_value_of_any_dependency=do_return('expected value')) assertion = sut.equals_string_fragment_ddv(expected) assert_that_assertion_fails(assertion, actual)
def test_evaluation_of_comparison(self): the_instruction_environment = instruction_environment.fake_post_sds_environment() the_os_services = os_services.new_default() cases = [ ( 'expectation type is positive: pass WHEN comparison succeeds', asrt_pfh.is_pass(), ExpectationType.POSITIVE, 1, comparators.LT, 2, ), ( 'expectation type is positive: fail WHEN comparison does not succeeds', asrt_pfh.is_fail(ASSERT_ERROR_MESSAGE_IS_A_STRING), ExpectationType.POSITIVE, 1, comparators.LT, 1, ), ( 'expectation type is negative: fail WHEN comparison succeeds', asrt_pfh.is_fail(ASSERT_ERROR_MESSAGE_IS_A_STRING), ExpectationType.NEGATIVE, 1, comparators.LT, 2, ), ( 'expectation type is negative: pass WHEN comparison does not succeeds', asrt_pfh.is_pass(), ExpectationType.NEGATIVE, 1, comparators.LT, 1, ), ] for name, result_assertion, expectation_type, l_op, op, r_op in cases: # ARRANGE # instruction_to_check = sut.Instruction( ComparisonHandler(THE_PROPERTY_DESCRIPTOR, expectation_type, operand_resolver_that( resolve_return_value_action=do_return(l_op)), op, operand_resolver_that( resolve_return_value_action=do_return(r_op)))) with self.subTest(name=name): # ACT # actual = instruction_to_check.main(the_instruction_environment, the_os_services) # ASSERT # result_assertion.apply_without_message(self, actual)
def test_pass(self): actual = csv.ConstantFragmentDdv('fragment value') expected = AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return('fragment value'), get_value_of_any_dependency=do_return('fragment value')) assertion = sut.equals_string_fragment_ddv(expected) assertion.apply_without_message(self, actual)
def test_fail__value_when_no_dir_dependencies(self): self._assert_not_equal( AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return('expected')), AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return('actual')), )
def test_fail__value_post_sds(self): self._assert_not_equal( AMultiDirDependentValue( resolving_dependencies={DirectoryStructurePartition.NON_HDS}, get_value_of_any_dependency=do_return('expected')), AMultiDirDependentValue( resolving_dependencies={DirectoryStructurePartition.NON_HDS}, get_value_of_any_dependency=do_return('actual')), )
def test_pass(self): actual = csv.ConstantFragment('fragment value') expected = AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return('fragment value'), get_value_of_any_dependency=do_return('fragment value')) assertion = sut.equals_string_fragment(expected) assertion.apply_without_message(self, actual)
def test_fail__value_when_no_dir_dependencies(self): self._assert_not_equal( AMax1DependencyDdv( resolving_dependency=None, value_when_no_dir_dependencies=do_return('expected')), AMax1DependencyDdv( resolving_dependency=None, value_when_no_dir_dependencies=do_return('actual')), )
def cleanup_phase_instruction_that(validate_pre_sds: Callable = do_return(svh.new_svh_success()), validate_pre_sds_initial_action: Optional[Callable] = None, main: Callable = do_return(sh.new_sh_success()), main_initial_action: Optional[Callable] = None, symbol_usages_initial_action: Optional[Callable] = None, symbol_usages: Callable = do_return([])) -> CleanupPhaseInstruction: return _CleanupPhaseInstructionThat(action_of(validate_pre_sds_initial_action, validate_pre_sds), action_of(main_initial_action, main), action_of(symbol_usages_initial_action, symbol_usages))
def test_fail__value_post_sds(self): self._assert_not_equal( AMax1DependencyDdv( resolving_dependency=DirectoryStructurePartition.NON_HDS, value_post_sds=do_return('expected')), AMax1DependencyDdv( resolving_dependency=DirectoryStructurePartition.NON_HDS, value_post_sds=do_return('actual')), )
def assert_phase_instruction_that(validate_pre_sds: Callable = do_return(svh.new_svh_success()), validate_pre_sds_initial_action: Optional[Callable] = None, validate_post_setup: Callable = do_return(svh.new_svh_success()), validate_post_setup_initial_action: Optional[Callable] = None, main: Callable = do_return(pfh.new_pfh_pass()), main_initial_action: Optional[Callable] = None, symbol_usages_initial_action: Optional[Callable] = None, symbol_usages: Callable = do_return([])) -> AssertPhaseInstruction: return _AssertPhaseInstructionThat(action_of(validate_pre_sds_initial_action, validate_pre_sds), action_of(validate_post_setup_initial_action, validate_post_setup), action_of(main_initial_action, main), action_of(symbol_usages_initial_action, symbol_usages))
def test_pass(self): resolved_value = 'resolved value' cases = [ single_dir_dep_val_without_dependencies(resolved_value), single_dir_dep_val_with_dep_on_hds(do_return(resolved_value)), single_dir_dep_val_with_dep_on_sds(do_return(resolved_value)), ] for value in cases: with self.subTest(value=str(value)): assertion = sut.matches_single_dir_dependent_value(value.resolving_dependency(), lambda tcds: asrt.equals(resolved_value)) assertion.apply_without_message(self, value)
def cleanup_phase_instruction_that( validate_pre_sds: ValidatePreSdsAction = do_return(svh.new_svh_success()), validate_pre_sds_initial_action: Optional[Callable] = None, main: CleanupMainAction = do_return(sh.new_sh_success()), main_initial_action: Optional[CleanupMainInitialAction] = None, symbol_usages_initial_action: Optional[Callable] = None, symbol_usages: Callable = do_return([]) ) -> CleanupPhaseInstruction: return _CleanupPhaseInstructionThat( action_of(validate_pre_sds_initial_action, validate_pre_sds), action_of(main_initial_action, main), action_of(symbol_usages_initial_action, symbol_usages))
def test_pass(self): resolved_value = 'resolved value' cases = [ single_dir_dep_val_without_dependencies(resolved_value), single_dir_dep_val_with_dep_on_hds(do_return(resolved_value)), single_dir_dep_val_with_dep_on_sds(do_return(resolved_value)), ] for value in cases: with self.subTest(value=str(value)): assertion = sut.matches_single_dir_dependent_value( value.resolving_dependency(), lambda tcds: asrt.equals(resolved_value)) assertion.apply_without_message(self, value)
def test_list_constant(self): # ARRANGE # constant = ['a', 'b' 'c'] # ACT # actual = list_sdvs.from_str_constants(constant) # ASSERT # self.assertEqual([], actual.references, 'references') actual_value = actual.resolve(empty_symbol_table()) expected_value = AMultiDirDependentValue(resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return(constant), get_value_of_any_dependency=do_return(constant)) matches_multi_dir_dependent_value(expected_value).apply_with_message(self, actual_value, 'resolve value')
def instruction_embryo_that(validate_pre_sds_initial_action=do_nothing, validate_pre_sds_return_value=None, validate_post_sds_initial_action=do_nothing, validate_post_sds_return_value=None, main=do_return(None), main_initial_action=None, symbol_usages_initial_action=None, symbol_usages=do_return([])) -> InstructionEmbryo: return _InstructionEmbryoThat(ValidatorThat(pre_sds_action=validate_pre_sds_initial_action, pre_sds_return_value=validate_pre_sds_return_value, post_setup_action=validate_post_sds_initial_action, post_setup_return_value=validate_post_sds_return_value), action_of(main_initial_action, main), action_of(symbol_usages_initial_action, symbol_usages))
def test_pass(self): cases = [ AMultiDirDependentValue(resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return('value when no dep'), get_value_of_any_dependency=do_return('value')), AMultiDirDependentValue(resolving_dependencies={DirectoryStructurePartition.HOME}, get_value_of_any_dependency=do_return('value_of_any_dependency')), AMultiDirDependentValue(resolving_dependencies={DirectoryStructurePartition.NON_HOME}, get_value_of_any_dependency=do_return('value_of_any_dependency')) ] for value in cases: with self.subTest(value=str(value)): assertion = sut.matches_multi_dir_dependent_value(value) assertion.apply_without_message(self, value)
def test_pass(self): cases = [ ASingleDirDependentValue(resolving_dependency=None, value_when_no_dir_dependencies=do_return('value'), value_pre_sds=do_return('value')), ASingleDirDependentValue(resolving_dependency=DirectoryStructurePartition.HOME, value_pre_sds=do_return('value pre sds')), ASingleDirDependentValue(resolving_dependency=DirectoryStructurePartition.NON_HOME, value_post_sds=do_return('value post sds')) ] for value in cases: with self.subTest(value=str(value)): assertion = sut.matches_single_dir_dependent_value(value) assertion.apply_without_message(self, value)
def __new__( cls, test_case_generator: TestCaseGeneratorForExecutionRecording, actor_parse=do_nothing, atc_validate_post_setup=do_return(svh.new_svh_success()), atc_prepare=prepare_action_that_returns(sh.new_sh_success()), atc_execute: ExecuteFunctionEh = execute_action_that_returns_exit_code( ), atc_validate_pre_sds=do_return(svh.new_svh_success()), atc_symbol_usages: Callable[[], Sequence[SymbolUsage]] = do_return([])): return tuple.__new__(cls, (test_case_generator, atc_validate_post_setup, atc_prepare, atc_execute, atc_validate_pre_sds, atc_symbol_usages, actor_parse))
def runTest(self): conf = self.configuration defined_symbol = data_symbol_utils.string_symbol_definition('symbol_name') error_message_for_failed_restriction = 'error message' reference_with_restriction_failure = SymbolReference( defined_symbol.name, ReferenceRestrictionsOnDirectAndIndirect( direct=value_restriction_that_is_unconditionally_unsatisfied(error_message_for_failed_restriction))) test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr() \ .add(PartialPhase.SETUP, setup_phase_instruction_that(symbol_usages=do_return([defined_symbol]))) \ .add(conf.phase, conf.instruction_that_returns([reference_with_restriction_failure])) execute_test_case_with_recording( self, Arrangement(test_case), Expectation( asrt_result.matches2( PartialExeResultStatus.VALIDATION_ERROR, asrt_result.has_no_sds(), asrt_result.has_no_action_to_check_outcome(), ExpectedFailureForInstructionFailure.new_with_phase_and_message_assertion( conf.step, asrt.equals(error_message_for_failed_restriction)), ), conf.expected_steps_before_failing_instruction, ) )
def test_hard_error_in_setup_main_step(self): py_pgm_setup = PyProgramSetup('some output to stdout', 'some output to stderr', 72) test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr( act_phase_source=py_pgm_setup.as_line_sequence()) \ .add(PartialPhase.SETUP, test.setup_phase_instruction_that( main=do_return(sh.new_sh_hard_error('hard error msg from setup')))) self._check( arr_for_py3_source(test_case), Expectation( asrt_result.matches2( PartialExeResultStatus.HARD_ERROR, asrt_result.has_sds(), asrt_result.has_no_action_to_check_outcome(), ExpectedFailureForInstructionFailure.new_with_message( phase_step.SETUP__MAIN, test_case.the_extra(PartialPhase.SETUP)[0].source, 'hard error msg from setup'), ), atc_stdout_output=asrt.equals(''), atc_stderr_output=asrt.equals(''), step_recordings= [phase_step.ACT__PARSE] + SYMBOL_VALIDATION_STEPS__TWICE + PRE_SDS_VALIDATION_STEPS__TWICE + [phase_step.SETUP__MAIN, (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP), (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP), ], ))
def test(self): cases = [ ( 'single string constant fragment', csv.ConstantFragment('fragment'), AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return('fragment'), get_value_of_any_dependency=do_return('fragment')), ), ] for test_case_name, expected, actual in cases: assertion = matches_multi_dir_dependent_value(expected) with self.subTest(name=test_case_name, expected=str(expected)): assertion.apply_without_message(self, actual)
def test_validation_SHOULD_fail_WHEN_resolved_value_is_not_an_integer(self): the_instruction_environment = instruction_environment.fake_pre_sds_environment() test_cases = [ 'a', '1+x', 'a b', '10 a', '10a', '1.5', ] for custom_validator in [None, do_return(None)]: for resolved_value in test_cases: with self.subTest( custom_validator_is_none=str(custom_validator is None), resolved_value=resolved_value): # ARRANGE # resolver_to_check = sut.IntegerResolver('the property to check', string_resolvers.str_constant(resolved_value), custom_validator) # ACT & ASSERT # with self.assertRaises(SvhValidationException) as cm: resolver_to_check.validate_pre_sds(the_instruction_environment) self.assertIsInstance(cm.exception.err_msg, str, 'the error message should be a str')
def test_hard_error_in_setup_main_step(self): test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr() \ .add(PartialPhase.SETUP, test.setup_phase_instruction_that( main=do_return(sh.new_sh_hard_error('hard error msg from setup')))) self._check( Arrangement(test_case), Expectation( asrt_result.matches2( PartialExeResultStatus.HARD_ERROR, asrt_result.has_sds(), asrt_result.has_no_action_to_check_outcome(), ExpectedFailureForInstructionFailure.new_with_message( phase_step.SETUP__MAIN, test_case.the_extra(PartialPhase.SETUP)[0].source, 'hard error msg from setup'), ), [phase_step.ACT__PARSE] + SYMBOL_VALIDATION_STEPS__TWICE + PRE_SDS_VALIDATION_STEPS__TWICE + [phase_step.SETUP__MAIN, (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP), (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP), ], ))
def assert_phase_instruction_that( validate_pre_sds: ValidatePreSdsAction = do_return(svh.new_svh_success()), validate_pre_sds_initial_action: Optional[Callable] = None, validate_post_setup: ValidatePostSdsAction = do_return( svh.new_svh_success()), validate_post_setup_initial_action: Optional[Callable] = None, main: AssertMainAction = do_return(pfh.new_pfh_pass()), main_initial_action: Optional[AssertMainInitialAction] = None, symbol_usages_initial_action: Optional[Callable] = None, symbol_usages: Callable = do_return([]) ) -> AssertPhaseInstruction: return _AssertPhaseInstructionThat( action_of(validate_pre_sds_initial_action, validate_pre_sds), action_of(validate_post_setup_initial_action, validate_post_setup), action_of(main_initial_action, main), action_of(symbol_usages_initial_action, symbol_usages))
def test_symbol_that_does_not_meet_restriction_in_validate_symbols(self): test_case = _single_successful_instruction_in_each_phase() symbol_name = 'symbol_name' reference_to_string_symbol = data_references.reference_to__on_direct_and_indirect( symbol_name, value_restrictions.is_string()) definition_of_path_symbol = arbitrary_path_symbol_context( symbol_name).definition symbol_usages = [ definition_of_path_symbol, reference_to_string_symbol, ] self._check( Arrangement(test_case, atc_symbol_usages=do_return(symbol_usages)), Expectation( asrt_result.matches2( ExecutionFailureStatus.VALIDATION_ERROR, asrt_result.has_no_sds(), asrt_result.has_no_action_to_check_outcome(), ExpectedFailureForPhaseFailure.new_with_step( phase_step.ACT__VALIDATE_SYMBOLS), ), [ phase_step.ACT__PARSE, phase_step.SETUP__VALIDATE_SYMBOLS, phase_step.ACT__VALIDATE_SYMBOLS, ], ))
def test_dir_dependence(self): cases = [ NEA( 'single string constant fragment', expected=AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return('fragment'), get_value_of_any_dependency=do_return('fragment')), actual=strings.ConstantFragmentDdv('fragment'), ), ] for case in cases: assertion = matches_multi_dir_dependent_value(case.expected) with self.subTest(name=case.name, expected=str(case.expected)): assertion.apply_without_message(self, case.actual)
def test_symbol_that_does_not_meet_restriction_in_validate_symbols(self): test_case = _single_successful_instruction_in_each_phase() symbol_name = 'symbol_name' reference_to_string_symbol = data_symbol_utils.symbol_reference(symbol_name, StringRestriction()) definition_of_path_symbol = data_symbol_utils.file_ref_symbol_definition(symbol_name) symbol_usages = [ definition_of_path_symbol, reference_to_string_symbol, ] self._check( Arrangement(test_case, act_executor_symbol_usages=do_return(symbol_usages)), Expectation( asrt_result.matches2( PartialExeResultStatus.VALIDATION_ERROR, asrt_result.has_no_sds(), asrt_result.has_no_action_to_check_outcome(), ExpectedFailureForPhaseFailure.new_with_step(phase_step.ACT__VALIDATE_SYMBOLS), ), [ phase_step.ACT__PARSE, phase_step.SETUP__VALIDATE_SYMBOLS, phase_step.ACT__VALIDATE_SYMBOLS, ], ))
def configuration_phase_instruction_that( main: Callable = do_return(svh.new_svh_success()), main_initial_action: Optional[Callable[[ConfigurationBuilder], None]] = None, ) -> ConfigurationPhaseInstruction: return _ConfigurationPhaseInstructionThat( main=action_of(main_initial_action, main))
def __new__(cls, test_case_generator: TestCaseGeneratorForExecutionRecording, act_executor_parse=do_nothing, act_executor_validate_post_setup=do_return(svh.new_svh_success()), act_executor_prepare=prepare_action_that_returns(sh.new_sh_success()), act_executor_execute=execute_action_that_returns_exit_code(), act_executor_validate_pre_sds=do_return(svh.new_svh_success()), act_executor_symbol_usages=do_return([]) ): return tuple.__new__(cls, (test_case_generator, act_executor_validate_post_setup, act_executor_prepare, act_executor_execute, act_executor_validate_pre_sds, act_executor_symbol_usages, act_executor_parse))
def test_hard_error_in_setup_main_step(self): py_pgm_setup = PyProgramSetup('some output to stdout', 'some output to stderr', 72) test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr( act_phase_source=py_pgm_setup.as_line_sequence()) \ .add(PartialPhase.SETUP, test.setup_phase_instruction_that( main=do_return(sh.new_sh_hard_error__str('hard error msg from setup')))) self._check( arr_for_py3_source(test_case), Expectation( asrt_result.matches2( ExecutionFailureStatus.HARD_ERROR, asrt_result.has_sds(), asrt_result.has_no_action_to_check_outcome(), ExpectedFailureForInstructionFailure.new_with_message( phase_step.SETUP__MAIN, test_case.the_extra(PartialPhase.SETUP)[0].source, 'hard error msg from setup'), ), atc_stdout_output=asrt.equals(''), atc_stderr_output=asrt.equals(''), step_recordings=[phase_step.ACT__PARSE] + SYMBOL_VALIDATION_STEPS__TWICE + PRE_SDS_VALIDATION_STEPS__TWICE + [ phase_step.SETUP__MAIN, (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP), (phase_step.CLEANUP__MAIN, PreviousPhase.SETUP), ], ))
def test(self): cases = [ ( 'single string constant fragment', strings.TransformedStringFragmentDdv(strings.ConstantFragmentDdv('fragment'), str.upper), AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return('FRAGMENT'), get_value_of_any_dependency=do_return('FRAGMENT')), ), ] for test_case_name, actual, expected in cases: assertion = matches_multi_dir_dependent_value(expected) with self.subTest(name=test_case_name, expected=str(expected)): assertion.apply_without_message(self, actual)
def test_pass(self): cases = [ AMax1DependencyDdv( resolving_dependency=None, value_when_no_dir_dependencies=do_return('value'), value_pre_sds=do_return('value')), AMax1DependencyDdv( resolving_dependency=DirectoryStructurePartition.HDS, value_pre_sds=do_return('value pre sds')), AMax1DependencyDdv( resolving_dependency=DirectoryStructurePartition.NON_HDS, value_post_sds=do_return('value post sds')) ] for value in cases: with self.subTest(value=str(value)): assertion = sut.matches_single_dir_dependent_value(value) assertion.apply_without_message(self, value)
def __init__( self, prepare: Callable = do_nothing, execute_initial_action: BeforeExecuteMethod = do_nothing, execute: ExecuteFunction = do_return(0), ): self._prepare = prepare self._execute_initial_action = execute_initial_action self._execute = execute
def test_that_default_expectation_assumes_no_symbol_usages(self): with self.assertRaises(utils.TestError): unexpected_symbol_usages = [data_symbol_utils.symbol_reference('symbol_name')] self._check( utils.ParserThatGives( cleanup_phase_instruction_that( symbol_usages=do_return(unexpected_symbol_usages))), utils.single_line_source(), sut.Arrangement(), sut.Expectation(), )
def test_pass(self): cases = [ AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return( 'value when no dep'), get_value_of_any_dependency=do_return('value')), AMultiDirDependentValue( resolving_dependencies={DirectoryStructurePartition.HDS}, get_value_of_any_dependency=do_return( 'value_of_any_dependency')), AMultiDirDependentValue( resolving_dependencies={DirectoryStructurePartition.NON_HDS}, get_value_of_any_dependency=do_return( 'value_of_any_dependency')) ] for value in cases: with self.subTest(value=str(value)): assertion = sut.matches_multi_dir_dependent_value(value) assertion.apply_without_message(self, value)
def test_fail__dependency(self): resolved_value = 'the resolved value' cases = [ NEA('invalid dep/none - NON_HOME', DirDependencies.HOME, multi_dir_dep_val_without_dependencies(resolved_value) ), NEA('invalid dep/HOME - NON_HOME', DirDependencies.HOME, multi_dir_dep_val_with_dependencies({DirectoryStructurePartition.NON_HOME}, do_return(resolved_value)) ), NEA('invalid dep/HOME - HOME+NON_HOME', DirDependencies.HOME, multi_dir_dep_val_with_dependencies({DirectoryStructurePartition.HOME, DirectoryStructurePartition.NON_HOME}, do_return(resolved_value)) ), NEA('invalid dep/SDS - HOME', DirDependencies.SDS, multi_dir_dep_val_with_dependencies({DirectoryStructurePartition.HOME}, do_return(resolved_value)) ), NEA('invalid dep/HOME_AND_SDS - NON_HOME', DirDependencies.HOME_AND_SDS, multi_dir_dep_val_with_dependencies({DirectoryStructurePartition.NON_HOME}, do_return(resolved_value)) ), NEA('invalid dep/HOME_AND_SDS - {}', DirDependencies.HOME_AND_SDS, multi_dir_dep_val_with_dependencies(set(), do_return(resolved_value)) ), ] for case in cases: with self.subTest(case.name): self._assert_not_matches( case.actual, case.expected, lambda tcds: asrt.anything_goes() )
def test_fail__resolving_dependency(self): cases = [ NEA('expects no dependencies', expected=None, actual=single_dir_dep_val_with_dep_on_hds(do_return('resolved_value')) ), NEA('expects dependencies', expected=DirectoryStructurePartition.HOME, actual=single_dir_dep_val_without_dependencies('resolved_value') ), NEA('expects correct dependency', expected=DirectoryStructurePartition.HOME, actual=single_dir_dep_val_with_dep_on_sds(do_return('resolved value')) ), ] for case in cases: with self.subTest(case.name): self._assert_not_matches(case.actual, case.expected, asrt.anything_goes(), )
def test_that_default_expectation_assumes_no_symbol_usages(self): with self.assertRaises(utils.TestError): unexpected_symbol_usages = [ data_references.reference_to__on_direct_and_indirect('symbol_name')] self._check( utils.ParserThatGives( before_assert_phase_instruction_that( symbol_usages=do_return(unexpected_symbol_usages))), single_line_source(), sut.arrangement(), sut.Expectation(), )
def test_as_file_should_call_wrapped_method(self): # ARRANGE # value_from_wrapped_method = Path('the path') wrapped = StringSourceContentsThat.new_w_defaults_of_not_impl( as_file=do_return(value_from_wrapped_method), ) source = sut.StringSourceContentsThatThatChecksLines(self, wrapped) # ACT # actual = source.as_file # ASSERT # self.assertIs(actual, value_from_wrapped_method)
def test_tmp_file_space_should_call_wrapped_method(self): # ARRANGE # value_from_wrapped_method = DirFileSpaceThatMustNoBeUsed() wrapped = StringSourceContentsThat.new_w_defaults_of_not_impl( tmp_file_space=do_return(value_from_wrapped_method), ) source = sut.StringSourceContentsThatThatChecksLines(self, wrapped) # ACT # actual = source.tmp_file_space # ASSERT # self.assertIs(actual, value_from_wrapped_method)
def parse(self, instructions: Sequence[ActPhaseInstruction]) -> ActionToCheck: try: source_lines = list(itertools.chain.from_iterable(map(self._get_source_code_lines, instructions))) reference_instructions_arguments = self._get_reference_instruction_arguments(source_lines) references = list( itertools.chain.from_iterable(map(_parse_reference_arguments, reference_instructions_arguments))) return ActionToCheckThatRunsConstantActions( symbol_usages_action=do_return(references) ) except SingleInstructionInvalidArgumentException as ex: raise ParseException(svh.new_svh_validation_error(ex.error_message))
def test_fail__resolving_dependency(self): cases = [ NEA('expects no dependencies', expected=None, actual=single_dir_dep_val_with_dep_on_hds( do_return('resolved_value'))), NEA('expects dependencies', expected=DirectoryStructurePartition.HDS, actual=single_dir_dep_val_without_dependencies( 'resolved_value')), NEA('expects correct dependency', expected=DirectoryStructurePartition.HDS, actual=single_dir_dep_val_with_dep_on_sds( do_return('resolved value'))), ] for case in cases: with self.subTest(case.name): self._assert_not_matches( case.actual, case.expected, asrt.anything_goes(), )
def configuration_with_assert_instruction_that_fails(instruction_name: str) -> sut.Configuration: assert_instruction_setup = instr_setup(instr.assert_phase_instruction_that( main=do_return(pfh.new_pfh_fail('fail error message'))) ) instruction_set = InstructionsSetup( config_instruction_set={}, setup_instruction_set={}, before_assert_instruction_set={}, assert_instruction_set={instruction_name: assert_instruction_setup}, cleanup_instruction_set={}, ) return configuration_for_instruction_set(instruction_set)
def test_that_fails_due_to_missing_symbol_reference(self): with self.assertRaises(utils.TestError): symbol_usages_of_instruction = [] symbol_usages_of_expectation = [data_symbol_utils.symbol_reference('symbol_name')] self._check( utils.ParserThatGives( cleanup_phase_instruction_that( symbol_usages=do_return(symbol_usages_of_instruction))), utils.single_line_source(), sut.Arrangement(), sut.Expectation( symbol_usages=sym_asrt.equals_symbol_references(symbol_usages_of_expectation)), )
def test_as_str_should_call_wrapped_method(self): # ARRANGE # value_from_wrapped_method = 'the str' wrapped = StringSourceOfContents.of_identical( string_source_contents.StringSourceContentsThat.new_w_defaults_of_not_impl( as_str=do_return(value_from_wrapped_method), ) ) source = sut.StringSourceThatThatChecksLines(self, wrapped) # ACT # actual = source.contents().as_str # ASSERT # self.assertIs(actual, value_from_wrapped_method)
def configuration_with_assert_instruction_that_fails( instruction_name: str) -> sut.Configuration: assert_instruction_setup = instr_setup( instr.assert_phase_instruction_that( main=do_return(pfh.new_pfh_fail__str('fail error message')))) instruction_set = InstructionsSetup( config_instruction_set={}, setup_instruction_set={}, before_assert_instruction_set={}, assert_instruction_set={instruction_name: assert_instruction_setup}, cleanup_instruction_set={}, ) return configuration_for_instruction_set(instruction_set)
def instruction_embryo_that__phase_agnostic( validate_pre_sds_initial_action=do_nothing, validate_pre_sds_return_value: Optional[TextRenderer] = None, validate_post_sds_initial_action=do_nothing, validate_post_sds_return_value: Optional[TextRenderer] = None, main: Callable[[ InstructionEnvironmentForPostSdsStep, InstructionSettings, OsServices ], T] = do_return(None), main_initial_action: Optional[Callable[[ InstructionEnvironmentForPostSdsStep, InstructionSettings, OsServices ], None]] = None, symbol_usages_initial_action=None, symbol_usages=do_return([]) ) -> InstructionEmbryo[T]: return _PhaseAgnosticInstructionEmbryoThat( SdvValidatorThat( pre_sds_action=validate_pre_sds_initial_action, pre_sds_return_value=validate_pre_sds_return_value, post_setup_action=validate_post_sds_initial_action, post_setup_return_value=validate_post_sds_return_value), action_of(main_initial_action, main), action_of(symbol_usages_initial_action, symbol_usages), )
def test_return_value_from_parser_WHEN_command_is_found(self): command_name = 'command' return_value_from_parser = 'parser return value' command_parser = do_return(return_value_from_parser) command_name_2_parser = { command_name: command_parser, } # ARRANGE # token_stream = TokenStream(command_name) parser = sut.TokenParser(token_stream) # ACT # actual = parser.parse_optional_command(command_name_2_parser) # ASSERT # self.assertEqual(return_value_from_parser, actual)
def test(self): string_of_path_rel_home = string_ddv_of_single_path( path_ddvs.of_rel_option(path_ddvs.RelOptionType.REL_HDS_CASE, PathPartDdvAsNothing())) string_1 = 'string value 1' string_2 = 'string value 2' cases = [ ( 'single string constant element', strings.ListFragmentDdv(strings.ListDdv([string_ddv_of_single_string(string_1)])), AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return(string_1), get_value_of_any_dependency=do_return(string_1)), ), ( 'multiple string constant element', strings.ListFragmentDdv(strings.ListDdv([string_ddv_of_single_string(string_1), string_ddv_of_single_string(string_2)])), AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return(list_formatting.format_elements([string_1, string_2])), get_value_of_any_dependency=do_return(list_formatting.format_elements([string_1, string_2]))), ), ( 'dependency on ' + str(DirectoryStructurePartition.HDS), strings.ListFragmentDdv(strings.ListDdv([string_of_path_rel_home])), AMultiDirDependentValue( resolving_dependencies={DirectoryStructurePartition.HDS}, get_value_of_any_dependency=lambda h_s: str( string_of_path_rel_home.value_of_any_dependency(h_s))), ), ] for test_case_name, expected, actual in cases: assertion = matches_multi_dir_dependent_value(expected) with self.subTest(name=test_case_name): assertion.apply_without_message(self, actual)
def test_pass(self): resolved_value = 'the resolved value' cases = [ NameAndValue( 'no dep', multi_dir_dep_val_without_dependencies(resolved_value)), NameAndValue( str({DirectoryStructurePartition.HDS}), multi_dir_dep_val_with_dependencies( {DirectoryStructurePartition.HDS}, get_value_of_any_dependency=do_return(resolved_value)), ), NameAndValue( str({DirectoryStructurePartition.NON_HDS}), multi_dir_dep_val_with_dependencies( {DirectoryStructurePartition.NON_HDS}, get_value_of_any_dependency=do_return(resolved_value)), ), NameAndValue( str({ DirectoryStructurePartition.HDS, DirectoryStructurePartition.NON_HDS }), multi_dir_dep_val_with_dependencies( { DirectoryStructurePartition.HDS, DirectoryStructurePartition.NON_HDS }, get_value_of_any_dependency=do_return(resolved_value)), ), ] for case in cases: with self.subTest(case.name): assertion = sut.matches_multi_dir_dependent_value( case.value.dir_dependencies(), lambda tcds: asrt.equals(resolved_value)) assertion.apply_without_message(self, case.value)
def test(self): string_of_file_ref_rel_home = string_value_of_single_file_ref( file_refs.of_rel_option(file_refs.RelOptionType.REL_HOME_CASE, PathPartAsNothing())) string_1 = 'string value 1' string_2 = 'string value 2' cases = [ ( 'single string constant element', csv.ListValueFragment(csv.ListValue([string_value_of_single_string(string_1)])), AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return(string_1), get_value_of_any_dependency=do_return(string_1)), ), ( 'multiple string constant element', csv.ListValueFragment(csv.ListValue([string_value_of_single_string(string_1), string_value_of_single_string(string_2)])), AMultiDirDependentValue( resolving_dependencies=set(), get_value_when_no_dir_dependencies=do_return(string_1 + ' ' + string_2), get_value_of_any_dependency=do_return(string_1 + ' ' + string_2)), ), ( 'dependency on ' + str(DirectoryStructurePartition.HOME), csv.ListValueFragment(csv.ListValue([string_of_file_ref_rel_home])), AMultiDirDependentValue( resolving_dependencies={DirectoryStructurePartition.HOME}, get_value_of_any_dependency=lambda h_s: str( string_of_file_ref_rel_home.value_of_any_dependency(h_s))), ), ] for test_case_name, expected, actual in cases: assertion = matches_multi_dir_dependent_value(expected) with self.subTest(name=test_case_name): assertion.apply_without_message(self, actual)
def test_return_value_from_parser_WHEN_command_is_found(self): command_name = 'command' return_value_from_parser = 'parser return value' command_parser = do_return(return_value_from_parser) command_name_2_parser = { command_name: command_parser, } # ARRANGE # token_stream = TokenStream(command_name) parser = sut.TokenParser(token_stream) # ACT # actual = parser.parse_optional_command(command_name_2_parser) # ASSERT # self.assertEqual(return_value_from_parser, actual)