Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Ensure that the target directory exists in FilesystemWriter.

  • Loading branch information...
commit c76a2047734cadbdd9470b57e344c9d940645d6f 1 parent 67b30f0
Gavin Panella authored

Showing 2 changed files with 12 additions and 2 deletions. Show diff stats Hide diff stats

  1. +3 0  tftp/backend.py
  2. +9 2 tftp/test/test_backend.py
3  tftp/backend.py
@@ -194,6 +194,9 @@ class FilesystemWriter(object):
194 194 def __init__(self, file_path):
195 195 if file_path.exists():
196 196 raise FileExists(file_path)
  197 + file_dir = file_path.parent()
  198 + if not file_dir.exists():
  199 + file_dir.makedirs()
197 200 self.file_path = file_path
198 201 self.destination_file = self.file_path.open('w')
199 202 self.temp_destination = tempfile.TemporaryFile()
11 tftp/test/test_backend.py
@@ -125,12 +125,19 @@ class Writer(unittest.TestCase):
125 125 def setUp(self):
126 126 self.temp_dir = FilePath(tempfile.mkdtemp())
127 127 self.existing_file_name = self.temp_dir.child('foo')
128   - with self.existing_file_name.open('w') as f:
129   - f.write(self.test_data)
  128 + self.existing_file_name.setContent(self.test_data)
130 129
131 130 def test_write_existing_file(self):
132 131 self.assertRaises(FileExists, FilesystemWriter, self.temp_dir.child('foo'))
133 132
  133 + def test_write_to_non_existent_directory(self):
  134 + new_directory = self.temp_dir.child("new")
  135 + new_file = new_directory.child("baz")
  136 + self.assertFalse(new_directory.exists())
  137 + FilesystemWriter(new_file).finish()
  138 + self.assertTrue(new_directory.exists())
  139 + self.assertTrue(new_file.exists())
  140 +
134 141 def test_finished_write(self):
135 142 w = FilesystemWriter(self.temp_dir.child('bar'))
136 143 w.write(self.test_data)

0 comments on commit c76a204

Please sign in to comment.
Something went wrong with that request. Please try again.