Ejemplo n.º 1
0
 def test_filename(self):
     """Verify that an appropriate file name is generated in an appropriate
     folder"""
     file_path = tempfile.mkdtemp() + os.path.join('some', 'depth', 'here')
     cp = Checkpointer(file_path)
     cp.counter = 25
     filename = cp._filename('A WeIrD TaG')
     self.assertTrue(os.path.join('some', 'depth', 'here') in filename)
     self.assertTrue('25' in filename)
     self.assertTrue('aweirdtag' in filename)
Ejemplo n.º 2
0
 def test_filename(self):
     """Verify that an appropriate file name is generated in an appropriate
     folder"""
     file_path = tempfile.mkdtemp() + os.path.join('some', 'depth', 'here')
     cp = Checkpointer(file_path)
     cp.counter = 25
     filename = cp._filename('A WeIrD TaG')
     self.assertTrue(os.path.join('some', 'depth', 'here') in filename)
     self.assertTrue('25' in filename)
     self.assertTrue('aweirdtag' in filename)
Ejemplo n.º 3
0
 def test_exception_reading(self):
     """If a file exists but is not the correct format, we expect
     deserialization to gracefully fail (rather than exploding)"""
     cp = Checkpointer(tempfile.mkdtemp())
     self.assertEqual(1, cp.checkpoint("1", lambda: 1))
     with open(cp._filename("1"), "w") as written_file:
         written_file.write("")
     cp._reset()
     # pickle will raise an exception, so we will recompute
     self.assertEqual(-1, cp.checkpoint("1", lambda: -1))
Ejemplo n.º 4
0
 def test_exception_reading(self):
     """If a file exists but is not the correct format, we expect
     deserialization to gracefully fail (rather than exploding)"""
     cp = Checkpointer(tempfile.mkdtemp())
     self.assertEqual(1, cp.checkpoint("1", lambda: 1))
     with open(cp._filename("1"), "w") as written_file:
         written_file.write("")
     cp._reset()
     # pickle will raise an exception, so we will recompute
     self.assertEqual(-1, cp.checkpoint("1", lambda: -1))