def test_parseAssertionFile_shouldReturnNullAndPrintMessageIfBadRule( printErrorMock): currentFolder = os.path.dirname(os.path.abspath(__file__)) testFolder = Path(currentFolder).parent.joinpath("example") assertionFile = testFolder.joinpath( "sampleAssertionFileWithUnparseableAssertion.yaml") expectedRules = [] expectedErrorMessage = "Unable to parse assertion file {}. Error on assertion \"sdjhfs sdhjfgs 6463\"".format( str(assertionFile)) actualRules = assertion_file_parser.parseAssertionFile( str(assertionFile), str(testFolder), {}) assert expectedRules == actualRules printErrorMock.assert_called_once_with(expectedErrorMessage)
def test_parseAssertionFile_clie_options_should_override_assertion_file(): currentFolder = os.path.dirname(os.path.abspath(__file__)) testFolder = Path(currentFolder).parent.joinpath("example") assertionFile = testFolder.joinpath( "sampleAssertionFileWithVisibleWhitespace.yaml") cli_options = {VISIBLE_WHITESPACE: False} #opposite of what's in yaml file expectedRules = [] expectedRules.append( PathExistsRule(cli_options, str(testFolder), "foo.txt")) expectedRules.append(PathExistsRule(cli_options, str(testFolder), "bin")) expectedRules.append( PathNotExistsRule(cli_options, str(testFolder), "missingFile")) expectedRules.append( FileMatchesRule(cli_options, str(testFolder), "build.gradle", "expectedBuild.gradle")) expectedRules.append( RunScriptRule(cli_options, str(testFolder), "MyApp", "./gradlew clean build")) expectedRules.append( FileContainsLineRule(cli_options, str(testFolder), "MyApp/foo", "this line should exist")) expectedRules.append( FileDoesNotContainLineRule(cli_options, str(testFolder), "MyApp/foo", "this line should not exist")) expectedRules.append( FileHasRegexMatchLineRule(cli_options, str(testFolder), "MyApp/foo", "^lo+king \\sfor.*$")) expectedRules.append( FileDoesNotRegexMatchRule(cli_options, str(testFolder), "MyApp/foo", "^lo+king\\s[fdfgd]{4} or.*$")) expectedRules.append( FileContainsSnippetRule(cli_options, str(testFolder), "MyApp/foo", "goodSnippet.txt")) expectedRules.append( FileDoesNotContainSnippetRule(cli_options, str(testFolder), "MyApp/foo", "badSnippet.txt")) actualRules = assertion_file_parser.parseAssertionFile( str(assertionFile), str(testFolder), cli_options) assert expectedRules == actualRules
def test_parseAssertionFile_shouldReturnAssertionRuleArray(): currentFolder = os.path.dirname(os.path.abspath(__file__)) testFolder = Path(currentFolder).parent.joinpath("example") assertionFile = testFolder.joinpath("sampleAssertionFile.yaml") expectedRules = [] expectedRules.append(PathExistsRule({}, str(testFolder), "foo.txt")) expectedRules.append(PathExistsRule({}, str(testFolder), "bin")) expectedRules.append(PathNotExistsRule({}, str(testFolder), "missingFile")) expectedRules.append( FileMatchesRule({}, str(testFolder), "build.gradle", "expectedBuild.gradle")) expectedRules.append( RunScriptRule({}, str(testFolder), "MyApp", "./gradlew clean build")) expectedRules.append( FileContainsLineRule({}, str(testFolder), "MyApp/foo", "this line should exist")) expectedRules.append( FileDoesNotContainLineRule({}, str(testFolder), "MyApp/foo", "this line should not exist")) expectedRules.append( FileHasRegexMatchLineRule({}, str(testFolder), "MyApp/foo", "^lo+king \\sfor.*$")) expectedRules.append( FileDoesNotRegexMatchRule({}, str(testFolder), "MyApp/foo", "^lo+king\\s[fdfgd]{4} or.*$")) expectedRules.append( FileContainsSnippetRule({}, str(testFolder), "MyApp/foo", "goodSnippet.txt")) expectedRules.append( FileDoesNotContainSnippetRule({}, str(testFolder), "MyApp/foo", "badSnippet.txt")) actualRules = assertion_file_parser.parseAssertionFile( str(assertionFile), str(testFolder), {}) assert expectedRules == actualRules