Skip to content

Commit 706f639

Browse files
committed
Merge pull request #7 from ccnmtl/python3-support
add python3 support
2 parents 16d4d3d + db64ee5 commit 706f639

File tree

6 files changed

+28
-20
lines changed

6 files changed

+28
-20
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ language: python
22
sudo: False
33
python:
44
- "2.7"
5+
- "3.5"
6+
env:
7+
- DJANGO="Django>=1.8.0,<1.9.0"
8+
- DJANGO="Django>=1.9.0,<1.10.0"
59
install:
610
- pip install .
711
- pip install flake8

exceptionstest/tests.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from exceptionstest import EXC_MSG
66

77

8-
98
class ExceptionsTest(TestCase):
109
""" Check how smoke test works with different exceptionstest raise from
1110
different places in code.
@@ -15,11 +14,10 @@ def setUp(self):
1514
settings.INSTALLED_APPS = ('exceptionstest', 'smoketest')
1615
self.c = Client()
1716

18-
1917
def test_exceptions(self):
2018
response = self.c.get("/smoketest/")
2119
self.assertEqual(response.status_code, 500)
22-
self.assertIn("FAIL", response.content)
20+
self.assertIn("FAIL", response.content.decode('utf-8'))
2321
self.assertIn(
2422
"Exception while importing smoke test script: %s" % EXC_MSG,
25-
response.content)
23+
response.content.decode('utf-8'))

main/tests.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django.test import TestCase
55
from django.test.client import Client
66

7-
from smoke import TestFailedSmokeTests
7+
from .smoke import TestFailedSmokeTests
88
from smoketest import SmokeTest
99

1010

@@ -34,28 +34,31 @@ def test_basics(self):
3434
response = self.c.get("/smoketest/")
3535
self.assertEqual(response.status_code, 500)
3636

37-
self.assertIn("FAIL", response.content)
37+
self.assertIn("FAIL", response.content.decode('utf-8'))
3838
# only tests from TestFailedSmokeTests should fail
39-
self.assertNotIn(".SmokeTest.", response.content)
39+
self.assertNotIn(".SmokeTest.",
40+
response.content.decode('utf-8'))
4041
# and both tests from TestFailedSmokeTests should fail
41-
self.assertIn("tests failed: 2\n", response.content)
42-
self.assertIn("tests errored: 0\n", response.content)
42+
self.assertIn("tests failed: 2\n",
43+
response.content.decode('utf-8'))
44+
self.assertIn("tests errored: 0\n",
45+
response.content.decode('utf-8'))
4346
self.assertIn(
4447
(".TestFailedSmokeTests.test_assertTrueWoMsg "
4548
"failed: False is not true"),
46-
response.content)
49+
response.content.decode('utf-8'))
4750
self.assertIn(
4851
".TestFailedSmokeTests.test_assertEqualWMsg failed: %s" %
4952
TestFailedSmokeTests.CUSTOM_TEST_MSG,
50-
response.content)
53+
response.content.decode('utf-8'))
5154

5255
def test_json(self):
5356
" Testing JSON response. "
5457
json_content_type = 'application/json'
5558
response = self.c.get("/smoketest/", HTTP_ACCEPT=json_content_type)
5659
self.assertEqual(json_content_type, response.get('Content-Type', None))
5760

58-
response_obj = json.loads(response.content)
61+
response_obj = json.loads(response.content.decode('utf-8'))
5962
self.assertEqual('FAIL', response_obj['status'])
6063
self.assertEqual(2, response_obj['tests_failed'])
6164
self.assertEqual(0, response_obj['tests_errored'])

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[bdist_wheel]
2+
universal = 1

smoketest/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def run(self):
5757
passed += 1
5858
if hasattr(self, 'tearDown'):
5959
self.tearDown()
60-
except Exception, e:
60+
except Exception as e:
6161
errored += 1
6262
msg = self._FAILED_TEST_FULL_MSG % {
6363
'method_full_name': method_full_name,

smoketest/views.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.db import transaction
33
from django.http import HttpResponse
44
from django.views.generic import View
5+
import functools
56
import json
67
import inspect
78
import importlib
@@ -41,7 +42,7 @@ def test_application(app):
4142
except ImportError:
4243
# no 'smokes' module for the app
4344
pass
44-
except Exception, e:
45+
except Exception as e:
4546
num_tests_errored += 1
4647
errored_tests.append(
4748
'Exception while importing smoke test script: %s' % e)
@@ -59,7 +60,7 @@ def test_application(app):
5960
num_tests_errored += errored
6061
failed_tests = failed_tests + f_tests
6162
errored_tests = errored_tests + e_tests
62-
except Exception, e:
63+
except Exception as e:
6364
# probably an error in setUp() or tearDown()
6465
num_tests_errored += 1
6566
e_tests.append('Exception during test: %s' % e)
@@ -74,13 +75,13 @@ def test_application(app):
7475

7576
def make_failed_report(result_sets):
7677
return "\n\n".join(
77-
[f for f in reduce(
78+
[f for f in functools.reduce(
7879
lambda x, y: x + y, [r.failed for r in result_sets])])
7980

8081

8182
def make_errored_report(result_sets):
8283
return "\n\n".join(
83-
[f for f in reduce(
84+
[f for f in functools.reduce(
8485
lambda x, y: x + y, [r.errored for r in result_sets])])
8586

8687

@@ -120,7 +121,7 @@ def get(self, request):
120121
for app in settings.INSTALLED_APPS
121122
if app not in skip]
122123
finish = time.time()
123-
all_passed = reduce(
124+
all_passed = functools.reduce(
124125
lambda x, y: x & y, [r.passed() for r in result_sets])
125126
num_test_classes = sum([r.num_test_classes for r in result_sets])
126127
num_tests_run = sum([r.num_tests_run for r in result_sets])
@@ -154,10 +155,10 @@ def get(self, request):
154155
tests_passed=num_tests_passed,
155156
tests_failed=num_tests_failed,
156157
tests_errored=num_tests_errored,
157-
failed_tests=reduce(
158+
failed_tests=functools.reduce(
158159
lambda x, y: x + y,
159160
[r.failed for r in result_sets]),
160-
errored_tests=reduce(
161+
errored_tests=functools.reduce(
161162
lambda x, y: x + y,
162163
[r.errored for r in result_sets]),
163164
time=(finish - start) * 1000,

0 commit comments

Comments
 (0)