Exemplo n.º 1
0
 def testSample(self):
   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.sample(inputFile, outputFile, 1)
   result = StringIO(output.getvalue())
   result.next()
   result.next()
   result.next()
   reader = csv.reader(result)
   _, value = reader.next()
   self.assertIn(int(value), (1, 2, 3, 4, 5, 6))
   self.assertRaises(StopIteration, result.next)
Exemplo n.º 2
0
 def testSample(self):
     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.sample(inputFile, outputFile, 1)
     result = StringIO(output.getvalue())
     result.next()
     result.next()
     result.next()
     reader = csv.reader(result)
     _, value = reader.next()
     self.assertIn(int(value), (1, 2, 3, 4, 5, 6))
     self.assertRaises(StopIteration, result.next)