Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensure that the target directory exists in FilesystemWriter.

  • Loading branch information...
commit c76a2047734cadbdd9470b57e344c9d940645d6f 1 parent 67b30f0
Gavin Panella authored
Showing with 12 additions and 2 deletions.
  1. +3 −0  tftp/backend.py
  2. +9 −2 tftp/test/test_backend.py
3  tftp/backend.py
View
@@ -194,6 +194,9 @@ class FilesystemWriter(object):
def __init__(self, file_path):
if file_path.exists():
raise FileExists(file_path)
+ file_dir = file_path.parent()
+ if not file_dir.exists():
+ file_dir.makedirs()
self.file_path = file_path
self.destination_file = self.file_path.open('w')
self.temp_destination = tempfile.TemporaryFile()
11 tftp/test/test_backend.py
View
@@ -125,12 +125,19 @@ class Writer(unittest.TestCase):
def setUp(self):
self.temp_dir = FilePath(tempfile.mkdtemp())
self.existing_file_name = self.temp_dir.child('foo')
- with self.existing_file_name.open('w') as f:
- f.write(self.test_data)
+ self.existing_file_name.setContent(self.test_data)
def test_write_existing_file(self):
self.assertRaises(FileExists, FilesystemWriter, self.temp_dir.child('foo'))
+ def test_write_to_non_existent_directory(self):
+ new_directory = self.temp_dir.child("new")
+ new_file = new_directory.child("baz")
+ self.assertFalse(new_directory.exists())
+ FilesystemWriter(new_file).finish()
+ self.assertTrue(new_directory.exists())
+ self.assertTrue(new_file.exists())
+
def test_finished_write(self):
w = FilesystemWriter(self.temp_dir.child('bar'))
w.write(self.test_data)
Please sign in to comment.
Something went wrong with that request. Please try again.