def test_creates_directories(self): # When given directory specifications, it creates those directories. path = self.useFixture(TempDir()).path create_normal_shape(path, [('a/', None), ('b/', None)]) self.assertThat(path, DirContains(['a', 'b'])) self.assertThat(os.path.join(path, 'a'), DirExists()) self.assertThat(os.path.join(path, 'b'), DirExists())
def test_creates_files(self): # When given a list of file specifications, it creates those files # underneath the temporary directory. path = self.useFixture(TempDir()).path create_normal_shape(path, [('a', 'foo'), ('b', 'bar')]) self.assertThat(path, DirContains(['a', 'b'])) self.assertThat(os.path.join(path, 'a'), FileContains('foo')) self.assertThat(os.path.join(path, 'b'), FileContains('bar'))
def test_creates_parent_directories(self): # If the parents of a file or directory don't exist, they get created # too. path = self.useFixture(TempDir()).path create_normal_shape(path, [('a/b/', None), ('c/d.txt', 'text')]) self.assertThat(path, DirContains(['a', 'c'])) self.assertThat(os.path.join(path, 'a'), DirContains('b')) self.assertThat(os.path.join(path, 'a', 'b'), DirExists()) self.assertThat(os.path.join(path, 'c'), DirExists()) self.assertThat(os.path.join(path, 'c', 'd.txt'), FileContains('text'))
def test_empty(self): tempdir = self.useFixture(TempDir()).path create_normal_shape(tempdir, []) self.assertThat(tempdir, DirContains([]))