diff --git a/devel/run-tests b/devel/run-tests index df61c37..58a083a 100755 --- a/devel/run-tests +++ b/devel/run-tests @@ -37,7 +37,7 @@ runtests() { >>test.out.stdout 2>>test.out.stderr & PID=$! kill -0 $PID || exit 1 - python test.py + python3 test.py kill $PID wait $PID @@ -48,7 +48,7 @@ runtests() { >>test.out.stdout 2>>test.out.stderr & PID=$! kill -0 $PID || exit 1 - python test_forward.py + python3 test_forward.py kill $PID wait $PID @@ -59,7 +59,7 @@ runtests() { >>test.out.stdout 2>>test.out.stderr & PID=$! kill -0 $PID || exit 1 - python test_forward_all.py + python3 test_forward_all.py kill $PID wait $PID @@ -68,7 +68,7 @@ runtests() { >>test.out.stdout 2>>test.out.stderr & PID=$! kill -0 $PID || exit 1 - python test_server_id.py + python3 test_server_id.py kill $PID wait $PID @@ -84,7 +84,7 @@ runtests() { >>test.out.stdout 2>>test.out.stderr & PID=$! kill -0 $PID || exit 1 - python test_mimemap.py + python3 test_mimemap.py kill $PID wait $PID @@ -93,7 +93,7 @@ runtests() { >>test.out.stdout 2>>test.out.stderr & PID=$! kill -0 $PID || exit 1 - python test_no_listing.py + python3 test_no_listing.py kill $PID wait $PID @@ -102,7 +102,7 @@ runtests() { >>test.out.stdout 2>>test.out.stderr & PID=$! kill -0 $PID || exit 1 - python test_timeout.py + python3 test_timeout.py kill $PID wait $PID @@ -115,7 +115,7 @@ runtests() { >>test.out.stdout 2>>test.out.stderr & PID=$! kill -0 $PID || exit 1 - python test_auth.py + python3 test_auth.py kill $PID wait $PID diff --git a/devel/test_forward.py b/devel/test_forward.py index 1d1cdc3..d946ab9 100755 --- a/devel/test_forward.py +++ b/devel/test_forward.py @@ -1,24 +1,23 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # This is run by the "run-tests" script. import unittest from test import TestHelper, Conn, parse class TestForward(TestHelper): def test_forward_root(self): - resp = Conn().get("/", req_hdrs = { "Host": "example.com" }) + resp = self.get('/', req_hdrs={'Host': 'example.com'}) status, hdrs, body = parse(resp) self.assertContains(status, "301 Moved Permanently") expect = "http://www.example.com/" - self.assertEquals(hdrs["Location"], expect) + self.assertEqual(hdrs["Location"], expect) self.assertContains(body, expect) def test_forward_relative(self): - resp = Conn().get("/foo/bar", - req_hdrs = { "Host": "secure.example.com" }) + resp = self.get('/foo/bar', req_hdrs={'Host': 'secure.example.com'}) status, hdrs, body = parse(resp) self.assertContains(status, "301 Moved Permanently") expect = "https://www.example.com/secure/foo/bar" - self.assertEquals(hdrs["Location"], expect) + self.assertEqual(hdrs["Location"], expect) self.assertContains(body, expect) if __name__ == '__main__': diff --git a/devel/test_forward_all.py b/devel/test_forward_all.py index fc0f068..1c44057 100755 --- a/devel/test_forward_all.py +++ b/devel/test_forward_all.py @@ -1,24 +1,24 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # This is run by the "run-tests" script. import unittest from test import TestHelper, Conn, parse class TestForwardAll(TestHelper): def test_forward_root(self): - resp = Conn().get("/", req_hdrs = { "Host": "not-example.com" }) + resp = self.get('/', req_hdrs={'Host': 'not-example.com'}) status, hdrs, body = parse(resp) self.assertContains(status, "301 Moved Permanently") expect = "http://catchall.example.com/" - self.assertEquals(hdrs["Location"], expect) + self.assertEqual(hdrs["Location"], expect) self.assertContains(body, expect) def test_forward_relative(self): - resp = Conn().get("/foo/bar", - req_hdrs = { "Host": "still-not.example.com" }) + resp = self.get('/foo/bar', + req_hdrs={'Host': 'still-not.example.com'}) status, hdrs, body = parse(resp) self.assertContains(status, "301 Moved Permanently") expect = "http://catchall.example.com/foo/bar" - self.assertEquals(hdrs["Location"], expect) + self.assertEqual(hdrs["Location"], expect) self.assertContains(body, expect) if __name__ == '__main__': diff --git a/devel/test_mimemap.py b/devel/test_mimemap.py index 8eb3ccc..9b85626 100755 --- a/devel/test_mimemap.py +++ b/devel/test_mimemap.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # This is run by the "run-tests" script. import unittest import os @@ -6,14 +6,15 @@ from test import WWWROOT, TestHelper, Conn, parse class TestMimemap(TestHelper): def setUp(self): - self.data = "hello\n" + self.data = b'hello\n' self.datalen = len(self.data) self.files = [ ("test-file.a1", "test/type1"), ("test-file.ap2", "test/type2"), ("test-file.app3", "test/type3"), ("test-file.appp4", "test/default") ] for fn, _ in self.files: - open(WWWROOT + "/" + fn, "w").write(self.data) + with open(WWWROOT + "/" + fn, 'wb') as f: + f.write(self.data) def tearDown(self): for fn, _ in self.files: @@ -21,14 +22,14 @@ class TestMimemap(TestHelper): def get_helper(self, idx): fn, content_type = self.files[idx] - resp = Conn().get("/" + fn) + resp = self.get("/" + fn) status, hdrs, body = parse(resp) self.assertContains(status, "200 OK") - self.assertEquals(hdrs["Accept-Ranges"], "bytes") - self.assertEquals(hdrs["Content-Length"], str(self.datalen)) - self.assertEquals(hdrs["Content-Type"], content_type) + self.assertEqual(hdrs["Accept-Ranges"], "bytes") + self.assertEqual(hdrs["Content-Length"], str(self.datalen)) + self.assertEqual(hdrs["Content-Type"], content_type) self.assertContains(hdrs["Server"], "darkhttpd/") - self.assertEquals(body, self.data) + self.assertEqual(body, self.data) def test_get_1(self): self.get_helper(0) def test_get_2(self): self.get_helper(1) diff --git a/devel/test_no_listing.py b/devel/test_no_listing.py index 2bd2f06..7912bd1 100755 --- a/devel/test_no_listing.py +++ b/devel/test_no_listing.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # This is run by the "run-tests" script. import unittest from test import TestHelper, Conn, parse diff --git a/devel/test_server_id.py b/devel/test_server_id.py index ea74fe6..bfac5c2 100755 --- a/devel/test_server_id.py +++ b/devel/test_server_id.py @@ -1,15 +1,15 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # This is run by the "run-tests" script. import unittest from test import TestHelper, Conn, parse class TestForward(TestHelper): def test_no_server_id(self): - resp = Conn().get("/", method = 'BOGUS') + resp = self.get('/', method = 'BOGUS') status, hdrs, body = parse(resp) self.assertContains(status, "400 Bad Request") - self.assertFalse(hdrs.has_key("Server")) - self.assertFalse("Generated by darkhttpd/" in body) + self.assertFalse('Server' in hdrs) + self.assertFalse(b'Generated by darkhttpd/' in body) if __name__ == '__main__': unittest.main() diff --git a/devel/test_timeout.py b/devel/test_timeout.py index ae32298..0109d5a 100755 --- a/devel/test_timeout.py +++ b/devel/test_timeout.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # This is run by the "run-tests" script. import unittest import signal @@ -14,7 +14,8 @@ class TestTimeout(unittest.TestCase): # Expect to get EOF before the alarm fires. ret = s.recv(1024) signal.alarm(0) - self.assertEquals(ret, '') + s.close() + self.assertEqual(ret, b'') if __name__ == '__main__': unittest.main()