Beispiel #1
0
def test_readLinesFromFile_shouedPreserveNewlinesIfAsked():
    expectedLinesWithNewlines = []
    for line in expectedLines:
        expectedLinesWithNewlines.append(line + "\n")
    expectedLinesWithNewlines[-1] = expectedLines[-1]
    assert readLinesFromFile("fileWithLine.txt",
                             folder="example",
                             removeNewline=False) == expectedLinesWithNewlines
 def execute(self, outputFolder):
     if (not path_exists_case_sensitive(self.fileName,
                                        parent_path=outputFolder)):
         messager.printError(
             "assertion fileContainsSnippet {0} {1} failed. {0} does not exist in {2}."
             .format(self.fileName, self.snippetFile, outputFolder))
         return False
     if (not path_exists_case_sensitive(self.snippetFile,
                                        parent_path=self.testFolder)):
         messager.printError(
             "assertion fileContainsSnippet {0} {1} failed. {1} does not exist in {2}."
             .format(self.fileName, self.snippetFile, self.testFolder))
         return False
     fileLines = readLinesFromFile(self.fileName, folder=outputFolder)
     snippetLines = readLinesFromFile(self.snippetFile,
                                      folder=self.testFolder)
     success = snippetExistsInFile(snippetLines, fileLines)
     if not success:
         messager.printError(
             "assertion fileContainsSnippet {0} {1} failed.  Matching lines from {1} not found in {2}/{0}."
             .format(self.fileName, self.snippetFile, outputFolder))
     return success
 def printDifferences(self, outputFile, fixtureFile):
     try:
         outputLines = rules_util.readLinesFromFile(outputFile,
                                                    removeNewline=False)
         fixtureLines = rules_util.readLinesFromFile(fixtureFile,
                                                     removeNewline=False)
         i = 0
         for diffLine in difflib.unified_diff(outputLines,
                                              fixtureLines,
                                              fromfile=outputFile,
                                              tofile=fixtureFile):
             if (i > 2):
                 diffLine = self.getVisibleWhitespace(diffLine)
             styledLine = diffLine
             if (diffLine.startswith("+")):
                 styledLine = click.style(diffLine, fg='blue')
             elif (diffLine.startswith("-")):
                 styledLine = click.style(diffLine, fg="yellow")
             click.echo(styledLine)
             i = i + 1
     except UnicodeDecodeError:
         messager.printError(
             "One or both files are binary, unable to print differences")
Beispiel #4
0
 def execute(self, outputFolder):
     if (not path_exists_case_sensitive(self.fileName,
                                        parent_path=outputFolder)):
         messager.printError(
             "assertion fileHasMatchingLine {0} {1} failed. {0} does not exist in {2}."
             .format(self.fileName, self.regex, outputFolder))
         return False
     fileLines = readLinesFromFile(self.fileName, folder=outputFolder)
     filtered = filter(lambda line: re.search(self.regex, line), fileLines)
     success = len(list(filtered)) > 0
     if not success:
         messager.printError(
             "assertion fileHasMatchingLine {0} {1} failed.  Matching line not found in {2}/{0}."
             .format(self.fileName, self.regex, outputFolder))
     return success
    def execute(self, outputFolder):
        if (not path_exists_case_sensitive(self.fileName,
                                           parent_path=outputFolder)):
            messager.printError(
                "assertion fileContainsLine {0} {1} failed. {0} does not exist in {2}."
                .format(self.fileName, self.line, outputFolder))
            return False

        fileLines = readLinesFromFile(self.fileName, folder=outputFolder)
        success = self.line in fileLines
        if not success:
            messager.printError(
                "assertion fileContainsLine {0} {1} failed.  Matching line not found in {2}/{0}."
                .format(self.fileName, self.line, outputFolder))
        return success
Beispiel #6
0
def test_readLinesFromFile_shouldReadLinesFromFQPath():
    assert readLinesFromFile("example/fileWithLine.txt") == expectedLines
Beispiel #7
0
def test_readLinesFromFile_shouldReadLinesFromFile():
    assert readLinesFromFile("fileWithLine.txt",
                             folder="example") == expectedLines