Argh, this is the *actual* test that works under Windows.
This commit is contained in:
parent
b740f6a0c7
commit
7bb1653cc3
|
@ -193,18 +193,19 @@ class SimpleHTTPServerTestCase(BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
BaseTestCase.setUp(self)
|
BaseTestCase.setUp(self)
|
||||||
os.chdir(tempfile.gettempdir())
|
self.cwd = os.getcwd()
|
||||||
|
basetempdir = tempfile.gettempdir()
|
||||||
|
os.chdir(basetempdir)
|
||||||
self.data = 'We are the knights who say Ni!'
|
self.data = 'We are the knights who say Ni!'
|
||||||
self.tempdir = tempfile.mkdtemp(dir=tempfile.gettempdir())
|
self.tempdir = tempfile.mkdtemp(dir=basetempdir)
|
||||||
self.tempdir_name = os.path.basename(self.tempdir)
|
self.tempdir_name = os.path.basename(self.tempdir)
|
||||||
self.tempfile = tempfile.NamedTemporaryFile(dir=self.tempdir)
|
temp = open(os.path.join(self.tempdir, 'test'), 'wb')
|
||||||
self.tempfile.file.write(self.data)
|
temp.write(self.data)
|
||||||
self.tempfile.file.flush()
|
temp.close()
|
||||||
self.tempfile_name = os.path.basename(self.tempfile.name)
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
try:
|
try:
|
||||||
self.tempfile.close()
|
os.chdir(self.cwd)
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(self.tempdir)
|
shutil.rmtree(self.tempdir)
|
||||||
except:
|
except:
|
||||||
|
@ -222,7 +223,7 @@ class SimpleHTTPServerTestCase(BaseTestCase):
|
||||||
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
#constructs the path relative to the root directory of the HTTPServer
|
#constructs the path relative to the root directory of the HTTPServer
|
||||||
response = self.request(self.tempdir_name + '/' + self.tempfile_name)
|
response = self.request(self.tempdir_name + '/test')
|
||||||
self.check_status_and_reason(response, 200, data=self.data)
|
self.check_status_and_reason(response, 200, data=self.data)
|
||||||
response = self.request(self.tempdir_name + '/')
|
response = self.request(self.tempdir_name + '/')
|
||||||
self.check_status_and_reason(response, 200)
|
self.check_status_and_reason(response, 200)
|
||||||
|
@ -244,7 +245,7 @@ class SimpleHTTPServerTestCase(BaseTestCase):
|
||||||
|
|
||||||
def test_head(self):
|
def test_head(self):
|
||||||
response = self.request(
|
response = self.request(
|
||||||
self.tempdir_name + '/'+ self.tempfile_name, method='HEAD')
|
self.tempdir_name + '/test', method='HEAD')
|
||||||
self.check_status_and_reason(response, 200)
|
self.check_status_and_reason(response, 200)
|
||||||
self.assertEqual(response.getheader('content-length'),
|
self.assertEqual(response.getheader('content-length'),
|
||||||
str(len(self.data)))
|
str(len(self.data)))
|
||||||
|
@ -301,10 +302,12 @@ class CGIHTTPServerTestCase(BaseTestCase):
|
||||||
file2.write(cgi_file2 % sys.executable)
|
file2.write(cgi_file2 % sys.executable)
|
||||||
os.chmod(self.file2_path, 0777)
|
os.chmod(self.file2_path, 0777)
|
||||||
|
|
||||||
|
self.cwd = os.getcwd()
|
||||||
os.chdir(self.parent_dir)
|
os.chdir(self.parent_dir)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
try:
|
try:
|
||||||
|
os.chdir(self.cwd)
|
||||||
os.remove(self.file1_path)
|
os.remove(self.file1_path)
|
||||||
os.remove(self.file2_path)
|
os.remove(self.file2_path)
|
||||||
os.rmdir(self.cgi_dir)
|
os.rmdir(self.cgi_dir)
|
||||||
|
|
Loading…
Reference in New Issue