| 79 | | |
|---|
| 80 | | |
|---|
| 81 | | class TestDirectories(Base): |
|---|
| 82 | | """Getting, making, changing, deleting directories.""" |
|---|
| 83 | | |
|---|
| 84 | | def test_getcwd_and_change(self): |
|---|
| 85 | | """Test FTPHost.getcwd and FTPHost.chdir.""" |
|---|
| 86 | | host = self.host |
|---|
| 87 | | self.assertEqual( host.getcwd(), self.rootdir ) |
|---|
| 88 | | host.chdir(self.testdir) |
|---|
| 89 | | self.assertEqual( host.getcwd(), self.testdir ) |
|---|
| 90 | | |
|---|
| 91 | | def test_mkdir(self): |
|---|
| 92 | | """Test FTPHost.mkdir.""" |
|---|
| 93 | | host = self.host |
|---|
| 94 | | # use invalid directory name (__test2 doesn't exist) |
|---|
| 95 | | self.assertRaises( ftputil.PermanentError, host.mkdir, |
|---|
| 96 | | host.path.join(self.rootdir, '__test2', '__test3') ) |
|---|
| 97 | | # this is valid |
|---|
| 98 | | host.mkdir( host.path.join(self.testdir, '__test2') ) |
|---|
| 99 | | # repeat first mkdir (now valid) |
|---|
| 100 | | host.mkdir( host.path.join(self.testdir, '__test2', |
|---|
| 101 | | '__test3') ) |
|---|
| 102 | | # clean up for this test |
|---|
| 103 | | host.rmdir( host.path.join(self.testdir, '__test2', |
|---|
| 104 | | '__test3') ) |
|---|
| 105 | | host.rmdir( host.path.join(self.testdir, '__test2') ) |
|---|
| 106 | | |
|---|
| 107 | | def test_rmdir(self): |
|---|
| 108 | | """Test FTPHost.rmdir.""" |
|---|
| 109 | | host = self.host |
|---|
| 110 | | # try to remove nonexistent directory |
|---|
| 111 | | self.assertRaises( ftputil.PermanentError, host.rmdir, |
|---|
| 112 | | host.path.join(self.testdir, '__test2') ) |
|---|
| 113 | | # make two nested directories |
|---|
| 114 | | host.mkdir( host.path.join(self.testdir, '__test2') ) |
|---|
| 115 | | host.mkdir( host.path.join(self.testdir, '__test2', |
|---|
| 116 | | '__test3') ) |
|---|
| 117 | | # try to remove non-empty directory |
|---|
| 118 | | self.assertRaises( ftputil.PermanentError, host.rmdir, |
|---|
| 119 | | host.path.join(self.testdir, '__test2') ) |
|---|
| 120 | | # remove leaf dir __test3 |
|---|
| 121 | | host.rmdir( host.path.join(self.testdir, '__test2', |
|---|
| 122 | | '__test3') ) |
|---|
| 123 | | # try to remove a dir we are in |
|---|
| 124 | | host.chdir(self.testdir) |
|---|
| 125 | | host.chdir('./__test2') |
|---|
| 126 | | self.assertRaises( ftputil.PermanentError, host.rmdir, |
|---|
| 127 | | host.path.join(self.testdir, '__test2') ) |
|---|
| 128 | | # finally remove __test2 |
|---|
| 129 | | host.chdir(self.rootdir) |
|---|
| 130 | | host.rmdir( host.path.join(self.testdir, '__test2') ) |
|---|