Skip to content

Commit 011016c

Browse files
scajanusdefnull
authored andcommitted
Changes to make tests pass on Windows
1 parent 21a8db0 commit 011016c

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

test/test_config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import tempfile
23
import unittest
34
from bottle import ConfigDict
@@ -167,7 +168,7 @@ class TestINIConfigLoader(unittest.TestCase):
167168
@classmethod
168169
def setUpClass(self):
169170
self.config_file = tempfile.NamedTemporaryFile(suffix='.example.ini',
170-
delete=True)
171+
delete=False)
171172
self.config_file.write(b'[DEFAULT]\n'
172173
b'default: 45\n'
173174
b'[bottle]\n'
@@ -184,6 +185,7 @@ def setUpClass(self):
184185
@classmethod
185186
def tearDownClass(self):
186187
self.config_file.close()
188+
os.unlink(self.config_file.name)
187189

188190
def test_load_config(self):
189191
c = ConfigDict()

test/test_resources.py

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1-
from bottle import ResourceManager
21
import os.path
2+
import sys
33
import unittest
4+
from bottle import ResourceManager
5+
6+
if sys.platform == 'win32':
7+
TEST_PATHS = ('C:\\foo\\bar\\', 'C:\\foo\\bar\\baz', 'C:\\foo\\baz\\..\\bar\\blub')
8+
EXPECTED = ['C:\\foo\\bar\\']
9+
else:
10+
TEST_PATHS = ('/foo/bar/', '/foo/bar/baz', '/foo/baz/../bar/blub')
11+
EXPECTED = ['/foo/bar/']
12+
413

514
class TestResourceManager(unittest.TestCase):
615

716
def test_path_normalize(self):
8-
tests = ('/foo/bar/', '/foo/bar/baz', '/foo/baz/../bar/blub')
9-
for test in tests:
17+
for test in TEST_PATHS:
1018
rm = ResourceManager()
1119
rm.add_path(test)
12-
self.assertEqual(rm.path, ['/foo/bar/'])
20+
self.assertEqual(rm.path, EXPECTED)
1321

1422
def test_path_create(self):
15-
import tempfile, shutil
23+
import shutil
24+
import tempfile
1625
tempdir = tempfile.mkdtemp()
1726
try:
1827
rm = ResourceManager()
@@ -24,8 +33,13 @@ def test_path_create(self):
2433
shutil.rmtree(tempdir)
2534

2635
def test_path_absolutize(self):
27-
tests = ('./foo/bar/', './foo/bar/baz', './foo/baz/../bar/blub')
28-
abspath = os.path.abspath('./foo/bar/') + os.sep
36+
if sys.platform == 'win32':
37+
tests = ('.\\foo\\bar\\', '.\\foo\\bar\\baz', '.\\foo\\baz\\..\\bar\\blub')
38+
abspath = os.path.abspath('.\\foo\\bar\\') + os.sep
39+
else:
40+
tests = ('./foo/bar/', './foo/bar/baz', './foo/baz/../bar/blub')
41+
abspath = os.path.abspath('./foo/bar/') + os.sep
42+
2943
for test in tests:
3044
rm = ResourceManager()
3145
rm.add_path(test)
@@ -37,29 +51,36 @@ def test_path_absolutize(self):
3751
self.assertEqual(rm.path, [abspath])
3852

3953
def test_path_unique(self):
40-
tests = ('/foo/bar/', '/foo/bar/baz', '/foo/baz/../bar/blub')
4154
rm = ResourceManager()
42-
[rm.add_path(test) for test in tests]
43-
self.assertEqual(rm.path, ['/foo/bar/'])
55+
[rm.add_path(test) for test in TEST_PATHS]
56+
self.assertEqual(rm.path, EXPECTED)
4457

4558
def test_root_path(self):
46-
tests = ('/foo/bar/', '/foo/bar/baz', '/foo/baz/../bar/blub')
47-
for test in tests:
59+
if sys.platform == 'win32':
60+
expected = ['C:\\foo\\bar\\baz\\']
61+
else:
62+
expected = ['/foo/bar/baz/']
63+
64+
for test in TEST_PATHS:
4865
rm = ResourceManager()
4966
rm.add_path('./baz/', test)
50-
self.assertEqual(rm.path, ['/foo/bar/baz/'])
67+
self.assertEqual(rm.path, expected)
5168

52-
for test in tests:
69+
for test in TEST_PATHS:
5370
rm = ResourceManager()
5471
rm.add_path('baz/', test)
55-
self.assertEqual(rm.path, ['/foo/bar/baz/'])
72+
self.assertEqual(rm.path, expected)
5673

5774
def test_path_order(self):
5875
rm = ResourceManager()
5976
rm.add_path('/middle/')
6077
rm.add_path('/first/', index=0)
6178
rm.add_path('/last/')
62-
self.assertEqual(rm.path, ['/first/', '/middle/', '/last/'])
79+
80+
if sys.platform == 'win32':
81+
self.assertEqual(rm.path, ['C:\\first\\', 'C:\\middle\\', 'C:\\last\\'])
82+
else:
83+
self.assertEqual(rm.path, ['/first/', '/middle/', '/last/'])
6384

6485
def test_get(self):
6586
rm = ResourceManager()

test/test_sendfile.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import unittest
23
from bottle import static_file, request, response, parse_date, parse_range_header, Bottle, tob
34
import bottle
@@ -63,6 +64,8 @@ def test_invalid(self):
6364
self.assertEqual(403, f.status_code)
6465

6566
def test_file_not_readable(self):
67+
if sys.platform == 'win32':
68+
return
6669
if os.geteuid() == 0:
6770
return # Root can read anything
6871

@@ -89,6 +92,7 @@ def test_mime_gzip(self):
8992
""" SendFile: Mime Guessing"""
9093
try:
9194
fp, fn = tempfile.mkstemp(suffix=".txt.gz")
95+
os.close(fp) # File needs to be closed before it can be accessed on Windows
9296
f = static_file(fn, root='/')
9397
self.assertTrue(f.headers['Content-Type'][0] in ('application/gzip'))
9498
self.assertFalse('Content-Encoding' in f.headers)

0 commit comments

Comments
 (0)