Ejemplo n.º 1
0
 def test_plus_mode(self):
     # Write, then seek to 0
     with open(self.tmpfilepath, 'w+') as f:
         f.write(self.teststring)
         f.seek(0)
         new_f = pickle.loads(cloudpickle.dumps(f))
         self.assertEqual(self.teststring, new_f.read())
     os.remove(self.tmpfilepath)
Ejemplo n.º 2
0
 def test_r_mode(self):
     # Write & close
     with open(self.tmpfilepath, 'w') as f:
         f.write(self.teststring)
     # Open for reading
     with open(self.tmpfilepath, 'r') as f:
         new_f = pickle.loads(cloudpickle.dumps(f))
         self.assertEqual(self.teststring, new_f.read())
     os.remove(self.tmpfilepath)
Ejemplo n.º 3
0
 def test_seek(self):
     # Write, then seek to arbitrary position
     with open(self.tmpfilepath, 'w+') as f:
         f.write(self.teststring)
         f.seek(4)
         unpickled = pickle.loads(cloudpickle.dumps(f))
         # unpickled StringIO is at position 4
         self.assertEqual(4, unpickled.tell())
         self.assertEqual(self.teststring[4:], unpickled.read())
         # but unpickled StringIO also contained the start
         unpickled.seek(0)
         self.assertEqual(self.teststring, unpickled.read())
     os.remove(self.tmpfilepath)
Ejemplo n.º 4
0
 def test_pickling_special_file_handles(self):
     # Warning: if you want to run your tests with nose, add -s option
     for out in sys.stdout, sys.stderr:  # Regression test for SPARK-3415
         self.assertEqual(out, pickle.loads(cloudpickle.dumps(out)))
     self.assertRaises(pickle.PicklingError,
                       lambda: cloudpickle.dumps(sys.stdin))
Ejemplo n.º 5
0
 def test_empty_file(self):
     # Empty file
     open(self.tmpfilepath, 'w').close()
     with open(self.tmpfilepath, 'r') as f:
         self.assertEqual('', pickle.loads(cloudpickle.dumps(f)).read())
     os.remove(self.tmpfilepath)