def generate( self, root_dir_path: DescribedPath, directory_prune: Optional[FileMatcher], ) -> Iterator[FileModel]: directory_prune = (constant.MatcherWithConstantResult(False) if directory_prune is None else directory_prune) def add_dir_to_process_if_is_dir(maybe_entry_for_dir): try: if (maybe_entry_for_dir.is_dir() and not directory_prune.matches_w_trace( current_file_model.as_file_matcher_model()).value): remaining_dirs.append( current_file.new_for_sub_dir(maybe_entry_for_dir)) except OSError as ex: raise HardErrorException( text_docs.os_exception_error_message(ex)) remaining_dirs = self._initialize_for_depth_0(root_dir_path) while remaining_dirs: current_file = remaining_dirs.pop(0) is_within_min_depth_limit = self._is_within_min_depth_limit( current_file.depth) is_not_at_max_depth = not self._is_at_max_depth_limit( current_file.depth) for dir_entry in current_file.dir_entries(): current_file_model = current_file.file_model(dir_entry) if is_within_min_depth_limit: yield current_file_model if is_not_at_max_depth: add_dir_to_process_if_is_dir(dir_entry)
def of_primitive_constant( result: bool, definition_source: Optional[ SourceLocationInfo] = ARBITRARY_LINE_SEQUENCE_FOR_DEFINITION, ) -> 'IntegerMatcherSymbolValueContext': return IntegerMatcherSymbolValueContext.of_primitive( constant.MatcherWithConstantResult(result), definition_source)
def successful_matcher_with_validation( validator: DdvValidator) -> LineMatcherSdv: return sdv_ddv.sdv_from_primitive_value( constant.MatcherWithConstantResult(True), (), validator, )
def test_expect_match_is_true(self): self._check_raises_test_error__single_and_multi( _constant_line_matcher_type_parser_of_matcher_sdv( sdv_ddv.sdv_from_primitive_value(constant.MatcherWithConstantResult(False)) ), is_expectation_of_execution_result_of(True), )
def test_accept_visitor_invokes_correct_method(self): # ARRANGE # operand1 = constant.MatcherWithConstantResult(False) operand2 = constant.MatcherWithConstantResult(False) matcher = sut.Disjunction([operand1, operand2]) return_value = 11 visitor = MatcherStdTypeVisitorTestAcceptImpl.new_w_default_to_raise_exception( disjunction_action=assert_argument_satisfies__and_return( self, asrt.matches_sequence([asrt.is_(operand1), asrt.is_(operand2)]), return_value, )) actual_return_value = matcher.accept(visitor) # ASSERT # self.assertEqual(return_value, actual_return_value, 'return value')
def of_primitive_constant( name: str, result: bool, definition_source: Optional[ SourceLocationInfo] = ARBITRARY_LINE_SEQUENCE_FOR_DEFINITION, ) -> 'LineMatcherSymbolContext': return LineMatcherSymbolContext.of_primitive( name, constant.MatcherWithConstantResult(result), definition_source)
def test_expect_post_validation_succeeds(self): self._check_raises_test_error__single_and_multi( _constant_line_matcher_type_parser_of_matcher_ddv( sdv_ddv.MatcherDdvOfConstantMatcherTestImpl( constant.MatcherWithConstantResult(True), ConstantDdvValidator( post_sds_result=rend_comb.ConstantSequenceR([]))) ), is_expectation_of_execution_result_of(True), )
def test_accept_SHOULD_invoke_method_for_constant_matcher(self): const_value = False matcher = sut.MatcherWithConstantResult(const_value) return_value = 5 visitor = MatcherStdTypeVisitorTestAcceptImpl.new_w_default_to_raise_exception( constant_action=assert_argument_satisfies__and_return( self, asrt.equals(const_value), return_value)) # ACT & ASSERT # actual_return_value = matcher.accept(visitor) # ASSERT # self.assertEqual(return_value, actual_return_value, 'return value')
def __init__( self, name: str, result: bool, definition_source: Optional[ SourceLocationInfo] = ARBITRARY_LINE_SEQUENCE_FOR_DEFINITION, ): super().__init__( name, IntegerMatcherSymbolValueContext.of_primitive( constant.MatcherWithConstantResult(result), definition_source)) self._result = result
def __init__( self, expectation: ValidationAssertions, actual: ValidationActual, ): self.actual = actual self._expectation = expectation self._symbol_context = StringMatcherSymbolContext.of_sdv( 'string_matcher_symbol', sdv_components.MatcherSdvFromConstantDdv( sdv_ddv.MatcherDdvOfConstantMatcherTestImpl( constant.MatcherWithConstantResult(True), validator=ddv_validators.constant(actual))))
def test_accept_visitor_invokes_correct_method(self): # ARRANGE # operand = constant.MatcherWithConstantResult(False) matcher = sut.Negation(operand) return_value = 5 visitor = MatcherStdTypeVisitorTestAcceptImpl.new_w_default_to_raise_exception( negation_action=assert_argument_satisfies__and_return( self, asrt.is_(operand), return_value)) # ACT & ASSERT # actual_return_value = matcher.accept(visitor) # ASSERT # self.assertEqual(return_value, actual_return_value, 'return value')
class _MatcherDdvThatIsAssertionOnTcds(MatcherDdv[int]): MATCHER = constant.MatcherWithConstantResult(True) def __init__(self, put: unittest.TestCase, assertion: Assertion[TestCaseDs], ): self._put = put self._assertion = assertion def structure(self) -> StructureRenderer: return self.MATCHER.structure() def value_of_any_dependency(self, tcds: TestCaseDs) -> MatcherAdv[MODEL]: self._assertion.apply_with_message(self._put, tcds, 'assertion on tcds') return advs.ConstantMatcherAdv(self.MATCHER)
def test_SHOULD_not_match_WHEN_validator_is_none(self): # ARRANGE # cases = [ NameAndValue('without symbol table', None), NameAndValue( 'with symbol table', StringMatcherSymbolContext( 'the symbol name', string_matcher. ARBITRARY_SYMBOL_VALUE_CONTEXT).symbol_table, ), ] sdv_of_actual = string_matcher_sdv_constant_test_impl( constant.MatcherWithConstantResult(True), validator=None) for case in cases: with self.subTest(name=case.name): assertion_to_check = _matches_string_matcher_sdv( symbols=case.value) # ACT & ASSERT # assert_that_assertion_fails(assertion_to_check, sdv_of_actual)
def test_fail_due_to_unsatisfied_assertion_on_output_from_application(self): matcher_result_value = True for check_application_result_with_tcds in [False, True]: parser = _constant_line_matcher_type_parser_of_matcher_sdv( sdv_ddv.sdv_from_primitive_value(constant.MatcherWithConstantResult(matcher_result_value)) ) checker = sut.IntegrationChecker( parser, _CustomMatcherPropertiesConfiguration(asrt_matching_result.matches_value(not matcher_result_value)), check_application_result_with_tcds, ) expectation = is_expectation_of_execution_result_of(matcher_result_value) for arrangement in _EMPTY_ARRANGEMENT_W_WO_TCDS: with self.subTest(arrangement.name, check_application_result_with_tcds=check_application_result_with_tcds, execution_variant='single execution'): with self.assertRaises(utils.TestError): self._check( utils.single_line_source(), ARBITRARY_MODEL, checker, arrangement.value, expectation, ) with self.subTest(arrangement.name, check_application_result_with_tcds=check_application_result_with_tcds, execution_variant='multiple execution'): with self.assertRaises(utils.TestError): self._check___multi( utils.single_line_arguments(), ARBITRARY_MODEL, checker, arrangement.value, expectation, )
def arbitrary_sdv_with_references( references: Sequence[SymbolReference]) -> StringMatcherSdv: return string_matcher_sdv_constant_test_impl( constant.MatcherWithConstantResult(True), references)
NameAndValue( 'assert single invalid reference', asrt.matches_sequence([asrt.not_(asrt.is_(actual_reference)) ])), ] for case in cases: with self.subTest(name=case.name): assertion_to_check = _matches_string_matcher_sdv( references=case.value) # ACT & ASSERT # assert_that_assertion_fails(assertion_to_check, actual_sdv) ARBITRARY_STRING_MATCHER_SDV = string_matcher_sdv_constant_test_impl( constant.MatcherWithConstantResult(True)) def _matches_string_matcher_sdv( primitive_value: Assertion[MatcherWTrace] = asrt.anything_goes(), references: Assertion[ Sequence[SymbolReference]] = asrt.is_empty_sequence, symbols: SymbolTable = None, tcds: TestCaseDs = fake_tcds(), ) -> Assertion[SymbolDependentValue]: return sut.matches_matcher_sdv(primitive_value, references, symbols, tcds) def arbitrary_sdv_with_references( references: Sequence[SymbolReference]) -> StringMatcherSdv: return string_matcher_sdv_constant_test_impl(
def ddv_of_unconditionally_matching_matcher() -> LineMatcherDdv: return ddv_components.MatcherDdvFromConstantPrimitive( constant.MatcherWithConstantResult(False))
def get_matcher(symbols: SymbolTable, tcds: TestCaseDs) -> FileMatcher: return constant.MatcherWithConstantResult(True)
def make_primitive(tcds: TestCaseDs) -> MatcherWTrace[int]: return constant.MatcherWithConstantResult(True)
def _make_constant_matcher(boolean_keyword: str) -> MatcherSdv: return sdv_components.matcher_sdv_from_constant_primitive( constant.MatcherWithConstantResult(logic.BOOLEANS_STRINGS[boolean_keyword]) )
def constant_result(result: bool) -> FileMatcher: return constant.MatcherWithConstantResult(result)