Ejemplo n.º 1
0
 def test_fails_when_file_exists(self):
     path = os.path.join(self.get_temp_dir(), "test.txt")
     with open(path, "w"):
         pass
     with self.assertRaises(exporter_lib.OutputFileExistsError) as cm:
         exporter_lib._open_excl(path)
     self.assertEqual(str(cm.exception), path)
Ejemplo n.º 2
0
 def test_propagates_other_errors(self):
     path = os.path.join(self.get_temp_dir(), "enoent", "test.txt")
     with self.assertRaises(OSError) as cm:
         exporter_lib._open_excl(path)
     self.assertEqual(cm.exception.errno, errno.ENOENT)
Ejemplo n.º 3
0
 def test_success(self):
     path = os.path.join(self.get_temp_dir(), "test.txt")
     with exporter_lib._open_excl(path) as outfile:
         outfile.write("hello\n")
     with open(path) as infile:
         self.assertEqual(infile.read(), "hello\n")