def testCopyOneRow(self):
   expectedOutput = ("Timestamp,Value\n"
                     "datetime,int\n"
                     "T,\n"
                     "2011-09-04 02:00:00.000000,1\n"
                     "2011-09-04 02:05:00.000000,2\n"
                     "2011-09-04 02:10:00.000000,2\n"
                     "2011-09-04 02:15:00.000000,3\n"
                     "2011-09-04 02:20:00.000000,4\n"
                     "2011-09-04 02:25:00.000000,5\n"
                     "2011-09-04 02:30:00.000000,6\n")
   mockInput = MagicMock(return_value=StringIO(self.sampleInput))
   output = StringIO()
   mockOutput = MagicMock(return_value=output)
   with patch("__builtin__.open", mockInput):
     inputFile = FileRecordStream("input_path")
     with patch("__builtin__.open", mockOutput):
       outputFile = FileRecordStream("output_path",
                                     fields=inputFile.getFields(),
                                     write=True)
       anomalyzer.copy(inputFile, outputFile, 1, 1, 1)
   result = output.getvalue()
   result = result.replace("\r\n", "\n")
   result = result.replace("\r", "\n")
   self.assertSequenceEqual(expectedOutput, result)
Beispiel #2
0
 def testCopyOneRow(self):
     expectedOutput = ("Timestamp,Value\n"
                       "datetime,int\n"
                       "T,\n"
                       "2011-09-04 02:00:00.000000,1\n"
                       "2011-09-04 02:05:00.000000,2\n"
                       "2011-09-04 02:10:00.000000,2\n"
                       "2011-09-04 02:15:00.000000,3\n"
                       "2011-09-04 02:20:00.000000,4\n"
                       "2011-09-04 02:25:00.000000,5\n"
                       "2011-09-04 02:30:00.000000,6\n")
     mockInput = MagicMock(return_value=StringIO(self.sampleInput))
     output = StringIO()
     mockOutput = MagicMock(return_value=output)
     with patch("__builtin__.open", mockInput):
         inputFile = FileRecordStream("input_path")
         with patch("__builtin__.open", mockOutput):
             outputFile = FileRecordStream("output_path",
                                           fields=inputFile.getFields(),
                                           write=True)
             anomalyzer.copy(inputFile, outputFile, 1, 1, 1)
     result = output.getvalue()
     result = result.replace("\r\n", "\n")
     result = result.replace("\r", "\n")
     self.assertSequenceEqual(expectedOutput, result)