def _check_cases_for_no_lines( self, get_assertion_part_function: Callable[ [ExpectationType, LineMatcherSdv], AssertionPart[StringSource, pfh.PassOrFailOrHardError]], expected_result_when_positive_expectation: PassOrFail): empty_file_contents = '' environment = fake_post_sds_environment() os_services = new_for_current_os() matchers = [ ('unconditionally true', MatcherWithConstantResult(True)), ('unconditionally false', MatcherWithConstantResult(False)), ] with string_source_factory() as source_factory: # This test is expected to not create files using the above object, # but to be sure, one is used that creates and destroys temporary files. with tmp_file_containing(empty_file_contents) as actual_file_path: for expectation_type in ExpectationType: for matcher_name, matcher in matchers: with self.subTest(expectation_type=expectation_type, matcher_name=matcher_name): model = source_factory.of_file__poorly_described( actual_file_path) matcher_sdv = sdv_components.matcher_sdv_from_constant_primitive( matcher) assertion_part = get_assertion_part_function( expectation_type, matcher_sdv) # ACT # actual = assertion_part.check_and_return_pfh( environment, os_services, model) # ASSERT # pfh_assertion = pfh_expectation_type_config( expectation_type).main_result( expected_result_when_positive_expectation) pfh_assertion.apply_without_message(self, actual)
def _name_starts_with__and_hard_error_if_applied_to_non_directory( name: str, expected_name_prefix: str, ) -> FileMatcherSymbolContext: return FileMatcherSymbolContext.of_sdv( name, combinator_sdvs.Conjunction( [ sdv_components.matcher_sdv_from_constant_primitive( file_matchers.BaseNameStartsWithMatcher( expected_name_prefix)), sdv_components.matcher_sdv_from_constant_primitive( _HardErrorIfAppliedToNonDirectory()), ], combinator_matchers.no_op_freezer, ))
def test_fails_if_applied(put: unittest.TestCase) -> FileMatcherSymbolContext: return FileMatcherSymbolContext.of_sdv( 'test_fails_if_applied', sdv_components.matcher_sdv_from_constant_primitive( matcher_w_init_action.matcher_that_applies_assertion( put, asrt.fail('must not be applied'), lambda x: x, asrt.MessageBuilder.new_empty(), 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 file_matcher_constant_sdv(primitive: FileMatcher) -> FileMatcherSdv: return sdv_components.matcher_sdv_from_constant_primitive(primitive)
'Test failure: File is not a directory')) return matching_result.of(True) NAME_STARTS_WITH__P1 = _name_starts_with__and_hard_error_if_applied_to_non_directory( 'name_starts_with_P1', 'P1') NAME_STARTS_WITH__P2 = _name_starts_with__and_hard_error_if_applied_to_non_directory( 'name_starts_with_P2', 'P2', ) NAME_STARTS_WITH__S1 = FileMatcherSymbolContext.of_sdv( 'name_starts_with_S1', sdv_components.matcher_sdv_from_constant_primitive( file_matchers.BaseNameStartsWithMatcher('S1'))) NO_ACTION_ON_FILES_THEMSELVES__CONTENTS = [ File.empty('P1-f'), Dir.empty('P1-d'), sym_link('P1-s', 'P1-f'), sym_link('P1-sb', 'no-P2-existing'), ] FILES_SHOULD_BE_INCLUDED_EVEN_IF_MATCH__DEPTH_0 = NEA.new_identical_expected_and_actual( 'files should be included even if match / depth 0', NO_ACTION_ON_FILES_THEMSELVES__CONTENTS, ) FILES_SHOULD_BE_INCLUDED_EVEN_IF_MATCH__DEPTH_1 = NEA.new_identical_expected_and_actual( 'files should be included even if match / depth 1',
def _constant(matcher: FileMatcher) -> FileMatcherSdv: return sdv_components.matcher_sdv_from_constant_primitive(matcher)
def _parse_type_matcher(parser: TokenParser) -> FileMatcherSdv: file_type = parser.consume_mandatory_constant_string_that_must_be_unquoted_and_equal( file_properties.SYNTAX_TOKEN_2_FILE_TYPE, file_properties.SYNTAX_TOKEN_2_FILE_TYPE.get, TYPE_MATCHER_ARGUMENT.name) return sdv_components.matcher_sdv_from_constant_primitive(FileMatcherType(file_type))
def sdv() -> StringMatcherSdv: return sdv_components.matcher_sdv_from_constant_primitive( EmptinessStringMatcher())
str( surrounded_by_hard_quotes( line_matcher.CONTENTS_MATCHER_NAME)), ), NameAndValue( 'non-transformer name that is not a valid symbol name', NOT_A_VALID_SYMBOL_NAME, ), NameAndValue( 'missing matcher', '', ), ] # ARRANGE # parser = sut.EmbryoParser() for case in cases: with self.subTest(name=case.name): source = single_line_source( src2(ValueType.LINE_MATCHER, 'defined_name', case.value), ) with self.assertRaises( SingleInstructionInvalidArgumentException): # ACT & ASSERT # parser.parse(ARBITRARY_FS_LOCATION_INFO, source) CONSTANT_TRUE_MATCHER_SDV = sdv_components.matcher_sdv_from_constant_primitive( constant.MatcherWithConstantResult(True)) if __name__ == '__main__': unittest.TextTestRunner().run(suite())
def emptiness_matcher() -> FilesMatcherSdv: return sdv_components.matcher_sdv_from_constant_primitive( _EmptinessMatcher())