Ejemplo n.º 1
0
 def test_DROPFile(self):
     """
     This test exercises the DROPFile mechanism to read the data represented by
     a given DROP. The DROPFile class will decide whether the data should be read
     directly or through the DROP
     """
     drop = FileDROP("a", "a", expectedSize=5)
     drop.write(b"abcde")
     with DROPFile(drop) as f:
         self.assertEqual(b"abcde", f.read())
         self.assertTrue(drop.isBeingRead())
         self.assertIsNotNone(f._io)
     self.assertFalse(drop.isBeingRead())
Ejemplo n.º 2
0
    def run(self):
        # check number of outputs
        if len(self.outputs) != 1:
            raise Exception("One output is expected by this application")

        # read from all inputs
        inputs = []
        for i in range(len(self.inputs)):
            with DROPFile(self.inputs[i]) as f:
                file_data = f.read()
                inputs.append(json.loads(file_data))

        # write to output
        self.outputs[0].write(json.dumps(inputs))
Ejemplo n.º 3
0
    def _readDirections(self, inDrop):
        directions = []

        # NOTE: it appears csv.reader() can't use the DROPFile(inDrop) directly,
        #       since DROPFile is not a iterator. Instead, we read the whole
        #       inDrop to a string and pass that to csv.reader()
        with DROPFile(inDrop) as f:
            file_data = f.read()
            if type(file_data) is bytes:
                file_data=file_data.decode('utf-8')
            csvreader = csv.reader(file_data.split('\n'))
            for row in csvreader:
                # skip rows with incorrect number of values
                if len(row) is not 2:
                    continue

                x = float(row[0])
                y = float(row[1])
                directions.append([x,y])

        return directions
 def _readConfig(self, inDrop):
     with DROPFile(inDrop) as f:
         config = json.load(f)
     return config